java.lang.Character.isLowSurrogate()方法的使用及代码示例

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

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

Character.isLowSurrogate介绍

[英]Indicates whether ch is a low- (or trailing-) 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: wildfly/wildfly

private void processChar(final int ch) {
  switch (ch) {
    case '\n': {
      characterOffset++;
      lineNumber++;
      columnNumber = 1;
      break;
    }
    default: {
      if (! Character.isLowSurrogate((char) ch)) {
        characterOffset++;
        columnNumber++;
      }
      break;
    }
  }
}

代码示例来源: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: 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: 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: 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: 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: 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: google/guava

if (Character.isLowSurrogate(c2)) {
 return Character.toCodePoint(c1, c2);

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

if (!Character.isLowSurrogate(c2)) {

代码示例来源:origin: org.apache.commons/commons-lang3

if (Character.isHighSurrogate(c1) && pos < len) {
  final char c2 = input.charAt(pos);
  if (Character.isLowSurrogate(c2)) {
   out.write(c2);
   pos++;

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

if (!Character.isLowSurrogate(c2)) {

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

private static int readCP(Reader r) throws IOException {
  int hi, lo;
  hi = r.read();
  if (hi == -1) {
    return -1;
  }
  if (Character.isHighSurrogate((char) hi)) {
    lo = r.read();
    if (lo == -1) throw log.unexpectedEof();
    if (Character.isLowSurrogate((char) lo)) {
      return Character.toCodePoint((char) hi, (char) lo);
    } else {
      throw new CharacterCodingException();
    }
  } else {
    return hi;
  }
}

代码示例来源: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: jphp-group/jphp

@FastMethod
@Signature(@Arg("char"))
public static Memory isLowSurrogate(Environment env, Memory... args) {
  return Character.isLowSurrogate(chr(args[0])) ? Memory.TRUE : Memory.FALSE;
}

代码示例来源: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);
}

相关文章

Character类方法