@Override public char next() { char ret = utf8Ptr.charAt(pos); pos += utf8Ptr.charSize(pos); return ret; } }
@Override public char next() { // Default - no character exists. int c = ICharacterIterator.EOS_CHAR; if (byteOffset < stringp.getLength()) { c = stringp.charAt(byteOffset); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.finer(" UTF8StringCharacterIterator char[" + byteOffset + "] = " + c); } // Increment cursor if ((c >= 0x0001) && (c <= 0x007F)) { ++byteOffset; } else if (c > 0x07FF) { byteOffset += 3; } else { byteOffset += 2; } } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.finer(" END UTF8StringCharacterIterator char[" + byteOffset + "] = " + c); } return (char) c; }
private void printString(PrintStream ps, UTF8StringPointable utf8sp) { int utfLen = utf8sp.getUTFLength(); int offset = 2; while (utfLen > 0) { char c = utf8sp.charAt(offset); switch (c) { case '<': ps.append("<"); break; case '>': ps.append(">"); break; case '&': ps.append("&"); break; case '"': ps.append("""); break; case '\'': ps.append("'"); break; default: ps.append(c); break; } int cLen = UTF8StringPointable.getModifiedUTF8Len(c); offset += cLen; utfLen -= cLen; } }
public static boolean startsWith(UTF8StringPointable src, UTF8StringPointable pattern, boolean ignoreCase) { int utflen1 = src.getUTF8Length(); int utflen2 = pattern.getUTF8Length(); if (utflen2 > utflen1) { return false; } int s1Start = src.getMetaDataLength(); int s2Start = pattern.getMetaDataLength(); int c1 = 0; int c2 = 0; while (c1 < utflen1 && c2 < utflen2) { char ch1 = src.charAt(s1Start + c1); char ch2 = pattern.charAt(s2Start + c2); if (ch1 != ch2) { if (!ignoreCase || Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) { break; } } c1 += src.charSize(s1Start + c1); c2 += pattern.charSize(s2Start + c2); } return (c2 == utflen2); }
public static boolean endsWith(UTF8StringPointable src, UTF8StringPointable pattern, boolean ignoreCase) { int len1 = src.getUTF8Length(); int len2 = pattern.getUTF8Length(); if (len2 > len1) { return false; } int s1Start = src.getMetaDataLength(); int s2Start = pattern.getMetaDataLength(); int c1 = len1 - len2; int c2 = 0; while (c1 < len1 && c2 < len2) { char ch1 = src.charAt(s1Start + c1); char ch2 = pattern.charAt(s2Start + c2); if (ch1 != ch2) { if (!ignoreCase || Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) { break; } } c1 += src.charSize(s1Start + c1); c2 += pattern.charSize(s2Start + c2); } return (c2 == len2); }
public void reset(UTF8StringPointable valuePtr) { int utfLen = valuePtr.getUTF8Length(); if (buf == null || buf.length < utfLen) { buf = new char[utfLen]; } int bytePos = 0; int charPos = 0; while (bytePos < utfLen) { buf[charPos++] = valuePtr.charAt(valuePtr.getMetaDataLength() + bytePos); bytePos += valuePtr.charSize(valuePtr.getMetaDataLength() + bytePos); } this.length = charPos; }
int byteIndex = 0; while (byteIndex < srcUtfLen) { char originalChar = src.charAt(srcStart + byteIndex); boolean isLetter = Character.isLetter(originalChar);
/** * Generates an upper case string of an input string. * * @param src * , the input source string. * @param builder * , a builder for the resulting string. * @param out * , the storage for a result string. * @throws IOException */ public static void uppercase(UTF8StringPointable src, UTF8StringBuilder builder, GrowableArray out) throws IOException { final int srcUtfLen = src.getUTF8Length(); final int srcStart = src.getMetaDataLength(); builder.reset(out, srcUtfLen); int byteIndex = 0; while (byteIndex < srcUtfLen) { builder.appendChar(Character.toUpperCase(src.charAt(srcStart + byteIndex))); byteIndex += src.charSize(srcStart + byteIndex); } builder.finish(); }
/** * Generates a lower case string of an input string. * * @param src * , the input source string. * @param builder * , a builder for the resulting string. * @param out * , the storage for a result string. * @throws IOException */ public static void lowercase(UTF8StringPointable src, UTF8StringBuilder builder, GrowableArray out) throws IOException { final int srcUtfLen = src.getUTF8Length(); final int srcStart = src.getMetaDataLength(); builder.reset(out, srcUtfLen); int byteIndex = 0; while (byteIndex < srcUtfLen) { builder.appendChar(Character.toLowerCase(src.charAt(srcStart + byteIndex))); byteIndex += src.charSize(srcStart + byteIndex); } builder.finish(); }
if (left) { while (startIndex < srcUtfLen) { char ch = srcPtr.charAt(srcStart + startIndex); if (!charSet.contains(ch)) { break; int cursorIndex = startIndex; while (cursorIndex < srcUtfLen) { char ch = srcPtr.charAt(srcStart + cursorIndex); cursorIndex += srcPtr.charSize(srcStart + cursorIndex); if (!charSet.contains(ch)) {
/** * @return {@code true} if substring was successfully written into given {@code out}, or * {@code false} if substring could not be obtained ({@code charOffset} or {@code charLength} * are less than 0 or starting position is greater than the input length) */ public static boolean substr(UTF8StringPointable src, int charOffset, int charLength, UTF8StringBuilder builder, GrowableArray out) throws IOException { if (charOffset < 0 || charLength < 0) { return false; } int utfLen = src.getUTF8Length(); int chIdx = 0; int byteIdx = 0; while (byteIdx < utfLen && chIdx < charOffset) { byteIdx += src.charSize(src.getMetaDataLength() + byteIdx); chIdx++; } if (byteIdx >= utfLen) { return false; } builder.reset(out, Math.min(utfLen - byteIdx, (int) (charLength * 1.0 * byteIdx / chIdx))); chIdx = 0; while (byteIdx < utfLen && chIdx < charLength) { builder.appendChar(src.charAt(src.getMetaDataLength() + byteIdx)); chIdx++; byteIdx += src.charSize(src.getMetaDataLength() + byteIdx); } builder.finish(); return true; }
/** * 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(); }