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

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

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

Character.highSurrogate介绍

[英]Returns the high surrogate for the given code point. The result is meaningless if the given code point is not a supplementary character.
[中]返回给定代码点的高代理项。如果给定的代码点不是补充字符,则结果没有意义。

代码示例

代码示例来源:origin: goldmansachs/gs-collections

public char charAt(int index)
{
  int currentIndex = 0;
  for (int i = 0; i < this.codePoints.size(); i++)
  {
    int codePoint = this.codePoints.get(i);
    int charCount = Character.charCount(codePoint);
    if (index < currentIndex + charCount)
    {
      if (charCount == 1)
      {
        return (char) codePoint;
      }
      if (index == currentIndex)
      {
        return Character.highSurrogate(codePoint);
      }
      return Character.lowSurrogate(codePoint);
    }
    currentIndex += charCount;
  }
  throw new IndexOutOfBoundsException("Char value at " + index + " is out of bounds for length " + currentIndex);
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public char charAt(int index)
{
  int currentIndex = 0;
  for (int i = 0; i < this.codePoints.size(); i++)
  {
    int codePoint = this.codePoints.get(i);
    int charCount = Character.charCount(codePoint);
    if (index < currentIndex + charCount)
    {
      if (charCount == 1)
      {
        return (char) codePoint;
      }
      if (index == currentIndex)
      {
        return Character.highSurrogate(codePoint);
      }
      return Character.lowSurrogate(codePoint);
    }
    currentIndex += charCount;
  }
  throw new IndexOutOfBoundsException("Char value at " + index + " is out of bounds for length " + currentIndex);
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public char charAt(int index)
{
  int currentIndex = 0;
  for (int i = 0; i < this.codePoints.size(); i++)
  {
    int codePoint = this.codePoints.get(i);
    int charCount = Character.charCount(codePoint);
    if (index < currentIndex + charCount)
    {
      if (charCount == 1)
      {
        return (char) codePoint;
      }
      if (index == currentIndex)
      {
        return Character.highSurrogate(codePoint);
      }
      return Character.lowSurrogate(codePoint);
    }
    currentIndex += charCount;
  }
  throw new IndexOutOfBoundsException("Char value at " + index + " is out of bounds for length " + currentIndex);
}

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

outArray[outPos++] = Character.highSurrogate(code);
  outArray[outPos++] = Character.lowSurrogate(code);
} else {

代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini

static void toSurrogates(int codePoint, char[] dst, int index) {
  // We write elements "backwards" to guarantee all-or-nothing
  dst[index+1] = lowSurrogate(codePoint);
  dst[index] = highSurrogate(codePoint);
}

代码示例来源:origin: org.osgl/osgl-tool

static void toSurrogates(int codePoint, char[] dst, int index) {
    // We write elements "backwards" to guarantee all-or-nothing
    dst[index + 1] = lowSurrogate(codePoint);
    dst[index] = highSurrogate(codePoint);
  }
}

代码示例来源:origin: osglworks/java-tool

static void toSurrogates(int codePoint, char[] dst, int index) {
    // We write elements "backwards" to guarantee all-or-nothing
    dst[index + 1] = lowSurrogate(codePoint);
    dst[index] = highSurrogate(codePoint);
  }
}

代码示例来源:origin: stackoverflow.com

//  byte[] bytes = new byte[] { (byte) 0xD8, 0x34, (byte) 0xDD, 0x1E };
String text = ""; // new String(bytes, StandardCharsets.UTF_16);
int codePoint = text.codePointAt(0);

ByteBuffer buf = ByteBuffer.allocate(4);
buf.putChar(Character.highSurrogate(codePoint));
buf.putChar(Character.lowSurrogate(codePoint));
byte[] data = buf.array();

// recreated
String rep = new String(data, StandardCharsets.UTF_16);

代码示例来源:origin: jtulach/bck2brwsr

static void toSurrogates(int codePoint, char[] dst, int index) {
  // We write elements "backwards" to guarantee all-or-nothing
  dst[index+1] = lowSurrogate(codePoint);
  dst[index] = highSurrogate(codePoint);
}

代码示例来源:origin: org.antlr/antlr4

