[jruby-joni] 20/279: Expose more API for 1.9 functionality.
Hideki Yamane
henrich at moszumanska.debian.org
Mon Nov 16 11:26:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository jruby-joni.
commit cbb370e108c5b0722c936e23b60e98c3ecbf1fa0
Author: Marcin Mielżyński <lopx at gazeta.pl>
Date: Wed May 7 19:46:49 2008 +0000
Expose more API for 1.9 functionality.
git-svn-id: http://svn.codehaus.org/jruby/joni/trunk@6634 961051c9-f516-0410-bf72-c9f7e237a7b7
---
src/org/joni/NameEntry.java | 21 +++++++++++++++++----
src/org/joni/Regex.java | 28 ++++++++++++++++------------
2 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/src/org/joni/NameEntry.java b/src/org/joni/NameEntry.java
index b5aacac..4dcb4ab 100644
--- a/src/org/joni/NameEntry.java
+++ b/src/org/joni/NameEntry.java
@@ -22,9 +22,9 @@ package org.joni;
public final class NameEntry {
static final int INIT_NAME_BACKREFS_ALLOC_NUM = 8;
- final byte[]name;
- final int nameP;
- final int nameEnd;
+ public final byte[]name;
+ public final int nameP;
+ public final int nameEnd;
int backNum;
int backRef1;
@@ -35,7 +35,20 @@ public final class NameEntry {
nameP = p;
nameEnd = end;
}
-
+
+ public int[] getBackRefs() {
+ switch (backNum) {
+ case 0:
+ return new int[]{};
+ case 1:
+ return new int[]{backRef1};
+ default:
+ int[]result = new int[backNum];
+ System.arraycopy(backRefs, 0, result, 0, backNum);
+ return result;
+ }
+ }
+
private void alloc() {
backRefs = new int[INIT_NAME_BACKREFS_ALLOC_NUM];
}
diff --git a/src/org/joni/Regex.java b/src/org/joni/Regex.java
index d7ce4b0..c5fc8da 100644
--- a/src/org/joni/Regex.java
+++ b/src/org/joni/Regex.java
@@ -24,6 +24,7 @@ import static org.joni.Option.isCaptureGroup;
import static org.joni.Option.isDontCaptureGroup;
import java.util.IllegalFormatConversionException;
+import java.util.Iterator;
import org.joni.constants.AnchorType;
import org.joni.constants.RegexState;
@@ -183,10 +184,10 @@ public final class Regex implements RegexState {
}
}
- int numberOfNames() {
+ public int numberOfNames() {
return nameTable == null ? 0 : nameTable.size();
}
-
+
void nameAdd(byte[]name, int nameP, int nameEnd, int backRef, Syntax syntax) {
if (nameEnd - nameP <= 0) throw new ValueException(ErrorMessages.ERR_EMPTY_GROUP_NAME);
@@ -207,12 +208,11 @@ public final class Regex implements RegexState {
e.addBackref(backRef);
}
-
+
NameEntry nameToGroupNumbers(byte[]name, int nameP, int nameEnd) {
- NameEntry e = nameFind(name, nameP, nameEnd);
- return e;
+ return nameFind(name, nameP, nameEnd);
}
-
+
public int nameToBackrefNumber(byte[]name, int nameP, int nameEnd, Region region) {
NameEntry e = nameToGroupNumbers(name, nameP, nameEnd);
if (e == null) throw new ValueException(ErrorMessages.ERR_UNDEFINED_NAME_REFERENCE,
@@ -233,8 +233,12 @@ public final class Regex implements RegexState {
return e.backRefs[e.backNum - 1];
}
}
-
- boolean noNameGroupIsActive(Syntax syntax) {
+
+ public Iterator<NameEntry> namedBackrefIterator() {
+ return nameTable.iterator();
+ }
+
+ public boolean noNameGroupIsActive(Syntax syntax) {
if (isDontCaptureGroup(options)) return false;
if (Config.USE_NAMED_GROUP) {
@@ -249,11 +253,11 @@ public final class Regex implements RegexState {
int p = exactP;
int end = exactEnd;
int len = end - p;
- if (map == null) map = new byte[Config.CHAR_TABLE_SIZE]; // ?? but seems to be safe
-
- // map/skip
-
+
if (len < Config.CHAR_TABLE_SIZE) {
+ // map/skip
+ if (map == null) map = new byte[Config.CHAR_TABLE_SIZE];
+
for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) map[i] = (byte)len;
for (int i=0; i<len-1; i++) map[bytes[p + i] & 0xff] = (byte)(len - 1 -i); // oxff ??
} else {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git
More information about the pkg-java-commits
mailing list