/** * Create a new text WebSocket message from the given CharSequence payload. * @param payload the non-null payload */ public TextMessage(CharSequence payload) { super(payload.toString(), true); this.bytes = null; }
/** * 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; }
/** * 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 ""; }
@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); }
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()); }
@Override public int size() { return sequence.length(); } }
@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 public Writer append(CharSequence csq, int start, int end) { CharSequence cs = (csq == null ? "null" : csq); write(cs.subSequence(start, end).toString()); return this; }
/** * 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); }
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()); }
/** * Gets a CharSequence length or {@code 0} if the CharSequence is * {@code null}. * * @param cs * a CharSequence or {@code null} * @return CharSequence length or {@code 0} if the CharSequence is * {@code null}. */ public static int length(final CharSequence cs) { return cs == null ? 0 : cs.length(); }
/** * Identical to {@link PlatformDependent0#hashCodeAsciiSanitize(short)} but for {@link CharSequence}. */ private static int hashCodeAsciiSanitizeShort(CharSequence value, int offset) { if (BIG_ENDIAN_NATIVE_ORDER) { // mimic a unsafe.getShort call on a big endian machine return (value.charAt(offset + 1) & 0x1f) | (value.charAt(offset) & 0x1f) << 8; } return (value.charAt(offset + 1) & 0x1f) << 8 | (value.charAt(offset) & 0x1f); }
@Override public Writer append(CharSequence csq, int start, int end) { CharSequence cs = (csq == null ? "null" : csq); write(cs.subSequence(start, end).toString()); return this; }
/** * Create a new text WebSocket message with the given payload representing the * full or partial message content. When the {@code isLast} boolean flag is set * to {@code false} the message is sent as partial content and more partial * messages will be expected until the boolean flag is set to {@code true}. * @param payload the non-null payload * @param isLast whether this the last part of a series of partial messages */ public TextMessage(CharSequence payload, boolean isLast) { super(payload.toString(), isLast); this.bytes = null; }
/** * 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 ""; }
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()); }
@Override public int lastIndexIn(CharSequence sequence) { return sequence.length() - 1; }