Get maximum i such that <tt>start <= i <= end</tt> and
<tt>s.substring(start, i)</tt> fits JVM UTF string encoding limit.
324876
int getUtfEncodingLimit(String s, int start, int end)
  {
    if ((end - start) * 3 <= MAX_UTF_ENCODING_SIZE) {
      return end;
    }
    int limit = MAX_UTF_ENCODING_SIZE;
    for (int i = start; i != end; i++) {
      int c = s.charAt(i);
      if (0 != c && c <= 0x7F) {
        --limit;
      } else if (c < 0x7FF) {
        limit -= 2;
      } else {
        limit -= 3;
      }
      if (limit < 0) {
        return i;
      }
    }
    return end;
  }
206650
static public String getEnglishString(byte[] data, int start, int end) {
        int len = end - start;
        if (0 >= len || null == data) {
            return null;
        }
        char chars[] = new char[len];
        for (int i = start; i < end; i++) {
            chars[i] = (char) (data[i] & 0xff);
        }
        return new String(chars);
    }
377524
private String getString(int offset, int maxLength) {
        int index = offset;
        int lastIndex = index + maxLength;
        while (index < lastIndex && (buffer[index] != 0)) {
            index++;
        }
        return new String(buffer, offset, index - offset, StandardCharsets.ISO_8859_1);
    }
834444
private static boolean matchInf(byte[] str, byte firstchar, int start, int end) {
    final int len = end - start;
    // The wonders of unicode. The infinity symbol \u221E is three bytes:
    if(len == 3 && firstchar == -0x1E && str[start + 1] == -0x78 && str[start + 2] == -0x62) {
      return true;
    }
    if((len != 3 && len != INFINITY_LENGTH) //
        || (firstchar != 'I' && firstchar != 'i')) {
      return false;
    }
    for(int i = 1, j = INFINITY_LENGTH + 1; i < INFINITY_LENGTH; i++, j++) {
      final byte c = str[start + i];
      if(c != INFINITY_PATTERN[i] && c != INFINITY_PATTERN[j]) {
        return false;
      }
      if(i == 2 && len == 3) {
        return true;
      }
    }
    return true;
  }
173785
@Override
    public String substring(int beginIndex, int endIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        char[] buf = this.buf;
        int sz = buf.length;
        if (endIndex > sz) {
            throw new StringIndexOutOfBoundsException(endIndex);
        }
        int subLen = endIndex - beginIndex;
        if (subLen < 0) {
            throw new StringIndexOutOfBoundsException(subLen);
        }
        return ((beginIndex == 0) && (endIndex == sz)) ? toString()
                : new String(buf, toInternalId(beginIndex), subLen);
    }
1189784
private static String prefix(String s, int start) {
        StringBuilder prefix=new StringBuilder(MAX_PREFIX_LENGTH+20);
        if(start==0) {
            prefix.append("\"");
        } else {
            prefix.append("[at pattern index ").append(start).append("] \"");
        }
        int substringLength=s.length()-start;
        if(substringLength<=MAX_PREFIX_LENGTH) {
            prefix.append(start==0 ? s : s.substring(start));
        } else {
            int limit=start+MAX_PREFIX_LENGTH-4;
            if(Character.isHighSurrogate(s.charAt(limit-1))) {
                // remove lead surrogate from the end of the prefix
                --limit;
            }
            prefix.append(s, start, limit).append(" ...");
        }
        return prefix.append("\"").toString();
    }
184869
private static int getXIndex(PatternFinderUser def, int x,
            Segment<PrimitiveParameter> lastMatch) {
        int skipStart = def.getSkipStart();
        if (lastMatch != null && skipStart > 0) {
            return Math.max(x, lastMatch.getFirstIndex() + skipStart);
        } else if (lastMatch != null && def.getSkip() > 0) {
            return Math.max(x, lastMatch.getLastIndex() + def.getSkip());
        } else {
            return x;
        }
    }
604807
public static String maxTruncStr(String source, int maxNrChars) {
        if (source != null && source.length() > maxNrChars) {
            return source.substring(0, maxNrChars);
        } else {
            return source;
        }
    }
551122
protected final int nextStringEndPos(byte[] bytes, int startPos, int limit, byte[] delimiter) {
		int endPos = startPos;

		final int delimLimit = limit - delimiter.length + 1;

		while (endPos < limit) {
			if (endPos < delimLimit && delimiterNext(bytes, endPos, delimiter)) {
				break;
			}
			endPos++;
		}

		if (endPos == startPos) {
			setErrorState(ParseErrorState.EMPTY_COLUMN);
			return -1;
		}
		return endPos;
	}
