java.lang.CharSequence类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中java.lang.CharSequence类的一些代码示例,展示了CharSequence类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CharSequence类的具体详情如下:
包路径:java.lang.CharSequence
类名称:CharSequence

CharSequence介绍

[英]This interface represents an ordered set of characters and defines the methods to probe them.
[中]此接口表示一组有序的字符,并定义探测这些字符的方法。

代码示例

代码示例来源:origin: spring-projects/spring-framework

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

代码示例来源:origin: netty/netty

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

代码示例来源:origin: google/guava

/**
 * 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 "";
}

代码示例来源:origin: google/guava

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

代码示例来源:origin: libgdx/libgdx

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

代码示例来源:origin: google/guava

@Override
 public int size() {
  return sequence.length();
 }
}

代码示例来源:origin: netty/netty

@Override
public byte convertToByte(CharSequence value) {
  if (value instanceof AsciiString && value.length() == 1) {
    return ((AsciiString) value).byteAt(0);
  }
  return Byte.parseByte(value.toString());
}

代码示例来源:origin: google/guava

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

代码示例来源:origin: apache/incubator-dubbo

@Override
public Writer append(CharSequence csq, int start, int end) {
  CharSequence cs = (csq == null ? "null" : csq);
  write(cs.subSequence(start, end).toString());
  return this;
}

代码示例来源:origin: netty/netty

/**
 * 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);
}

代码示例来源:origin: spring-projects/spring-framework

public CharSequence subSequence(int start, int end) {
  return new MatcherInput(this.value.subSequence(start, end), this.access);
}

代码示例来源:origin: libgdx/libgdx

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

代码示例来源:origin: apache/incubator-dubbo

/**
 * 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();
}

代码示例来源:origin: netty/netty

/**
 * 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);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Writer append(CharSequence csq, int start, int end) {
  CharSequence cs = (csq == null ? "null" : csq);
  write(cs.subSequence(start, end).toString());
  return this;
}

代码示例来源:origin: spring-projects/spring-framework

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

代码示例来源:origin: libgdx/libgdx

static int indexOf (CharSequence text, char ch, int start) {
  final int n = text.length();
  for (; start < n; start++)
    if (text.charAt(start) == ch) return start;
  return n;
}

代码示例来源:origin: google/guava

/**
 * 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 "";
}

代码示例来源:origin: libgdx/libgdx

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

代码示例来源:origin: google/guava

@Override
public int lastIndexIn(CharSequence sequence) {
 return sequence.length() - 1;
}

相关文章