/** * @param src, * the source string. * @param pattern, * the pattern string. * @param ignoreCase, * to ignore case or not. * @return the byte offset of the first character of the matching string. Not including the MetaLength. */ public static int find(UTF8StringPointable src, UTF8StringPointable pattern, boolean ignoreCase) { return find(src, pattern, ignoreCase, 0); }
public static boolean contains(UTF8StringPointable src, UTF8StringPointable pattern, boolean ignoreCase) { return find(src, pattern, ignoreCase) >= 0; }
public int find(UTF8StringPointable pattern, boolean ignoreCase) { return find(this, pattern, ignoreCase); }
/** * Write the substring after the given pattern. It will write a empty string if the matching fails. * * @param src * @param match * @param builder * @param out */ public static void substrAfter(UTF8StringPointable src, UTF8StringPointable match, UTF8StringBuilder builder, GrowableArray out) throws IOException { int byteOffset = find(src, match, false); if (byteOffset < 0) { builder.reset(out, 0); builder.finish(); return; } final int srcUtfLen = src.getUTF8Length(); final int matchUtfLen = match.getUTF8Length(); final int resultLen = srcUtfLen - byteOffset - matchUtfLen; builder.reset(out, resultLen); builder.appendUtf8StringPointable(src, src.getCharStartOffset() + byteOffset + matchUtfLen, resultLen); builder.finish(); }
/** * Write the substring before the given pattern. It will write a empty string if the matching fails. * * @param src * @param match * @param builder * @param out * @throws IOException */ public static void substrBefore(UTF8StringPointable src, UTF8StringPointable match, UTF8StringBuilder builder, GrowableArray out) throws IOException { int byteOffset = find(src, match, false); if (byteOffset < 0) { builder.reset(out, 0); builder.finish(); return; } final int srcMetaLen = src.getMetaDataLength(); builder.reset(out, byteOffset); for (int idx = 0; idx < byteOffset;) { builder.appendChar(src.charAt(srcMetaLen + idx)); idx += src.charSize(srcMetaLen + idx); } builder.finish(); }
replaceLimit = Integer.MAX_VALUE; int curIdx = find(srcPtr, searchPtr, false); if (curIdx < 0) { return false; while (limit > 0 && (nextIdx = find(srcPtr, searchPtr, false, curIdx)) > 0) { builder.appendUtf8StringPointable(srcPtr, srcPtr.getCharStartOffset() + curIdx, nextIdx - curIdx); builder.appendUtf8StringPointable(replacePtr);