582750
public static int getTrimmedLength(CharSequence s) {
        int len = s.length();

        int start = 0;
        while (start < len && s.charAt(start) <= ' ') {
            start++;
        }

        int end = len;
        while (end > start && s.charAt(end - 1) <= ' ') {
            end--;
        }

        return end - start;
    }
579631
private static int parseInt(Input s) {
    if (s.index >= s.len) throw new DateFormatException("unexpected end of input", s.str, s.index);
    int result = 0;
    while (s.index < s.len) {
      char c = s.getChar();
      if (c >= '0' && c <= '9') {
        if (result >= Integer.MAX_VALUE / 10) throw new ArithmeticException("Field too large.");
        result = result * 10 + ((int)c - (int)'0');
        s.index++;
      } else {
        break;
      }
    }
    return result;
  }
25096
public String substring(int beginIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        int subLen = size() - beginIndex;
        if (subLen < 0) {
            throw new StringIndexOutOfBoundsException(subLen);
        }
        return (beginIndex == 0) ? toString() : new String(buf, toInternalId(beginIndex), subLen);
    }
416229
private static String getLongString(IoBufferEx buffer)
    {
        long len = getUnsignedInt(buffer);
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++)
        {
            builder.append((char)(buffer.getUnsigned()));
        }
        String s = builder.toString();
        return s;
    }
707766
public static long parseLong(String s, int beginIndex, int endIndex) {
    // Fallback to default implementation in case the string is long
    if (endIndex - beginIndex > 16) {
      return Long.parseLong(s.substring(beginIndex, endIndex));
    }
    long res = digitAt(s, beginIndex);
    for (beginIndex++; beginIndex < endIndex; beginIndex++) {
      res = res * 10 + digitAt(s, beginIndex);
    }
    return res;
  }
1018419
public int indexOf(BinaryString subStr, int start) {
		ensureMaterialized();
		subStr.ensureMaterialized();
		if (subStr.sizeInBytes == 0) {
			return 0;
		}
		if (inFirstSegment()) {
			// position in byte
			int byteIdx = 0;
			// position is char
			int charIdx = 0;
			while (byteIdx < sizeInBytes && charIdx < start) {
				byteIdx += numBytesForFirstByte(getByteOneSegment(byteIdx));
				charIdx++;
			}
			do {
				if (byteIdx + subStr.sizeInBytes > sizeInBytes) {
					return -1;
				}
				if (SegmentsUtil.equals(segments, offset + byteIdx,
					subStr.segments, subStr.offset, subStr.sizeInBytes)) {
					return charIdx;
				}
				byteIdx += numBytesForFirstByte(getByteOneSegment(byteIdx));
				charIdx++;
			} while (byteIdx < sizeInBytes);

			return -1;
		} else {
			return indexOfSlow(subStr, start);
		}
	}
1288128
private static int parseLimits(int i, int end, char[] data, int[] limits) throws PatternSyntaxException {
        if (limits.length != LIMITS_LENGTH)
            throw new IllegalArgumentException("limits.length=" + limits.length + ", should be " + LIMITS_LENGTH);
        limits[LIMITS_PARSE_RESULT_INDEX] = LIMITS_OK;
        int ind = 0;
        int v = 0;
        char c;
        while (i < end) {
            c = data[i++];
            switch (c) {
                case ' ':
                    continue;

                case ',':
                    if (ind > 0) throw new PatternSyntaxException("illegal construction: {.. , , ..}");
                    limits[ind++] = v;
                    v = -1;
                    continue;

                case '}':
                    limits[ind] = v;
                    if (ind == 0) limits[1] = v;
                    return i;

                default:
                    if (c > '9' || c < '0') {
                        //throw new PatternSyntaxException("illegal symbol in iterator: '{"+c+"}'");
                        limits[LIMITS_PARSE_RESULT_INDEX] = LIMITS_FAILURE;
                        return i;
                    }
                    if (v < 0) v = 0;
                    v = v * 10 + (c - '0');
            }
        }
        throw new PatternSyntaxException("malformed quantifier");
    }
398076
private static int getSingleCP(CharSequence s) {
        if (s.length() < 1) {
            throw new IllegalArgumentException("Can't use zero-length strings in UnicodeSet");
        }
        if (s.length() > 2) return -1;
        if (s.length() == 1) return s.charAt(0);

        // at this point, len = 2
        int cp = UTF16.charAt(s, 0);
        if (cp > 0xFFFF) { // is surrogate pair
            return cp;
        }
        return -1;
    }