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

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

本文整理了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

  1. /**
  2. * Asserts that a Unicode escaper escapes the given hi/lo surrogate pair into the expected string.
  3. *
  4. * @param escaper the non-null escaper to test
  5. * @param expected the expected output string
  6. * @param hi the high surrogate pair character
  7. * @param lo the low surrogate pair character
  8. */
  9. public static void assertUnicodeEscaping(
  10. UnicodeEscaper escaper, String expected, char hi, char lo) {
  11. int cp = Character.toCodePoint(hi, lo);
  12. String escaped = computeReplacement(escaper, cp);
  13. Assert.assertNotNull(escaped);
  14. Assert.assertEquals(expected, escaped);
  15. }
  16. }

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

  1. @Override
  2. public int accepts(int strIndex, CharSequence testString) {
  3. char high = testString.charAt(strIndex++);
  4. char low = testString.charAt(strIndex);
  5. return (this.ch == Character.toLowerCase(Character.toUpperCase(Character.toCodePoint(high, low)))) ? 2 : -1;
  6. }

代码示例来源:origin: line/armeria

  1. int nextCodePoint() {
  2. assert pos < end;
  3. final char c1 = str.charAt(pos++);
  4. if (Character.isHighSurrogate(c1) && pos < end) {
  5. final char c2 = str.charAt(pos);
  6. if (Character.isLowSurrogate(c2)) {
  7. pos++;
  8. return Character.toCodePoint(c1, c2);
  9. }
  10. }
  11. return c1;
  12. }
  13. }

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

  1. return Character.toCodePoint(c1, c2);

代码示例来源:origin: termux/termux-app

  1. private boolean wideDisplayCharacterStartingAt(int column) {
  2. for (int currentCharIndex = 0, currentColumn = 0; currentCharIndex < mSpaceUsed; ) {
  3. char c = mText[currentCharIndex++];
  4. int codePoint = Character.isHighSurrogate(c) ? Character.toCodePoint(c, mText[currentCharIndex++]) : c;
  5. int wcwidth = WcWidth.width(codePoint);
  6. if (wcwidth > 0) {
  7. if (currentColumn == column && wcwidth == 2) return true;
  8. currentColumn += wcwidth;
  9. if (currentColumn > column) return false;
  10. }
  11. }
  12. return false;
  13. }

代码示例来源:origin: aNNiMON/Lightweight-Stream-API

  1. @Override
  2. public int nextInt() {
  3. final int length = ensureLength();
  4. if (current >= length) {
  5. throw new NoSuchElementException();
  6. }
  7. final char nextChar = charSequence.charAt(current++);
  8. if (Character.isHighSurrogate(nextChar) && current < length) {
  9. final char currentChar = charSequence.charAt(current);
  10. if (Character.isLowSurrogate(currentChar)) {
  11. current++;
  12. return Character.toCodePoint(nextChar, currentChar);
  13. }
  14. }
  15. return nextChar;
  16. }

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

  1. public ByteStringBuilder append(String s, int offs, int len) {
  2. int c;
  3. int i = 0;
  4. while (i < len) {
  5. c = s.charAt(offs + i++);
  6. if (Character.isHighSurrogate((char) c)) {
  7. if (i < len) {
  8. char t = s.charAt(offs + i ++);
  9. if (! Character.isLowSurrogate(t)) {
  10. throw new IllegalArgumentException();
  11. }
  12. c = Character.toCodePoint((char) c, t);
  13. } else {
  14. throw new IllegalArgumentException();
  15. }
  16. }
  17. appendUtf8Raw(c);
  18. }
  19. return this;
  20. }

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

  1. public ByteStringBuilder append(CharSequence s, int offs, int len) {
  2. int c;
  3. int i = 0;
  4. while (i < len) {
  5. c = s.charAt(offs + i++);
  6. if (Character.isHighSurrogate((char) c)) {
  7. if (i < len) {
  8. char t = s.charAt(offs + i ++);
  9. if (! Character.isLowSurrogate(t)) {
  10. throw new IllegalArgumentException();
  11. }
  12. c = Character.toCodePoint((char) c, t);
  13. } else {
  14. throw new IllegalArgumentException();
  15. }
  16. }
  17. appendUtf8Raw(c);
  18. }
  19. return this;
  20. }

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

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

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

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

