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

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

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

Character.isValidCodePoint介绍

[英]Indicates whether codePoint is a valid Unicode code point.
[中]指示代码点是否为有效的Unicode代码点。

代码示例

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

private static void checkValidCodePoint(int codePoint) {
  if (!isValidCodePoint(codePoint)) {
    throw new IllegalArgumentException("Invalid code point: " + codePoint);
  }
}

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

private static IllegalArgumentException invalidExpressionSyntax(final String string, final int index) {
  String msg = CommonMessages.msg.invalidExpressionSyntax(index);
  StringBuilder b = new StringBuilder(msg.length() + string.length() + string.length() + 5);
  b.append(msg);
  b.append('\n').append('\t').append(string);
  b.append('\n').append('\t');
  for (int i = 0; i < index; i = string.offsetByCodePoints(i, 1)) {
    final int cp = string.codePointAt(i);
    if (Character.isWhitespace(cp)) {
      b.append(cp);
    } else if (Character.isValidCodePoint(cp) && ! Character.isISOControl(cp)) {
      b.append(' ');
    }
  }
  b.append('^');
  return new IllegalArgumentException(b.toString());
}

代码示例来源:origin: igniterealtime/Openfire

stopReading = true;
else if (Character.isValidCodePoint(codePoint)) {
  buffer.appendCodePoint(codePoint);
} else {

代码示例来源:origin: plutext/docx4j

public static void writeCodePointToUtf8(final int c, final OutputStream out) throws IOException {
  if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {

代码示例来源:origin: plutext/docx4j

c = str.codePointAt(i);
i += Character.charCount(c);
if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {

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

if (! Character.isValidCodePoint(delim)) {
  return EMPTY;

代码示例来源:origin: plutext/docx4j

c = str.codePointAt(i);
i += Character.charCount(c);
if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {

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

@SuppressWarnings("deprecation")
public void testStringInputsUtf8() {
 Random rng = new Random(0);
 for (int z = 0; z < 100; z++) {
  String str;
  int[] codePoints = new int[rng.nextInt(8)];
  for (int i = 0; i < codePoints.length; i++) {
   do {
    codePoints[i] = rng.nextInt(0x800);
   } while (!Character.isValidCodePoint(codePoints[i])
     || (codePoints[i] >= Character.MIN_SURROGATE
       && codePoints[i] <= Character.MAX_SURROGATE));
  }
  StringBuilder builder = new StringBuilder();
  for (int i = 0; i < codePoints.length; i++) {
   builder.appendCodePoint(codePoints[i]);
  }
  str = builder.toString();
  assertEquals(
    murmur3_32().hashBytes(str.getBytes(Charsets.UTF_8)),
    murmur3_32().hashString(str, Charsets.UTF_8));
 }
}

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

public static int getRandomCodePoint() {
 int codePoint;
 if (rnd.nextDouble() < 0.50) {
  codePoint = 32 + rnd.nextInt(90);
 } else {
  codePoint = getRandomSupplementaryChar();
 }
 if (!Character.isValidCodePoint(codePoint)) {
  System.out.println(Integer.toHexString(codePoint) + " is not a valid code point");
 }
 return codePoint;
}

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

public static int getRandomCodePoint() {
 int codePoint;
 if (rnd.nextDouble() < 0.50) {
  codePoint = 32 + rnd.nextInt(90);
 } else {
  codePoint = getRandomSupplementaryChar();
 }
 if (!Character.isValidCodePoint(codePoint)) {
  System.out.println(Integer.toHexString(codePoint) + " is not a valid code point");
 }
 return codePoint;
}

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

private CharSequence transformFromCharacter() {
  if (arg == null) {
    return padding("null", 0);
  }
  if (arg instanceof Character) {
    return padding(String.valueOf(arg), 0);
  } else if (arg instanceof Byte || arg instanceof Short || arg instanceof Integer) {
    int codePoint = ((Number) arg).intValue();
    if (!Character.isValidCodePoint(codePoint)) {
      throw new IllegalFormatCodePointException(codePoint);
    }
    CharSequence result = (codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT)
        ? String.valueOf((char) codePoint)
        : String.valueOf(Character.toChars(codePoint));
    return padding(result, 0);
  } else {
    throw badArgumentType();
  }
}

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

int i = 0;
boolean insertPrefix = (prefix != null);
boolean insertDelim = Character.isValidCodePoint(delim);
if (hasNext()) {
  if (insertPrefix) {

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

int i = 0;
boolean insertPrefix = (prefix != null);
boolean insertDelim = Character.isValidCodePoint(delim);
if (hasNext()) {
  if (insertPrefix) {

代码示例来源:origin: prestodb/presto

escapedCharacterBuilder.setLength(0);
int codePoint = Integer.parseInt(currentEscapedCode, 16);
check(Character.isValidCodePoint(codePoint), "Invalid escaped character: " + currentEscapedCode, context);
if (Character.isSupplementaryCodePoint(codePoint)) {
  unicodeStringBuilder.appendCodePoint(codePoint);

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

private void formatChar(char specifier, boolean upperCase) throws IOException {
  verifyFlags(specifier, MASK_FOR_CHAR_FORMAT);
  Object arg = args[argumentIndex];
  if (precision >= 0) {
    throw new TIllegalFormatPrecisionException(precision);
  }
  int c;
  if (arg instanceof Character) {
    c = (Character) arg;
  } else if (arg instanceof Byte) {
    c = (char) (byte) arg;
  } else if (arg instanceof Short) {
    c = (char) (short) arg;
  } else if (arg instanceof Integer) {
    c = (int) arg;
    if (!Character.isValidCodePoint(c)) {
      throw new TIllegalFormatCodePointException(c);
    }
  } else if (arg == null) {
    formatGivenString(upperCase, "null");
    return;
  } else {
    throw new IllegalFormatConversionException(specifier, arg != null ? arg.getClass() : null);
  }
  formatGivenString(upperCase, new String(Character.toChars(c)));
}

代码示例来源: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: peter-lawrey/Java-Chronicle

sb.setLength(0);
for (int j = i; j < i + 16; j++) {
  if (Character.isValidCodePoint(j))
    sb.appendCodePoint(j);
sb.setLength(0);
for (int j = i; j < i + 16; j++) {
  if (Character.isValidCodePoint(j))
    sb.appendCodePoint(j);

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

Random rand = new Random();
char[] chars = new char[16];
for(int i=0;i<chars.length;i++) {
  chars[i] = (char) rand.nextInt(65536);
  if (!Character.isValidCodePoint(chars[i]))
    i--;
}
String s = new String(chars);

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

if (! Character.isValidCodePoint(cp)) {
  throw log.invalidCodePoint(cp);

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

if (!Character.isValidCodePoint(cp)) {
  throw log.invalidCodePoint(cp);

相关文章

微信公众号

最新文章

更多

Character类方法