@Override CharSequence trimTrailingPadding(CharSequence chars) { checkNotNull(chars); if (paddingChar == null) { return chars; } char padChar = paddingChar.charValue(); int l; for (l = chars.length() - 1; l >= 0; l--) { if (chars.charAt(l) != padChar) { break; } } return chars.subSequence(0, l + 1); }
@Override public Writer append(CharSequence csq, int start, int end) { CharSequence cs = (csq == null ? "null" : csq); write(cs.subSequence(start, end).toString()); return this; }
@Override public Writer append(CharSequence csq, int start, int end) { CharSequence cs = (csq == null ? "null" : csq); write(cs.subSequence(start, end).toString()); return this; }
public CharSequence subSequence(int start, int end) { return new MatcherInput(this.value.subSequence(start, end), this.access); }
final void insert0 (int index, CharSequence s, int start, int end) { if (s == null) { s = "null"; } if (index < 0 || index > length || start < 0 || end < 0 || start > end || end > s.length()) { throw new IndexOutOfBoundsException(); } insert0(index, s.subSequence(start, end).toString()); }
final void append0 (CharSequence s, int start, int end) { if (s == null) { s = "null"; } if (start < 0 || end < 0 || start > end || end > s.length()) { throw new IndexOutOfBoundsException(); } append0(s.subSequence(start, end).toString()); }
final void append0 (CharSequence s, int start, int end) { if (s == null) { s = "null"; } if (start < 0 || end < 0 || start > end || end > s.length()) { throw new IndexOutOfBoundsException(); } append0(s.subSequence(start, end).toString()); }
final void insert0 (int index, CharSequence s, int start, int end) { if (s == null) { s = "null"; } if (index < 0 || index > length || start < 0 || end < 0 || start > end || end > s.length()) { throw new IndexOutOfBoundsException(); } insert0(index, s.subSequence(start, end).toString()); }
/** * Returns a substring of the input character sequence that omits all matching BMP characters from * the end of the string. For example: * * <pre>{@code * CharMatcher.anyOf("ab").trimTrailingFrom("abacatbab") * }</pre> * * ... returns {@code "abacat"}. */ public String trimTrailingFrom(CharSequence sequence) { int len = sequence.length(); for (int last = len - 1; last >= 0; last--) { if (!matches(sequence.charAt(last))) { return sequence.subSequence(0, last + 1).toString(); } } return ""; }
public CharBuffer slice () { return new CharSequenceAdapter(sequence.subSequence(position, limit)); }
/** * Returns a substring of the input character sequence that omits all matching BMP characters from * the beginning of the string. For example: * * <pre>{@code * CharMatcher.anyOf("ab").trimLeadingFrom("abacatbab") * }</pre> * * ... returns {@code "catbab"}. */ public String trimLeadingFrom(CharSequence sequence) { int len = sequence.length(); for (int first = 0; first < len; first++) { if (!matches(sequence.charAt(first))) { return sequence.subSequence(first, len).toString(); } } return ""; }
public CharBuffer slice () { return new CharSequenceAdapter(sequence.subSequence(position, limit)); }
/** * Decode a 2-digit hex byte from within a string. */ public static byte decodeHexByte(CharSequence s, int pos) { int hi = decodeHexNibble(s.charAt(pos)); int lo = decodeHexNibble(s.charAt(pos + 1)); if (hi == -1 || lo == -1) { throw new IllegalArgumentException(String.format( "invalid hex byte '%s' at index %d of '%s'", s.subSequence(pos, pos + 2), pos, s)); } return (byte) ((hi << 4) + lo); }
@Override public Writer append(CharSequence csq, int start, int end) { String str = csq.subSequence(start, end).toString(); _buffer.append(str, 0, str.length()); return this; }
@Override public Writer append(CharSequence csq, int start, int end) { String str = csq.subSequence(start, end).toString(); _buffer.append(str, 0, str.length()); return this; }
/** * Returns the longest string {@code suffix} such that {@code a.toString().endsWith(suffix) && * b.toString().endsWith(suffix)}, taking care not to split surrogate pairs. If {@code a} and * {@code b} have no common suffix, returns the empty string. * * @since 11.0 */ public static String commonSuffix(CharSequence a, CharSequence b) { checkNotNull(a); checkNotNull(b); int maxSuffixLength = Math.min(a.length(), b.length()); int s = 0; while (s < maxSuffixLength && a.charAt(a.length() - s - 1) == b.charAt(b.length() - s - 1)) { s++; } if (validSurrogatePairAt(a, a.length() - s - 1) || validSurrogatePairAt(b, b.length() - s - 1)) { s--; } return a.subSequence(a.length() - s, a.length()).toString(); }
/** * Returns the longest string {@code prefix} such that {@code a.toString().startsWith(prefix) && * b.toString().startsWith(prefix)}, taking care not to split surrogate pairs. If {@code a} and * {@code b} have no common prefix, returns the empty string. * * @since 11.0 */ public static String commonPrefix(CharSequence a, CharSequence b) { checkNotNull(a); checkNotNull(b); int maxPrefixLength = Math.min(a.length(), b.length()); int p = 0; while (p < maxPrefixLength && a.charAt(p) == b.charAt(p)) { p++; } if (validSurrogatePairAt(a, p - 1) || validSurrogatePairAt(b, p - 1)) { p--; } return a.subSequence(0, p).toString(); }
/** * Decode a 2-digit hex byte from within a string. */ public static byte decodeHexByte(CharSequence s, int pos) { int hi = decodeHexNibble(s.charAt(pos)); int lo = decodeHexNibble(s.charAt(pos + 1)); if (hi == -1 || lo == -1) { throw new IllegalArgumentException(String.format( "invalid hex byte '%s' at index %d of '%s'", s.subSequence(pos, pos + 2), pos, s)); } return (byte) ((hi << 4) + lo); }
/** * Trim optional white-space characters from the specified value, * according to <a href="https://tools.ietf.org/html/rfc7230#section-7">RFC-7230</a>. * * @param value the value to trim * @return {@link CharSequence} the trimmed value if necessary, or the value unchanged */ public static CharSequence trimOws(CharSequence value) { final int length = value.length(); if (length == 0) { return value; } int start = indexOfFirstNonOwsChar(value, length); int end = indexOfLastNonOwsChar(value, start, length); return start == 0 && end == length - 1 ? value : value.subSequence(start, end + 1); }
@Override public CharSequence subSequence(final int start, final int end) { return new CustomCharSequence(seq.subSequence(start, end)); }