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

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

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

Character.toCodePoint介绍

[英]Converts a surrogate pair into a Unicode code point. This method assumes that the pair are valid surrogates. If the pair are not valid surrogates, then the result is indeterminate. The #isSurrogatePair(char,char) method should be used prior to this method to validate the pair.
[中]将代理项对转换为Unicode代码点。此方法假定该对是有效的代理项。如果该对不是有效的代理项,则结果是不确定的。在使用此方法之前,应先使用#isSurrogatePair(char,char)方法来验证对。

代码示例

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

/**
  * Asserts that a Unicode escaper escapes the given hi/lo surrogate pair into the expected string.
  *
  * @param escaper the non-null escaper to test
  * @param expected the expected output string
  * @param hi the high surrogate pair character
  * @param lo the low surrogate pair character
  */
 public static void assertUnicodeEscaping(
   UnicodeEscaper escaper, String expected, char hi, char lo) {

  int cp = Character.toCodePoint(hi, lo);
  String escaped = computeReplacement(escaper, cp);
  Assert.assertNotNull(escaped);
  Assert.assertEquals(expected, escaped);
 }
}

代码示例来源:origin: konsoletyper/teavm

@Override
public int accepts(int strIndex, CharSequence testString) {
  char high = testString.charAt(strIndex++);
  char low = testString.charAt(strIndex);
  return (this.ch == Character.toLowerCase(Character.toUpperCase(Character.toCodePoint(high, low)))) ? 2 : -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: google/guava

return Character.toCodePoint(c1, c2);

代码示例来源: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: aNNiMON/Lightweight-Stream-API

@Override
public int nextInt() {
  final int length = ensureLength();
  if (current >= length) {
    throw new NoSuchElementException();
  }
  final char nextChar = charSequence.charAt(current++);
  if (Character.isHighSurrogate(nextChar) && current < length) {
    final char currentChar = charSequence.charAt(current);
    if (Character.isLowSurrogate(currentChar)) {
      current++;
      return Character.toCodePoint(nextChar, currentChar);
    }
  }
  return nextChar;
}

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

public ByteStringBuilder append(String s, int offs, int len) {
  int c;
  int i = 0;
  while (i < len) {
    c = s.charAt(offs + i++);
    if (Character.isHighSurrogate((char) c)) {
      if (i < len) {
        char t = s.charAt(offs + i ++);
        if (! Character.isLowSurrogate(t)) {
          throw new IllegalArgumentException();
        }
        c = Character.toCodePoint((char) c, t);
      } else {
        throw new IllegalArgumentException();
      }
    }
    appendUtf8Raw(c);
  }
  return this;
}

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

public ByteStringBuilder append(CharSequence s, int offs, int len) {
  int c;
  int i = 0;
  while (i < len) {
    c = s.charAt(offs + i++);
    if (Character.isHighSurrogate((char) c)) {
      if (i < len) {
        char t = s.charAt(offs + i ++);
        if (! Character.isLowSurrogate(t)) {
          throw new IllegalArgumentException();
        }
        c = Character.toCodePoint((char) c, t);
      } else {
        throw new IllegalArgumentException();
      }
    }
    appendUtf8Raw(c);
  }
  return this;
}

代码示例来源:origin: apache/hive

public static int getRandomSupplementaryChar() {
 int lowSurrogate = 0xDC00 + rnd.nextInt(1024);
 //return 0xD8000000 + lowSurrogate;
 int highSurrogate = 0xD800;
 return Character.toCodePoint((char)highSurrogate, (char)lowSurrogate);
}

代码示例来源:origin: apache/hive

public static int getRandomSupplementaryChar() {
 int lowSurrogate = 0xDC00 + rnd.nextInt(1024);
 //return 0xD8000000 + lowSurrogate;
 int highSurrogate = 0xD800;
 return Character.toCodePoint((char)highSurrogate, (char)lowSurrogate);
}

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

private boolean JavaLetter_sempred(RuleContext _localctx, int predIndex) {
  switch (predIndex) {
  case 0:
    return Character.isJavaIdentifierStart(_input.LA(-1));
  case 1:
    return Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)));
  }
  return true;
}
private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) {

代码示例来源:origin: twosigma/beakerx

private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) {
  switch (predIndex) {
  case 2:
    return Character.isJavaIdentifierPart(_input.LA(-1));
  case 3:
    return Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)));
  }
  return true;
}

代码示例来源:origin: konsoletyper/teavm

private int nextCodePoint() {
  char high = pattern[nextIndex()];
  if (Character.isHighSurrogate(high)) {
    // low and high char may be delimited by spaces
    int lowExpectedIndex = prevNW + 1;
    if (lowExpectedIndex < pattern.length) {
      char low = pattern[lowExpectedIndex];
      if (Character.isLowSurrogate(low)) {
        nextIndex();
        return Character.toCodePoint(high, low);
      }
    }
  }
  return high;
}

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

+ (int) c);
char[] escaped = escape(Character.toCodePoint((char) pendingHighSurrogate, c));
if (escaped != null) {
  outputChars(escaped, escaped.length);

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

相关文章

Character类方法