/** * Asserts that a Unicode escaper escapes the given hi/lo surrogate pair into the expected string. * * @param escaper the non-null escaper to test * @param expected the expected output string * @param hi the high surrogate pair character * @param lo the low surrogate pair character */ public static void assertUnicodeEscaping( UnicodeEscaper escaper, String expected, char hi, char lo) { int cp = Character.toCodePoint(hi, lo); String escaped = computeReplacement(escaper, cp); Assert.assertNotNull(escaped); Assert.assertEquals(expected, escaped); } }
@Override public int accepts(int strIndex, CharSequence testString) { char high = testString.charAt(strIndex++); char low = testString.charAt(strIndex); return (this.ch == Character.toLowerCase(Character.toUpperCase(Character.toCodePoint(high, low)))) ? 2 : -1; }
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; } }
return Character.toCodePoint(c1, c2);
private boolean wideDisplayCharacterStartingAt(int column) { for (int currentCharIndex = 0, currentColumn = 0; currentCharIndex < mSpaceUsed; ) { char c = mText[currentCharIndex++]; int codePoint = Character.isHighSurrogate(c) ? Character.toCodePoint(c, mText[currentCharIndex++]) : c; int wcwidth = WcWidth.width(codePoint); if (wcwidth > 0) { if (currentColumn == column && wcwidth == 2) return true; currentColumn += wcwidth; if (currentColumn > column) return false; } } return false; }
@Override public int nextInt() { final int length = ensureLength(); if (current >= length) { throw new NoSuchElementException(); } final char nextChar = charSequence.charAt(current++); if (Character.isHighSurrogate(nextChar) && current < length) { final char currentChar = charSequence.charAt(current); if (Character.isLowSurrogate(currentChar)) { current++; return Character.toCodePoint(nextChar, currentChar); } } return nextChar; }
public ByteStringBuilder append(String s, int offs, int len) { int c; int i = 0; while (i < len) { c = s.charAt(offs + i++); if (Character.isHighSurrogate((char) c)) { if (i < len) { char t = s.charAt(offs + i ++); if (! Character.isLowSurrogate(t)) { throw new IllegalArgumentException(); } c = Character.toCodePoint((char) c, t); } else { throw new IllegalArgumentException(); } } appendUtf8Raw(c); } return this; }
public ByteStringBuilder append(CharSequence s, int offs, int len) { int c; int i = 0; while (i < len) { c = s.charAt(offs + i++); if (Character.isHighSurrogate((char) c)) { if (i < len) { char t = s.charAt(offs + i ++); if (! Character.isLowSurrogate(t)) { throw new IllegalArgumentException(); } c = Character.toCodePoint((char) c, t); } else { throw new IllegalArgumentException(); } } appendUtf8Raw(c); } return this; }
public static int getRandomSupplementaryChar() { int lowSurrogate = 0xDC00 + rnd.nextInt(1024); //return 0xD8000000 + lowSurrogate; int highSurrogate = 0xD800; return Character.toCodePoint((char)highSurrogate, (char)lowSurrogate); }
public static int getRandomSupplementaryChar() { int lowSurrogate = 0xDC00 + rnd.nextInt(1024); //return 0xD8000000 + lowSurrogate; int highSurrogate = 0xD800; return Character.toCodePoint((char)highSurrogate, (char)lowSurrogate); }
/** The width at an index position in a java char array. */ public static int width(char[] chars, int index) { char c = chars[index]; return Character.isHighSurrogate(c) ? width(Character.toCodePoint(c, chars[index + 1])) : width(c); }
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 boolean JavaLetter_sempred(RuleContext _localctx, int predIndex) { switch (predIndex) { case 0: return Character.isJavaIdentifierStart(_input.LA(-1)); case 1: return Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1))); } return true; } private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) {
private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) { switch (predIndex) { case 2: return Character.isJavaIdentifierPart(_input.LA(-1)); case 3: return Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1))); } return true; }
private int nextCodePoint() { char high = pattern[nextIndex()]; if (Character.isHighSurrogate(high)) { // low and high char may be delimited by spaces int lowExpectedIndex = prevNW + 1; if (lowExpectedIndex < pattern.length) { char low = pattern[lowExpectedIndex]; if (Character.isLowSurrogate(low)) { nextIndex(); return Character.toCodePoint(high, low); } } } return high; }
+ (int) c); char[] escaped = escape(Character.toCodePoint((char) pendingHighSurrogate, c)); if (escaped != null) { outputChars(escaped, escaped.length);
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 void assertLineStartsWith(int... codePoints) { char[] chars = row.mText; int charIndex = 0; for (int i = 0; i < codePoints.length; i++) { int lineCodePoint = chars[charIndex++]; if (Character.isHighSurrogate((char) lineCodePoint)) { lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]); } assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint); } }
protected TerminalTestCase assertLineStartsWith(int line, int... codePoints) { char[] chars = mTerminal.getScreen().mLines[mTerminal.getScreen().externalToInternalRow(line)].mText; int charIndex = 0; for (int i = 0; i < codePoints.length; i++) { int lineCodePoint = chars[charIndex++]; if (Character.isHighSurrogate((char) lineCodePoint)) { lineCodePoint = Character.toCodePoint((char) lineCodePoint, chars[charIndex++]); } assertEquals("Differing a code point index=" + i, codePoints[i], lineCodePoint); } return this; }