本文整理了Java中java.lang.Character.toChars()
方法的一些代码示例,展示了Character.toChars()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.toChars()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:toChars
[英]Converts the specified Unicode code point into a UTF-16 encoded sequence and returns it as a char array.
[中]将指定的Unicode代码点转换为UTF-16编码序列,并将其作为字符数组返回。
代码示例来源:origin: libgdx/libgdx
/** Queues the glyphs in the specified codepoint range (inclusive) to be loaded. Note that the glyphs are not actually loaded
* until {@link #loadGlyphs()} is called.
*
* Some characters like combining marks and non-spacing marks can only be rendered with the context of other glyphs. In this
* case, use {@link #addGlyphs(String)}. */
public void addGlyphs (int startCodePoint, int endCodePoint) {
for (int codePoint = startCodePoint; codePoint <= endCodePoint; codePoint++)
addGlyphs(new String(Character.toChars(codePoint)));
}
代码示例来源:origin: libgdx/libgdx
/** Queues the glyphs in the specified codepoint range (inclusive) to be loaded. Note that the glyphs are not actually loaded
* until {@link #loadGlyphs()} is called.
*
* Some characters like combining marks and non-spacing marks can only be rendered with the context of other glyphs. In this
* case, use {@link #addGlyphs(String)}. */
public void addGlyphs (int startCodePoint, int endCodePoint) {
for (int codePoint = startCodePoint; codePoint <= endCodePoint; codePoint++)
addGlyphs(new String(Character.toChars(codePoint)));
}
代码示例来源:origin: libgdx/libgdx
/** Appends the encoded Unicode code point. The code point is converted to a {@code char[]} as defined by
* {@link Character#toChars(int)}.
*
* @param codePoint the Unicode code point to encode and append.
* @return this builder.
* @see Character#toChars(int) */
public StringBuilder appendCodePoint (int codePoint) {
append0(Character.toChars(codePoint));
return this;
}
代码示例来源:origin: libgdx/libgdx
/** Appends the encoded Unicode code point. The code point is converted to a {@code char[]} as defined by
* {@link Character#toChars(int)}.
*
* @param codePoint the Unicode code point to encode and append.
* @return this builder.
* @see Character#toChars(int) */
public StringBuilder appendCodePoint (int codePoint) {
append0(Character.toChars(codePoint));
return this;
}
代码示例来源:origin: robolectric/robolectric
/**
* Converts code points in a given string to actual characters. This method doesn't handle code
* points whose char counts are 2. In other words, this method doesn't handle U+10XXXX.
*/
private static char[] extractCodePoint(String codePoint) {
try {
return Character.toChars(Integer.valueOf(codePoint, 16));
} catch (IllegalArgumentException e) {
// This may be caused by NumberFormatException of Integer.valueOf() or
// IllegalArgumentException of Character.toChars().
throw new IllegalArgumentException("Invalid code point: \\u" + codePoint, e);
}
}
代码示例来源:origin: redisson/redisson
@Override
public String toString() {
final String s = new String(Character.toChars(codePoint));
return "unacceptable code point '" + s + "' (0x"
+ Integer.toHexString(codePoint).toUpperCase() + ") " + getMessage()
+ "\nin \"" + name + "\", position " + position;
}
}
代码示例来源:origin: jersey/jersey
private static void appendUTF8EncodedCharacter(final StringBuilder sb, final int codePoint) {
final CharBuffer chars = CharBuffer.wrap(Character.toChars(codePoint));
final ByteBuffer bytes = UTF_8_CHARSET.encode(chars);
while (bytes.hasRemaining()) {
appendPercentEncodedOctet(sb, bytes.get() & 0xFF);
}
}
代码示例来源:origin: jersey/jersey
private static void appendUTF8EncodedCharacter(final StringBuilder sb, final int codePoint) {
final CharBuffer chars = CharBuffer.wrap(Character.toChars(codePoint));
final ByteBuffer bytes = UTF_8_CHARSET.encode(chars);
while (bytes.hasRemaining()) {
appendPercentEncodedOctet(sb, bytes.get() & 0xFF);
}
}
代码示例来源:origin: facebook/litho
private static String getBasePropMatcherName(final MethodParamModel prop, final String suffix) {
final String name = prop.getName();
final int fst = Character.toUpperCase(name.codePointAt(0));
return 'm'
+ String.copyValueOf(Character.toChars(fst))
+ name.substring(name.offsetByCodePoints(0, 1))
+ suffix;
}
代码示例来源:origin: libgdx/libgdx
private int getGlyphCode (Font font, int codePoint) {
char[] chars = Character.toChars(codePoint);
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
return vector.getGlyphCode(0);
}
}
代码示例来源:origin: libgdx/libgdx
private int getGlyphCode (Font font, int codePoint) {
char[] chars = Character.toChars(codePoint);
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
return vector.getGlyphCode(0);
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Converts the given codepoint to a hex string of the form {@code "\\uXXXX\\uXXXX"}
*
* @param codepoint
* a Unicode code point
* @return the hex string for the given codepoint
*/
@Override
protected String toUtf16Escape(final int codepoint) {
final char[] surrogatePair = Character.toChars(codepoint);
return "\\u" + hex(surrogatePair[0]) + "\\u" + hex(surrogatePair[1]);
}
代码示例来源:origin: google/guava
public void testSurrogatePairs() {
UnicodeEscaper e = SIMPLE_ESCAPER;
// Build up a range of surrogate pair characters to test
final int min = Character.MIN_SUPPLEMENTARY_CODE_POINT;
final int max = Character.MAX_CODE_POINT;
final int range = max - min;
final int s1 = min + (1 * range) / 4;
final int s2 = min + (2 * range) / 4;
final int s3 = min + (3 * range) / 4;
final char[] dst = new char[12];
// Put surrogate pairs at odd indices so they can be split easily
dst[0] = 'x';
Character.toChars(min, dst, 1);
Character.toChars(s1, dst, 3);
Character.toChars(s2, dst, 5);
Character.toChars(s3, dst, 7);
Character.toChars(max, dst, 9);
dst[11] = 'x';
String test = new String(dst);
// Get the expected result string
String expected = "x[" + min + "][" + s1 + "][" + s2 + "][" + s3 + "][" + max + "]x";
assertEquals(expected, escapeAsString(e, test));
}
代码示例来源:origin: google/guava
@AndroidIncompatible // slow
@GwtIncompatible // Doubles.tryParse
public void testTryParseAllCodePoints() {
// Exercise non-ASCII digit test cases and the like.
char[] tmp = new char[2];
for (int i = Character.MIN_CODE_POINT; i < Character.MAX_CODE_POINT; i++) {
Character.toChars(i, tmp, 0);
checkTryParse(String.copyValueOf(tmp, 0, Character.charCount(i)));
}
}
代码示例来源:origin: google/guava
@AndroidIncompatible // slow
@GwtIncompatible // Floats.tryParse
public void testTryParseAllCodePoints() {
// Exercise non-ASCII digit test cases and the like.
char[] tmp = new char[2];
for (int i = Character.MIN_CODE_POINT; i < Character.MAX_CODE_POINT; i++) {
Character.toChars(i, tmp, 0);
checkTryParse(String.copyValueOf(tmp, 0, Character.charCount(i)));
}
}
代码示例来源:origin: redisson/redisson
/**
* Scan a %TAG directive's handle. This is YAML's c-tag-handle.
*
* @see <a href="http://www.yaml.org/spec/1.1/#id896876"></a>
* @param startMark
* @return
*/
private String scanTagDirectiveHandle(Mark startMark) {
// See the specification for details.
String value = scanTagHandle("directive", startMark);
int c = reader.peek();
if (c != ' ') {
final String s = String.valueOf(Character.toChars(c));
throw new ScannerException("while scanning a directive", startMark,
"expected ' ', but found " + s + "(" + c + ")", reader.getMark());
}
return value;
}
代码示例来源:origin: redisson/redisson
/**
* Scan a %TAG directive's prefix. This is YAML's ns-tag-prefix.
*
* @see <a href="http://www.yaml.org/spec/1.1/#ns-tag-prefix"></a>
*/
private String scanTagDirectivePrefix(Mark startMark) {
// See the specification for details.
String value = scanTagUri("directive", startMark);
int c = reader.peek();
if (Constant.NULL_BL_LINEBR.hasNo(c)) {
final String s = String.valueOf(Character.toChars(c));
throw new ScannerException("while scanning a directive", startMark,
"expected ' ', but found " + s + "(" + c + ")",
reader.getMark());
}
return value;
}
代码示例来源:origin: prestodb/presto
@Setup
public void setup()
{
int[] codePointSet = ascii ? ASCII_CODE_POINTS : ALL_CODE_POINTS;
ThreadLocalRandom random = ThreadLocalRandom.current();
codePoints = new int[length];
DynamicSliceOutput sliceOutput = new DynamicSliceOutput(length * 4);
for (int i = 0; i < codePoints.length; i++) {
int codePoint = codePointSet[random.nextInt(codePointSet.length)];
codePoints[i] = codePoint;
sliceOutput.appendBytes(new String(Character.toChars(codePoint)).getBytes(StandardCharsets.UTF_8));
}
slice = sliceOutput.slice();
}
代码示例来源:origin: redisson/redisson
private void scanDirectiveIgnoredLine(Mark startMark) {
// See the specification for details.
while (reader.peek() == ' ') {
reader.forward();
}
if (reader.peek() == '#') {
while (Constant.NULL_OR_LINEBR.hasNo(reader.peek())) {
reader.forward();
}
}
int c = reader.peek();
String lineBreak = scanLineBreak();
if (lineBreak.length() == 0 && c != '\0') {
final String s = String.valueOf(Character.toChars(c));
throw new ScannerException("while scanning a directive", startMark,
"expected a comment or a line break, but found " + s + "(" + c + ")",
reader.getMark());
}
}
代码示例来源:origin: prestodb/presto
@Test
public void testChr()
{
assertFunction("CHR(65)", createVarcharType(1), "A");
assertFunction("CHR(9731)", createVarcharType(1), "\u2603");
assertFunction("CHR(131210)", createVarcharType(1), new String(Character.toChars(131210)));
assertFunction("CHR(0)", createVarcharType(1), "\0");
assertInvalidFunction("CHR(-1)", "Not a valid Unicode code point: -1");
assertInvalidFunction("CHR(1234567)", "Not a valid Unicode code point: 1234567");
assertInvalidFunction("CHR(8589934592)", "Not a valid Unicode code point: 8589934592");
}
内容来源于网络,如有侵权,请联系作者删除!