代码示例来源:origin: termux/termux-app

  1. /** The width at an index position in a java char array. */
  2. public static int width(char[] chars, int index) {
  3. char c = chars[index];
  4. return Character.isHighSurrogate(c) ? width(Character.toCodePoint(c, chars[index + 1])) : width(c);
  5. }

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

  1. private static int readCP(Reader r) throws IOException {
  2. int hi, lo;
  3. hi = r.read();
  4. if (hi == -1) {
  5. return -1;
  6. }
  7. if (Character.isHighSurrogate((char) hi)) {
  8. lo = r.read();
  9. if (lo == -1) throw log.unexpectedEof();
  10. if (Character.isLowSurrogate((char) lo)) {
  11. return Character.toCodePoint((char) hi, (char) lo);
  12. } else {
  13. throw new CharacterCodingException();
  14. }
  15. } else {
  16. return hi;
  17. }
  18. }

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

  1. private boolean JavaLetter_sempred(RuleContext _localctx, int predIndex) {
  2. switch (predIndex) {
  3. case 0:
  4. return Character.isJavaIdentifierStart(_input.LA(-1));
  5. case 1:
  6. return Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)));
  7. }
  8. return true;
  9. }
  10. private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) {

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

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

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

  1. private int nextCodePoint() {
  2. char high = pattern[nextIndex()];
  3. if (Character.isHighSurrogate(high)) {
  4. // low and high char may be delimited by spaces
  5. int lowExpectedIndex = prevNW + 1;
  6. if (lowExpectedIndex < pattern.length) {
  7. char low = pattern[lowExpectedIndex];
  8. if (Character.isLowSurrogate(low)) {
  9. nextIndex();
  10. return Character.toCodePoint(high, low);
  11. }
  12. }
  13. }
  14. return high;
  15. }

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

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

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

  1. private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) {
  2. if (!Character.isLowSurrogate(c2)) {
  3. buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
  4. buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2);
  5. return writerIndex;
  6. }
  7. int codePoint = Character.toCodePoint(c, c2);
  8. // See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
  9. buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
  10. buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
  11. buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
  12. buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
  13. return writerIndex;
  14. }

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

  1. private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) {
  2. if (!Character.isLowSurrogate(c2)) {
  3. buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
  4. buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2);
  5. return writerIndex;
  6. }
  7. int codePoint = Character.toCodePoint(c, c2);
  8. // See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630.
  9. buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18)));
  10. buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f)));
  11. buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f)));
  12. buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f)));
  13. return writerIndex;
  14. }

代码示例来源:origin: termux/termux-app

  1. private void assertLineStartsWith(int... codePoints) {
  2. char[] chars = row.mText;
  3. int charIndex = 0;
  4. for (int i = 0; i < codePoints.length; i++) {
  5. int lineCodePoint = chars[charIndex++];
  6. if (Character.isHighSurrogate((char) lineCodePoint)) {
  7. lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]);
  8. }
  9. assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint);
  10. }
  11. }

代码示例来源:origin: termux/termux-app

  1. protected TerminalTestCase assertLineStartsWith(int line, int... codePoints) {
  2. char[] chars = mTerminal.getScreen().mLines[mTerminal.getScreen().externalToInternalRow(line)].mText;
  3. int charIndex = 0;
  4. for (int i = 0; i < codePoints.length; i++) {
  5. int lineCodePoint = chars[charIndex++];
  6. if (Character.isHighSurrogate((char) lineCodePoint)) {
  7. lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]);
  8. }
  9. assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint);
  10. }
  11. return this;
  12. }

相关文章

Character类方法