use of org.joni.Matcher in project es6draft by anba.
the class JoniRegExpMatcher method matcher.
@Override
public JoniMatchState matcher(CharSequence s) {
UEncoding enc = getEncoding();
if (s != lastInput) {
lastInput = s;
lastInputBytes = enc.toBytes(s);
}
int length = lastInputBytes.length - enc.minLength();
Matcher matcher = getPattern().matcher(lastInputBytes, 0, length);
return new JoniMatchState(enc, matcher, s, negativeLAGroups);
}
use of org.joni.Matcher in project phoenix by apache.
the class JONIPattern method matches.
private boolean matches(byte[] bytes, int offset, int len) {
int range = offset + len;
Matcher matcher = pattern.matcher(bytes, offset, range);
int ret = matcher.match(offset, range, Option.DEFAULT);
return len == ret;
}
use of org.joni.Matcher in project phoenix by apache.
the class JONIPattern method split.
private boolean split(byte[] srcBytes, int srcOffset, int srcLen, ImmutableBytesWritable outPtr) {
SortOrder sortOrder = SortOrder.ASC;
PArrayDataTypeEncoder builder = new PArrayDataTypeEncoder(PVarchar.INSTANCE, sortOrder);
int srcRange = srcOffset + srcLen;
Matcher matcher = pattern.matcher(srcBytes, 0, srcRange);
int cur = srcOffset;
boolean append;
while (true) {
int nextCur = matcher.search(cur, srcRange, Option.DEFAULT);
if (nextCur < 0) {
builder.appendValue(srcBytes, cur, srcRange - cur);
break;
}
// REGEXP_SPLIT("12ONE34TWO56THREE78","[0-9]+")={null, "ONE", "TWO", "THREE", null}
if (cur == matcher.getBegin()) {
builder.appendValue(srcBytes, cur, 0);
}
if (cur < matcher.getBegin()) {
builder.appendValue(srcBytes, cur, matcher.getBegin() - cur);
}
cur = matcher.getEnd();
// REGEXP_SPLIT("12ONE34TWO56THREE78","[0-9]+")={null, "ONE", "TWO", "THREE", null}
if (cur == srcRange) {
builder.appendValue(srcBytes, cur, 0);
break;
}
}
byte[] bytes = builder.encode();
if (bytes == null)
return false;
outPtr.set(bytes);
return true;
}
use of org.joni.Matcher in project phoenix by apache.
the class JONIPattern method substr.
private boolean substr(byte[] srcBytes, int offset, int range, ImmutableBytesWritable outPtr) {
Matcher matcher = pattern.matcher(srcBytes, 0, range);
boolean ret = matcher.search(offset, range, Option.DEFAULT) >= 0;
if (ret) {
int len = matcher.getEnd() - matcher.getBegin();
outPtr.set(srcBytes, matcher.getBegin(), len);
} else {
outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
}
return ret;
}
Aggregations