@Override protected final int nextEscapeIndex(CharSequence csq, int index, int end) { while (index < end) { char c = csq.charAt(index); if ((c < replacementsLength && replacements[c] != null) || c > safeMaxChar || c < safeMinChar) { break; } index++; } return index; }
@Override protected int nextEscapeIndex(CharSequence csq, int index, int end) { checkNotNull(csq); for (; index < end; index++) { char c = csq.charAt(index); if (c >= safeOctets.length || !safeOctets[c]) { break; } } return index; }
/** * Determine if the string {@code s} ends with the char {@code c}. * * @param s the string to test * @param c the tested char * @return true if {@code s} ends with the char {@code c} */ public static boolean endsWith(CharSequence s, char c) { int len = s.length(); return len > 0 && s.charAt(len - 1) == c; }
/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); }
private static boolean containsText(CharSequence str) { int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
public static int lineNumber(CharSequence s, int index) { int cnt = 1; for (int i = 0; i < index; i++) { if (s.charAt(i) == '\n') { cnt++; } } return cnt; }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
@Override public HashCode hashUnencodedChars(CharSequence input) { int len = input.length(); ByteBuffer buffer = ByteBuffer.allocate(len * 2).order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < len; i++) { buffer.putChar(input.charAt(i)); } return hashBytes(buffer.array()); }
@Override public Hasher putUnencodedChars(CharSequence charSequence) { for (int i = 0, len = charSequence.length(); i < len; i++) { putChar(charSequence.charAt(i)); } return this; }
@Override int decodeTo(byte[] target, CharSequence chars) throws DecodingException { StringBuilder stripped = new StringBuilder(chars.length()); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { stripped.append(c); } } return delegate.decodeTo(target, stripped); }
public char charAt(int index) { this.access.check(); return this.value.charAt(index); }
/** * Returns the number of matching {@code char}s found in a character sequence. * * <p>Counts 2 per supplementary character, such as for {@link #whitespace}().{@link #negate}(). */ public int countIn(CharSequence sequence) { int count = 0; for (int i = 0; i < sequence.length(); i++) { if (matches(sequence.charAt(i))) { count++; } } return count; }
@Override int decodeTo(byte[] target, CharSequence chars) throws DecodingException { checkNotNull(target); if (chars.length() % 2 == 1) { throw new DecodingException("Invalid input length " + chars.length()); } int bytesWritten = 0; for (int i = 0; i < chars.length(); i += 2) { int decoded = alphabet.decode(chars.charAt(i)) << 4 | alphabet.decode(chars.charAt(i + 1)); target[bytesWritten++] = (byte) decoded; } return bytesWritten; }
@Override public boolean apply(CharSequence input) { return (input.length() > 0) && (input.charAt(0) == 'a'); } };
@Override protected int nextEscapeIndex(CharSequence csq, int index, int end) { while (index < end && !Character.isLetter(csq.charAt(index))) { index++; } return index; } };
@Override public synchronized int read(CharBuffer target) throws IOException { checkNotNull(target); checkOpen(); if (!hasRemaining()) { return -1; } int charsToRead = Math.min(target.remaining(), remaining()); for (int i = 0; i < charsToRead; i++) { target.put(seq.charAt(pos++)); } return charsToRead; }
@Override public synchronized int read() throws IOException { checkOpen(); return hasRemaining() ? seq.charAt(pos++) : -1; }
@Override public Character get(int index) { checkElementIndex(index, size()); // for GWT return sequence.charAt(index); }
@Override public boolean canDecode(CharSequence chars) { checkNotNull(chars); chars = trimTrailingPadding(chars); if (!alphabet.isValidPaddingStartPosition(chars.length())) { return false; } for (int i = 0; i < chars.length(); i++) { if (!alphabet.canDecode(chars.charAt(i))) { return false; } } return true; }
@Override public synchronized int read(char[] cbuf, int off, int len) throws IOException { checkPositionIndexes(off, off + len, cbuf.length); checkOpen(); if (!hasRemaining()) { return -1; } int charsToRead = Math.min(len, remaining()); for (int i = 0; i < charsToRead; i++) { cbuf[off + i] = seq.charAt(pos++); } return charsToRead; }