private static void checkValidCodePoint(int codePoint) { if (!isValidCodePoint(codePoint)) { throw new IllegalArgumentException("Invalid code point: " + codePoint); } }
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()); }
stopReading = true; else if (Character.isValidCodePoint(codePoint)) { buffer.appendCodePoint(codePoint); } else {
public static void writeCodePointToUtf8(final int c, final OutputStream out) throws IOException { if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {
c = str.codePointAt(i); i += Character.charCount(c); if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {
if (! Character.isValidCodePoint(delim)) { return EMPTY;
c = str.codePointAt(i); i += Character.charCount(c); if (!Character.isValidCodePoint(c) || c >= 0xD800 && c <= 0xDBFF || c >= 0xDC00 && c <= 0xDFFF) {
@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)); } }
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; }
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; }
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(); } }
int i = 0; boolean insertPrefix = (prefix != null); boolean insertDelim = Character.isValidCodePoint(delim); if (hasNext()) { if (insertPrefix) {
int i = 0; boolean insertPrefix = (prefix != null); boolean insertDelim = Character.isValidCodePoint(delim); if (hasNext()) { if (insertPrefix) {
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);
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))); }
@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); }
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);
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);
if (! Character.isValidCodePoint(cp)) { throw log.invalidCodePoint(cp);
if (!Character.isValidCodePoint(cp)) { throw log.invalidCodePoint(cp);