本文整理了Java中java.lang.CharSequence.charAt()
方法的一些代码示例,展示了CharSequence.charAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CharSequence.charAt()
方法的具体详情如下:
包路径:java.lang.CharSequence
类名称:CharSequence
方法名:charAt
[英]Returns the character at the specified index, with the first character having index zero.
[中]返回指定索引处的字符,第一个字符的索引为零。
代码示例来源: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: google/guava
@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;
}
代码示例来源: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
/**
* 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));
}
代码示例来源:origin: spring-projects/spring-framework
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;
}
代码示例来源:origin: ReactiveX/RxJava
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;
}
代码示例来源:origin: google/guava
@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);
}
代码示例来源:origin: google/guava
@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());
}
代码示例来源:origin: google/guava
@Override
public Hasher putUnencodedChars(CharSequence charSequence) {
for (int i = 0, len = charSequence.length(); i < len; i++) {
putChar(charSequence.charAt(i));
}
return this;
}
代码示例来源:origin: google/guava
@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);
}
代码示例来源:origin: spring-projects/spring-framework
public char charAt(int index) {
this.access.check();
return this.value.charAt(index);
}
代码示例来源:origin: google/guava
/**
* 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;
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@Override
public boolean apply(CharSequence input) {
return (input.length() > 0) && (input.charAt(0) == 'a');
}
};
代码示例来源:origin: google/guava
@Override
protected int nextEscapeIndex(CharSequence csq, int index, int end) {
while (index < end && !Character.isLetter(csq.charAt(index))) {
index++;
}
return index;
}
};
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@Override
public synchronized int read() throws IOException {
checkOpen();
return hasRemaining() ? seq.charAt(pos++) : -1;
}
代码示例来源:origin: google/guava
@Override
public Character get(int index) {
checkElementIndex(index, size()); // for GWT
return sequence.charAt(index);
}
代码示例来源:origin: google/guava
@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;
}
代码示例来源:origin: google/guava
@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;
}
内容来源于网络,如有侵权,请联系作者删除!