public static long strLengthWithCodeRange(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { return strLengthWithCodeRangeAsciiCompatible(enc, bytes, p, end); } else { return strLengthWithCodeRangeNonAsciiCompatible(enc, bytes, p, end); } }
public static long strLengthWithCodeRange(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { return strLengthWithCodeRangeAsciiCompatible(enc, bytes, p, end); } else { return strLengthWithCodeRangeNonAsciiCompatible(enc, bytes, p, end); } }
public static long strLengthWithCodeRange(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { return strLengthWithCodeRangeAsciiCompatible(enc, bytes, p, end); } else { return strLengthWithCodeRangeNonAsciiCompatible(enc, bytes, p, end); } }
public static long strLengthWithCodeRange(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { return strLengthWithCodeRangeAsciiCompatible(enc, bytes, p, end); } else { return strLengthWithCodeRangeNonAsciiCompatible(enc, bytes, p, end); } }
public static int nth(Encoding enc, byte[]bytes, int p, int end, int n) { if (enc.isSingleByte()) { p += n; } else if (enc.isFixedWidth()) { p += n * enc.maxLength(); } else if (enc.isAsciiCompatible()) { p = nthAsciiCompatible(enc, bytes, p, end, n); } else { p = nthNonAsciiCompatible(enc, bytes, p, end, n); } return p > end ? end : p; }
public static int nth(Encoding enc, byte[]bytes, int p, int end, int n) { if (enc.isSingleByte()) { p += n; } else if (enc.isFixedWidth()) { p += n * enc.maxLength(); } else if (enc.isAsciiCompatible()) { p = nthAsciiCompatible(enc, bytes, p, end, n); } else { p = nthNonAsciiCompatible(enc, bytes, p, end, n); } return p > end ? end : p; }
/** * Get the position of the nth character in the given byte array, using the given encoding and range. * * @param enc encoding to use * @param bytes bytes to scan * @param p starting byte offset * @param end ending byte offset * @param n index of character for which to find byte offset * @param singlebyte whether the byte contents are in a single byte encoding * @return the offset of the nth character in the string, or -1 if nth is out of the string */ public static int nth(Encoding enc, byte[]bytes, int p, int end, int n, boolean singlebyte) { if (singlebyte) { p += n; } else if (enc.isFixedWidth()) { p += n * enc.maxLength(); } else if (enc.isAsciiCompatible()) { p = nthAsciiCompatible(enc, bytes, p, end, n); } else { p = nthNonAsciiCompatible(enc, bytes, p, end, n); } if (p < 0) return -1; return p > end ? end : p; }
/** * Get the position of the nth character in the given byte array, using the given encoding and range. * * @param enc encoding to use * @param bytes bytes to scan * @param p starting byte offset * @param end ending byte offset * @param n index of character for which to find byte offset * @param singlebyte whether the byte contents are in a single byte encoding * @return the offset of the nth character in the string, or -1 if nth is out of the string */ public static int nth(Encoding enc, byte[]bytes, int p, int end, int n, boolean singlebyte) { if (singlebyte) { p += n; } else if (enc.isFixedWidth()) { p += n * enc.maxLength(); } else if (enc.isAsciiCompatible()) { p = nthAsciiCompatible(enc, bytes, p, end, n); } else { p = nthNonAsciiCompatible(enc, bytes, p, end, n); } if (p < 0) return -1; return p > end ? end : p; }
public static int strLength(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { int c = 0; while (p < end) { if (Encoding.isAscii(bytes[p])) { int q = searchNonAscii(bytes, p, end); if (q == -1) return c + (end - p); c += q - p; p = q; } p += length(enc, bytes, p, end); c++; } return c; } int c; for (c = 0; end > p; c++) p += length(enc, bytes, p, end); return c; }
public static int strLength(Encoding enc, byte[]bytes, int p, int end) { if (enc.isFixedWidth()) { return (end - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) { int c = 0; while (p < end) { if (Encoding.isAscii(bytes[p])) { int q = searchNonAscii(bytes, p, end); if (q == -1) return c + (end - p); c += q - p; p = q; } p += length(enc, bytes, p, end); c++; } return c; } int c; for (c = 0; end > p; c++) p += length(enc, bytes, p, end); return c; }
public static int strLength(Encoding enc, byte[]bytes, int p, int e, int cr) { int c; if (enc.isFixedWidth()) { return (e - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) {
public static int strLength(Encoding enc, byte[]bytes, int p, int e, int cr) { int c; if (enc.isFixedWidth()) { return (e - p + enc.minLength() - 1) / enc.minLength(); } else if (enc.isAsciiCompatible()) {
private char multibyteCharAt(Encoding enc, int beg, int length) { int p; int s = value.getBegin(); int end = s + length; byte[] bytes = value.getUnsafeBytes(); if (beg > 0 && beg > StringSupport.strLengthFromRubyString(this, enc)) { throw new StringIndexOutOfBoundsException(beg); } if (isCodeRangeValid() && enc.isUTF8()) { p = StringSupport.utf8Nth(bytes, s, end, beg); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w; if (p > end || w > end - p) { throw new StringIndexOutOfBoundsException(beg); } } else if ((p = StringSupport.nth(enc, bytes, s, end, beg)) == end) { throw new StringIndexOutOfBoundsException(beg); } int codepoint = enc.mbcToCode(bytes, p, end); if (Character.isBmpCodePoint(codepoint)) { return (char) codepoint; } // we can only return high surrogate here return Character.highSurrogate(codepoint); }
private char multibyteCharAt(Encoding enc, int beg, int length) { int p; int s = value.getBegin(); int end = s + length; byte[] bytes = value.getUnsafeBytes(); if (beg > 0 && beg > StringSupport.strLengthFromRubyString(this, enc)) { throw new StringIndexOutOfBoundsException(beg); } if (isCodeRangeValid() && enc.isUTF8()) { p = StringSupport.utf8Nth(bytes, s, end, beg); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w; if (p > end || w > end - p) { throw new StringIndexOutOfBoundsException(beg); } } else if ((p = StringSupport.nth(enc, bytes, s, end, beg)) == end) { throw new StringIndexOutOfBoundsException(beg); } int codepoint = enc.mbcToCode(bytes, p, end); if (Character.isBmpCodePoint(codepoint)) { return (char) codepoint; } // we can only return high surrogate here return Character.highSurrogate(codepoint); }
p = StringSupport.utf8Nth(bytes, s, end, beg); len = StringSupport.utf8Offset(bytes, p, end, len); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w;
p = StringSupport.utf8Nth(bytes, s, end, beg); len = StringSupport.utf8Offset(bytes, p, end, len); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w;
p = StringSupport.utf8Nth(bytes, s, end, beg); len = StringSupport.utf8Offset(bytes, p, end, len); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w;
p = StringSupport.utf8Nth(bytes, s, end, beg); len = StringSupport.utf8Offset(bytes, p, end, len); } else if (enc.isFixedWidth()) { int w = enc.maxLength(); p = s + beg * w;