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; }