/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); }
private void processChar(final int ch) { switch (ch) { case '\n': { characterOffset++; lineNumber++; columnNumber = 1; break; } default: { if (! Character.isLowSurrogate((char) ch)) { characterOffset++; columnNumber++; } break; } } }
/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); } }
/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); } }
/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); } }
private static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && isHighSurrogate(string.charAt(index)) && isLowSurrogate(string.charAt(index + 1)); } }
public static boolean isSurrogate(String string, int i) { return Character.isLowSurrogate(string.charAt(i - 1)) && Character.isHighSurrogate(string.charAt(i - 2)); }
int nextCodePoint() { assert pos < end; final char c1 = str.charAt(pos++); if (Character.isHighSurrogate(c1) && pos < end) { final char c2 = str.charAt(pos); if (Character.isLowSurrogate(c2)) { pos++; return Character.toCodePoint(c1, c2); } } return c1; } }
public static boolean isSurrogate(String string, int i) { return Character.isLowSurrogate(string.charAt(i - 1)) && Character.isHighSurrogate(string.charAt(i - 2)); }
public static boolean isSurrogate(String string, int i) { return Character.isLowSurrogate(string.charAt(i - 1)) && Character.isHighSurrogate(string.charAt(i - 2)); }
if (Character.isLowSurrogate(c2)) { return Character.toCodePoint(c1, c2);
if (!Character.isLowSurrogate(c2)) {
if (Character.isHighSurrogate(c1) && pos < len) { final char c2 = input.charAt(pos); if (Character.isLowSurrogate(c2)) { out.write(c2); pos++;
if (!Character.isLowSurrogate(c2)) {
private static int readCP(Reader r) throws IOException { int hi, lo; hi = r.read(); if (hi == -1) { return -1; } if (Character.isHighSurrogate((char) hi)) { lo = r.read(); if (lo == -1) throw log.unexpectedEof(); if (Character.isLowSurrogate((char) lo)) { return Character.toCodePoint((char) hi, (char) lo); } else { throw new CharacterCodingException(); } } else { return hi; } }
private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) { if (!Character.isLowSurrogate(c2)) { buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN); buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2); return writerIndex; } int codePoint = Character.toCodePoint(c, c2); // See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630. buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f))); return writerIndex; }
private static int writeUtf8Surrogate(AbstractByteBuf buffer, int writerIndex, char c, char c2) { if (!Character.isLowSurrogate(c2)) { buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN); buffer._setByte(writerIndex++, Character.isHighSurrogate(c2) ? WRITE_UTF_UNKNOWN : c2); return writerIndex; } int codePoint = Character.toCodePoint(c, c2); // See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G2630. buffer._setByte(writerIndex++, (byte) (0xf0 | (codePoint >> 18))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 12) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | ((codePoint >> 6) & 0x3f))); buffer._setByte(writerIndex++, (byte) (0x80 | (codePoint & 0x3f))); return writerIndex; }
private static String composeString(int len, Random r) { char[] cc = new char[len]; char ch; for (int i = 0; i<len; i++) { do { ch = (char)r.nextInt(); } while (!Character.isDefined(ch) || Character.isHighSurrogate(ch) || Character.isLowSurrogate(ch)); cc[i] = ch; } return new String(cc); }
@FastMethod @Signature(@Arg("char")) public static Memory isLowSurrogate(Environment env, Memory... args) { return Character.isLowSurrogate(chr(args[0])) ? Memory.TRUE : Memory.FALSE; }
@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); }