本文整理了Java中java.lang.Character.isHighSurrogate()
方法的一些代码示例,展示了Character.isHighSurrogate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.isHighSurrogate()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:isHighSurrogate
[英]Indicates whether ch is a high- (or leading-) surrogate code unit that is used for representing supplementary characters in UTF-16 encoding.
[中]指示ch是否为高位(或前导)代理代码单元,用于表示UTF-16编码中的补充字符。
代码示例来源: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: google/j2objc
/**
* 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: apache/kafka
/**
* Get the length for UTF8-encoding a string without encoding it first
*
* @param s The string to calculate the length for
* @return The length when serialized
*/
public static int utf8Length(CharSequence s) {
int count = 0;
for (int i = 0, len = s.length(); i < len; i++) {
char ch = s.charAt(i);
if (ch <= 0x7F) {
count++;
} else if (ch <= 0x7FF) {
count += 2;
} else if (Character.isHighSurrogate(ch)) {
count += 4;
++i;
} else {
count += 3;
}
}
return count;
}
代码示例来源:origin: prestodb/presto
/**
* 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: wildfly/wildfly
/**
* 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: goldmansachs/gs-collections
public static boolean isSurrogate(String string, int i)
{
return Character.isLowSurrogate(string.charAt(i - 1)) && Character.isHighSurrogate(string.charAt(i - 2));
}
代码示例来源:origin: google/truth
private static boolean validSurrogatePairAt(CharSequence string, int index) {
return index >= 0
&& index <= (string.length() - 2)
&& isHighSurrogate(string.charAt(index))
&& isLowSurrogate(string.charAt(index + 1));
}
}
代码示例来源:origin: line/armeria
int nextCodePoint() {
assert pos < end;
final char c1 = str.charAt(pos++);
if (Character.isHighSurrogate(c1) && pos < end) {
final char c2 = str.charAt(pos);
if (Character.isLowSurrogate(c2)) {
pos++;
return Character.toCodePoint(c1, c2);
}
}
return c1;
}
}
代码示例来源:origin: eclipse/eclipse-collections
public static boolean isSurrogate(String string, int i)
{
return Character.isLowSurrogate(string.charAt(i - 1)) && Character.isHighSurrogate(string.charAt(i - 2));
}
代码示例来源:origin: netty/netty
if (!Character.isHighSurrogate(c)) {
encodedLength++;
代码示例来源:origin: termux/termux-app
private boolean wideDisplayCharacterStartingAt(int column) {
for (int currentCharIndex = 0, currentColumn = 0; currentCharIndex < mSpaceUsed; ) {
char c = mText[currentCharIndex++];
int codePoint = Character.isHighSurrogate(c) ? Character.toCodePoint(c, mText[currentCharIndex++]) : c;
int wcwidth = WcWidth.width(codePoint);
if (wcwidth > 0) {
if (currentColumn == column && wcwidth == 2) return true;
currentColumn += wcwidth;
if (currentColumn > column) return false;
}
}
return false;
}
代码示例来源:origin: termux/termux-app
/** The width at an index position in a java char array. */
public static int width(char[] chars, int index) {
char c = chars[index];
return Character.isHighSurrogate(c) ? width(Character.toCodePoint(c, chars[index + 1])) : width(c);
}
代码示例来源:origin: netty/netty
private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) {
if (!Character.isLowSurrogate(c2)) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2);
return writerIndex;
}
int codePoint = Character.toCodePoint(c, c2);
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
return writerIndex;
}
代码示例来源:origin: redisson/redisson
private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) {
if (!Character.isLowSurrogate(c2)) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2);
return writerIndex;
}
int codePoint = Character.toCodePoint(c, c2);
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
return writerIndex;
}
代码示例来源:origin: apache/hive
private static String composeString(int len, Random r) {
char[] cc = new char[len];
char ch;
for (int i = 0; i<len; i++) {
do {
ch = (char)r.nextInt();
} while (!Character.isDefined(ch)
|| Character.isHighSurrogate(ch)
|| Character.isLowSurrogate(ch));
cc[i] = ch;
}
return new String(cc);
}
代码示例来源:origin: termux/termux-app
private void assertLineStartsWith(int... codePoints) {
char[] chars = row.mText;
int charIndex = 0;
for (int i = 0; i < codePoints.length; i++) {
int lineCodePoint = chars[charIndex++];
if (Character.isHighSurrogate((char) lineCodePoint)) {
lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]);
}
assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint);
}
}
代码示例来源:origin: jphp-group/jphp
@FastMethod
@Signature(@Arg("char"))
public static Memory isHighSurrogate(Environment env, Memory... args) {
return Character.isHighSurrogate(chr(args[0])) ? Memory.TRUE : Memory.FALSE;
}
代码示例来源:origin: netty/netty
buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
} else if (isSurrogate(c)) {
if (!Character.isHighSurrogate(c)) {
buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
continue;
代码示例来源:origin: ehcache/ehcache3
@Test
public void testBackwardsCompatibility() throws UnsupportedEncodingException, ClassNotFoundException {
StringSerializer serializer = new StringSerializer();
int codepoint = 65536;
do {
if (Character.isValidCodePoint(codepoint) && !(Character.isHighSurrogate((char) codepoint) || Character.isLowSurrogate((char) codepoint))) {
String s = new String(Character.toChars(codepoint));
ByteBuffer bytes = ByteBuffer.wrap(s.getBytes("UTF-8"));
assertThat("Codepoint : 0x" + Integer.toHexString(codepoint), serializer.read(bytes), is(s));
assertThat("Codepoint : 0x" + Integer.toHexString(codepoint), serializer.equals(s, bytes), is(true));
}
} while (++codepoint != Integer.MIN_VALUE);
}
代码示例来源:origin: termux/termux-app
protected TerminalTestCase assertLineStartsWith(int line, int... codePoints) {
char[] chars = mTerminal.getScreen().mLines[mTerminal.getScreen().externalToInternalRow(line)].mText;
int charIndex = 0;
for (int i = 0; i < codePoints.length; i++) {
int lineCodePoint = chars[charIndex++];
if (Character.isHighSurrogate((char) lineCodePoint)) {
lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]);
}
assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint);
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!