/** 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))); }
/** 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))); }
/** 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; }
/** 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; }
/** * 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); } }
@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; } }
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); } }
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); } }
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; }
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); } }
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); } }
/** * 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]); }
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)); }
@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))); } }
@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))); } }
/** * 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; }
/** * 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; }
@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(); }
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()); } }
@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"); }