static public void appendJavaStyleEscapedCodePoint(int codePoint, StringBuilder sb) {
  if (Character.isSupplementaryCodePoint(codePoint)) {
    // char is not an 'integral' type, so we have to explicitly convert
    // to int before passing to the %X formatter or else it throws.
    sb.append(String.format("\\u%04X", (int)Character.highSurrogate(codePoint)));
    sb.append(String.format("\\u%04X", (int)Character.lowSurrogate(codePoint)));
  }
  else {
    sb.append(String.format("\\u%04X", codePoint));
  }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

static public void appendJavaStyleEscapedCodePoint(int codePoint, StringBuilder sb) {
  if (Character.isSupplementaryCodePoint(codePoint)) {
    // char is not an 'integral' type, so we have to explicitly convert
    // to int before passing to the %X formatter or else it throws.
    sb.append(String.format("\\u%04X", (int)Character.highSurrogate(codePoint)));
    sb.append(String.format("\\u%04X", (int)Character.lowSurrogate(codePoint)));
  }
  else {
    sb.append(String.format("\\u%04X", codePoint));
  }
}

代码示例来源:origin: stackoverflow.com

Character.highSurrogate(codePoint);
Character.lowSurrogate(codePoint);

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client

/**
   * Appends the characters from codepoint into the string builder. This is the same as Character#toChars
   * but prevents the additional char array garbage for BMP codepoints.
   * 
   * @param dst
   *        the destination in which to append the characters
   * @param codePoint
   *        the codepoint to be appended
   */
  private static void appendCodepoint(StringBuilder dst, int codePoint) {
    if (Character.isBmpCodePoint(codePoint)) {
      dst.append((char)codePoint);
    }
    else if (Character.isValidCodePoint(codePoint)) {
      dst.append(Character.highSurrogate(codePoint));
      dst.append(Character.lowSurrogate(codePoint));
    }
    else {
      throw new IllegalArgumentException("Invalid codepoint " + codePoint);
    }
  }
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Appends the given code point to the underlying {@link #out} stream or buffer.
 *
 * @param  c  the code point to append.
 * @throws IOException if an error occurred while appending the code point.
 */
final void appendCodePoint(final int c) throws IOException {
  if (Character.isBmpCodePoint(c)) {
    out.append((char) c);
  } else if (Character.isSupplementaryCodePoint(c)) {
    out.append(Character.highSurrogate(c))
      .append(Character. lowSurrogate(c));
  } else {
    throw new CharConversionException();
  }
}

代码示例来源:origin: anba/es6draft

@Override
public int codeToMbc(int code, byte[] bytes, int p) {
  if (Character.isBmpCodePoint(code)) {
    bytes[p + 0] = (byte) (code >>> 8);
    bytes[p + 1] = (byte) (code >>> 0);
    return 2;
  }
  char high = Character.highSurrogate(code);
  char low = Character.lowSurrogate(code);
  bytes[p + 0] = (byte) (high >>> 8);
  bytes[p + 1] = (byte) (high >>> 0);
  bytes[p + 2] = (byte) (low >>> 8);
  bytes[p + 3] = (byte) (low >>> 0);
  return 4;
}

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

/**
 * Appends the given code point to the underlying {@link #out} stream or buffer.
 *
 * @param  c  the code point to append.
 * @throws IOException if an error occurred while appending the code point.
 */
final void appendCodePoint(final int c) throws IOException {
  if (Character.isBmpCodePoint(c)) {
    out.append((char) c);
  } else if (Character.isSupplementaryCodePoint(c)) {
    out.append(Character.highSurrogate(c))
      .append(Character. lowSurrogate(c));
  } else {
    throw new CharConversionException();
  }
}

代码示例来源:origin: com.goldmansachs/gs-collections

public char charAt(int index)
{
  int currentIndex = 0;
  for (int i = 0; i < this.codePoints.size(); i++)
  {
    int codePoint = this.codePoints.get(i);
    int charCount = Character.charCount(codePoint);
    if (index < currentIndex + charCount)
    {
      if (charCount == 1)
      {
        return (char) codePoint;
      }
      if (index == currentIndex)
      {
        return Character.highSurrogate(codePoint);
      }
      return Character.lowSurrogate(codePoint);
    }
    currentIndex += charCount;
  }
  throw new IndexOutOfBoundsException("Char value at " + index + " is out of bounds for length " + currentIndex);
}

代码示例来源:origin: org.ceylon-lang/ceylon.language

void appendCodepoint(int codepoint) {
    if (Character.charCount(codepoint) == 1) {
      appendChar((char)codepoint);
    } else {
      appendChar(Character.highSurrogate(codepoint));
      appendChar(Character.lowSurrogate(codepoint));
    }
  }
}

代码示例来源:origin: bluestreak01/questdb

private static int utf8Decode4Bytes(long lo, int b, long hi, CharSink sink) {
  if (b >> 3 != -2) {
    return utf8error();
  }
  if (hi - lo > 3) {
    byte b2 = Unsafe.getUnsafe().getByte(lo + 1);
    byte b3 = Unsafe.getUnsafe().getByte(lo + 2);
    byte b4 = Unsafe.getUnsafe().getByte(lo + 3);
    int codePoint = b << 18 ^ b2 << 12 ^ b3 << 6 ^ b4 ^ 3678080;
    if (!isMalformed4(b2, b3, b4) && Character.isSupplementaryCodePoint(codePoint)) {
      sink.put(Character.highSurrogate(codePoint));
      sink.put(Character.lowSurrogate(codePoint));
      return 4;
    }
  }
  return utf8error();
}

代码示例来源:origin: anba/es6draft

/**
 * Appends the code point to the buffer.
 * 
 * @param c
 *            the code point
 */
public void appendCodePoint(int c) {
  if (Character.isBmpCodePoint(c)) {
    append(c);
  } else {
    append(Character.highSurrogate(c));
    append(Character.lowSurrogate(c));
  }
}

相关文章

微信公众号

最新文章

更多

Character类方法