@Override public char charAt(int index) { return buf[toInternalId(index)]; }
@Override public char charAt(int index) { return buf[toInternalId(index)]; }
private int lastIndexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { final char[] buf = this.buf; char hi = highSurrogate(ch); char lo = lowSurrogate(ch); int i = Math.min(fromIndex, buf.length - 2); for (; i >= 0; i--) { if (buf[toInternalId(i)] == hi && buf[toInternalId(i + 1)] == lo) { return i; } } } return -1; }
private int lastIndexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { final char[] buf = this.buf; char hi = highSurrogate(ch); char lo = lowSurrogate(ch); int i = Math.min(fromIndex, buf.length - 2); for (; i >= 0; i--) { if (buf[toInternalId(i)] == hi && buf[toInternalId(i + 1)] == lo) { return i; } } } return -1; }
public boolean startsWith(FastStr prefix, int toffset) { if (prefix.isEmpty()) return true; int sz2 = prefix.size(), sz = size(); if (toffset < 0 || toffset > sz - sz2) { return false; } int po = 0, pc = sz2, to = toffset; char[] buf1 = buf, buf2 = prefix.buf; while (--pc >= 0) { if (buf1[toInternalId(to++)] != buf2[prefix.toInternalId(po++)]) { return false; } } return true; }
public boolean startsWith(FastStr prefix, int toffset) { if (prefix.isEmpty()) return true; int sz2 = prefix.size(), sz = size(); if (toffset < 0 || toffset > sz - sz2) { return false; } int po = 0, pc = sz2, to = toffset; char[] buf1 = buf, buf2 = prefix.buf; while (--pc >= 0) { if (buf1[toInternalId(to++)] != buf2[prefix.toInternalId(po++)]) { return false; } } return true; }
@Override public FastStr dropWhile($.Function<? super Character, Boolean> predicate) { int sz = size(); if (sz == 0) return EMPTY_STR; int b = -1, e = toInternalId(sz); for (int i = 0; i < sz; ++i) { char c = charAt(i); b = toInternalId(i); if (!predicate.apply(c)) break; } return unsafeOf(buf, b, e); }
@Override public FastStr reverse() { int sz = size(); char[] newBuf = new char[sz]; for (int i = 0, j = sz - 1; i < sz; ) { newBuf[j--] = buf[toInternalId(i++)]; } return new FastStr(newBuf, 0, sz); }
private int indexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { final char[] buf = this.buf; final char hi = highSurrogate(ch); final char lo = lowSurrogate(ch); final int max = size() - 1; for (int i = fromIndex; i < max; i++) { if (buf[toInternalId(i)] == hi && buf[toInternalId(i + 1)] == lo) { return i; } } } return -1; }
@Override public FastStr reverse() { int sz = size(); char[] newBuf = new char[sz]; for (int i = 0, j = sz - 1; i < sz; ) { newBuf[j--] = buf[toInternalId(i++)]; } return new FastStr(newBuf, 0, sz); }
@Override public FastStr dropWhile($.Function<? super Character, Boolean> predicate) { int sz = size(); if (sz == 0) return EMPTY_STR; int b = -1, e = toInternalId(sz); for (int i = 0; i < sz; ++i) { char c = charAt(i); b = toInternalId(i); if (!predicate.apply(c)) break; } return unsafeOf(buf, b, e); }
private int indexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { final char[] buf = this.buf; final char hi = highSurrogate(ch); final char lo = lowSurrogate(ch); final int max = size() - 1; for (int i = fromIndex; i < max; i++) { if (buf[toInternalId(i)] == hi && buf[toInternalId(i + 1)] == lo) { return i; } } } return -1; }
@Override public FastStr takeWhile($.Function<? super Character, Boolean> predicate) { if (isEmpty()) { return EMPTY_STR; } int sz = size(), b = toInternalId(0), e = -1; for (int i = 0; i < sz; ++i) { char c = charAt(i); e = toInternalId(i); if (!predicate.apply(c)) break; } return unsafeOf(buf, b, e); }
@Override public FastStr takeWhile($.Function<? super Character, Boolean> predicate) { if (isEmpty()) { return EMPTY_STR; } int sz = size(), b = toInternalId(0), e = -1; for (int i = 0; i < sz; ++i) { char c = charAt(i); e = toInternalId(i); if (!predicate.apply(c)) break; } return unsafeOf(buf, b, e); }
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } int sz = size(); if (srcEnd > sz) { throw new StringIndexOutOfBoundsException(srcEnd); } System.arraycopy(buf, toInternalId(srcBegin), dst, dstBegin, srcEnd - srcBegin); }
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } int sz = size(); if (srcEnd > sz) { throw new StringIndexOutOfBoundsException(srcEnd); } System.arraycopy(buf, toInternalId(srcBegin), dst, dstBegin, srcEnd - srcBegin); }
/** * Wrapper of {@link String#substring(int)} * * @param beginIndex the begin index * @return a String instance that is equivalent to a sub part of this FastStr */ 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); }
/** * Wrapper of {@link String#substring(int)} * * @param beginIndex the begin index * @return a String instance that is equivalent to a sub part of this FastStr */ 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); }
public int lastIndexOf(int ch, int fromIndex) { fromIndex = toInternalId(fromIndex); if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { // handle most cases here (ch is a BMP code point or a // negative value (invalid code point)) final char[] value = this.buf; int i = Math.min(fromIndex, length() - 1 + begin); for (; i >= begin; i--) { if (value[i] == ch) { return toExternalId(i); } } return -1; } else { return toExternalId(lastIndexOfSupplementary(ch, fromIndex)); } }
public int lastIndexOf(int ch, int fromIndex) { fromIndex = toInternalId(fromIndex); if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) { // handle most cases here (ch is a BMP code point or a // negative value (invalid code point)) final char[] value = this.buf; int i = Math.min(fromIndex, length() - 1 + begin); for (; i >= begin; i--) { if (value[i] == ch) { return toExternalId(i); } } return -1; } else { return toExternalId(lastIndexOfSupplementary(ch, fromIndex)); } }