@Override final int search(Matcher matcher, byte[]text, int textP, int adjustText, int textEnd, int textStart, int s_, int range_) { Regex regex = matcher.regex; Encoding enc = regex.enc; byte[]map = regex.map; int s = textStart; if (s >= textEnd) s = textEnd - 1; // multibyte safe ? while (s >= textP) { if (map[text[s] & 0xff] != 0) return s; s = enc.prevCharHead(text, adjustText, s, textEnd); } return -1; } };
@Override final int search(Matcher matcher, byte[]text, int textP, int adjustText, int textEnd, int textStart, int s_, int range_) { Regex regex = matcher.regex; Encoding enc = regex.enc; byte[]map = regex.map; int s = textStart; if (s >= textEnd) s = textEnd - 1; // multibyte safe ? while (s >= textP) { if (map[text[s] & 0xff] != 0) return s; s = enc.prevCharHead(text, adjustText, s, textEnd); } return -1; } };
private static int chomp_newline(byte[] bytes, int p, int e, Encoding enc) { int prev = enc.prevCharHead(bytes, p, e, e); if (enc.isNewLine(bytes, prev, e)) { e = prev; prev = enc.prevCharHead(bytes, p, e, e); if (prev != -1 && EncodingUtils.encAscget(bytes, prev, e, null, enc) == '\r') e = prev; } return e; }
private static int chomp_newline(byte[] bytes, int p, int e, Encoding enc) { int prev = enc.prevCharHead(bytes, p, e, e); if (enc.isNewLine(bytes, prev, e)) { e = prev; prev = enc.prevCharHead(bytes, p, e, e); if (prev != -1 && EncodingUtils.encAscget(bytes, prev, e, null, enc) == '\r') e = prev; } return e; }
private static int strRindex(final byte[] strBytes, final int strBeg, final int strLen, final byte[] subBytes, final int subBeg, final int subLen, int s, int pos, final Encoding enc) { final int e = strBeg + strLen; while (s >= strBeg) { if (s + subLen <= e && ByteList.memcmp(strBytes, s, subBytes, subBeg, subLen) == 0) { return pos; } if (pos == 0) break; pos--; s = enc.prevCharHead(strBytes, strBeg, s, e); } return -1; }
private static int strRindex(final byte[] strBytes, final int strBeg, final int strLen, final byte[] subBytes, final int subBeg, final int subLen, int s, int pos, final Encoding enc) { final int e = strBeg + strLen; while (s >= strBeg) { if (s + subLen <= e && ByteList.memcmp(strBytes, s, subBytes, subBeg, subLen) == 0) { return pos; } if (pos == 0) break; pos--; s = enc.prevCharHead(strBytes, strBeg, s, e); } return -1; }
private void opLookBehind() { int tlen = code[ip++]; s = enc.stepBack(bytes, str, s, end, tlen); if (s == -1) {opFail(); return;} sprev = enc.prevCharHead(bytes, str, s, end); }
private void opLookBehind() { int tlen = code[ip++]; s = enc.stepBack(bytes, str, s, end, tlen); if (s == -1) {opFail(); return;} sprev = enc.prevCharHead(bytes, str, s, end); }
private void opPushLookBehindNot() { int addr = code[ip++]; int tlen = code[ip++]; int q = enc.stepBack(bytes, str, s, end, tlen); if (q == -1) { /* too short case -> success. ex. /(?<!XXX)a/.match("a") If you want to change to fail, replace following line. */ ip += addr; // return FAIL; } else { pushLookBehindNot(ip + addr, s, sprev, pkeep); s = q; sprev = enc.prevCharHead(bytes, str, s, end); } }
private void opPushLookBehindNot() { int addr = code[ip++]; int tlen = code[ip++]; int q = enc.stepBack(bytes, str, s, end, tlen); if (q == -1) { /* too short case -> success. ex. /(?<!XXX)a/.match("a") If you want to change to fail, replace following line. */ ip += addr; // return FAIL; } else { pushLookBehindNot(ip + addr, s, sprev, pkeep); s = q; sprev = enc.prevCharHead(bytes, str, s, end); } }
@Override final int search(Matcher matcher, byte[]text, int textP, int adjustText, int textEnd, int textStart, int s_, int range_) { Regex regex = matcher.regex; Encoding enc = regex.enc; byte[]target = regex.exact; int targetP = regex.exactP; int targetEnd = regex.exactEnd; int s = textEnd; s -= targetEnd - targetP; s = (s > textStart) ? textStart : enc.leftAdjustCharHead(text, adjustText, s, textEnd); byte[]buf = matcher.icbuf(); while (s >= textP) { if (lowerCaseMatch(target, targetP, targetEnd, text, s, textEnd, enc, buf, regex.caseFoldFlag)) return s; s = enc.prevCharHead(text, adjustText, s, textEnd); } return -1; } };
public StringNode splitLastChar(Encoding enc) { StringNode n = null; if (end > p) { int prev = enc.prevCharHead(bytes, p, end, end); if (prev != -1 && prev > p) { /* can be split */ n = new StringNode(bytes, prev, end); if (isRaw()) n.setRaw(); end = prev; } } return n; }
public StringNode splitLastChar(Encoding enc) { StringNode n = null; if (end > p) { int prev = enc.prevCharHead(bytes, p, end, end); if (prev != -1 && prev > p) { /* can be split */ n = new StringNode(bytes, prev, end); if (isRaw()) n.setRaw(); end = prev; } } return n; }
private final int matchCommon(int at, int range, int option, boolean interrupt) throws InterruptedException { msaInit(option, at); if (Config.USE_CEC) { int offset = at = str; stateCheckBuffInit(end - str, offset, regex.numCombExpCheck); // move it to construction? } // USE_COMBINATION_EXPLOSION_CHECK int prev = enc.prevCharHead(bytes, str, at, end); if (Config.USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE) { return matchAt(end /*range*/, at, prev, interrupt); } else { return matchAt(range /*range*/, at, prev, interrupt); } }
private int choppedLength19(Ruby runtime) { int p = value.getBegin(); int end = p + value.getRealSize(); if (p > end) return 0; byte bytes[] = value.getUnsafeBytes(); Encoding enc = value.getEncoding(); int s = enc.prevCharHead(bytes, p, end, end); if (s == -1) return 0; if (s > p && codePoint(runtime, enc, bytes, s, end) == '\n') { int s2 = enc.prevCharHead(bytes, p, s, end); if (s2 != -1 && codePoint(runtime, enc, bytes, s2, end) == '\r') s = s2; } return s - p; }
private final int matchCommon(int at, int range, int option, boolean interrupt) throws InterruptedException { msaInit(option, at); if (Config.USE_CEC) { int offset = at = str; stateCheckBuffInit(end - str, offset, regex.numCombExpCheck); // move it to construction? } // USE_COMBINATION_EXPLOSION_CHECK int prev = enc.prevCharHead(bytes, str, at, end); if (Config.USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE) { return matchAt(end /*range*/, at, prev, interrupt); } else { return matchAt(range /*range*/, at, prev, interrupt); } }
private int choppedLength19(Ruby runtime) { int p = value.getBegin(); int end = p + value.getRealSize(); if (p > end) return 0; byte bytes[] = value.getUnsafeBytes(); Encoding enc = value.getEncoding(); int s = enc.prevCharHead(bytes, p, end, end); if (s == -1) return 0; if (s > p && codePoint(runtime, enc, bytes, s, end) == '\n') { int s2 = enc.prevCharHead(bytes, p, s, end); if (s2 != -1 && codePoint(runtime, enc, bytes, s2, end) == '\r') s = s2; } return s - p; }
/** * MRI: chopped_length */ public static int choppedLength(CodeRangeable str) { ByteList bl = str.getByteList(); Encoding enc = bl.getEncoding(); int p, p2, beg, end; beg = bl.begin(); end = beg + bl.realSize(); if (beg > end) return 0; p = enc.prevCharHead(bl.unsafeBytes(), beg, end, end); if (p == 0) return 0; if (p > beg && EncodingUtils.encAscget(bl.unsafeBytes(), p, end, null, enc) == '\n') { p2 = enc.prevCharHead(bl.unsafeBytes(), beg, p, end); if (p2 != -1 && EncodingUtils.encAscget(bl.unsafeBytes(), p2, end, null, enc) == '\r') p = p2; } return p - beg; }
/** * MRI: chopped_length */ public static int choppedLength(CodeRangeable str) { ByteList bl = str.getByteList(); Encoding enc = bl.getEncoding(); int p, p2, beg, end; beg = bl.begin(); end = beg + bl.realSize(); if (beg > end) return 0; p = enc.prevCharHead(bl.unsafeBytes(), beg, end, end); if (p == 0) return 0; if (p > beg && EncodingUtils.encAscget(bl.unsafeBytes(), p, end, null, enc) == '\n') { p2 = enc.prevCharHead(bl.unsafeBytes(), beg, p, end); if (p2 != -1 && EncodingUtils.encAscget(bl.unsafeBytes(), p2, end, null, enc) == '\r') p = p2; } return p - beg; }
private IRubyObject multiByteRStrip(ThreadContext context) { final Ruby runtime = context.runtime; byte[] bytes = value.getUnsafeBytes(); int start = value.getBegin(); int end = start + value.getRealSize(); Encoding enc = EncodingUtils.STR_ENC_GET(this); int endp = end; int prev; while ((prev = enc.prevCharHead(bytes, start, endp, end)) != -1) { int point = codePoint(runtime, enc, bytes, prev, end); if (point != 0 && !ASCII.isSpace(point)) break; endp = prev; } if (endp < end) { view(0, endp - start); return this; } return context.nil; }