public static int estimatedBinaryLengthAsUTF8(String value) { int length = 0; for (int i = 0; i < value.length(); i++) { char var10 = value.charAt(i); if (var10 < 0x80) { length += 1; } else if (var10 < 0x800) { length += 2; } else if (Character.isSurrogate(var10)) { length += 4; i++; } else { length += 3; } } return length; }
private boolean hasBadCharacters(String string) { for (int i = 0; i < string.length(); ++i) { char c = string.charAt(i); if (c == 0 || Character.isSurrogate(c)) { return true; } } return false; }
public static String getRandUnicodeString(Random r, int length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { char ch; while (true) { int codePoint = MIN_RANDOM_CODEPOINT + r.nextInt(RANGE_RANDOM_CODEPOINT); if (!Character.isDefined(codePoint) || Character.getType(codePoint) == Character.PRIVATE_USE) { continue; } ch = (char) codePoint; if (Character.isSurrogate(ch)) { continue; } break; } sb.append(ch); } return sb.toString(); }
check(!Character.isSurrogate(currentCodePoint), format("Invalid escaped character: %s. Escaped character is a surrogate. Use '\\+123456' instead.", currentEscapedCode), context); unicodeStringBuilder.append(currentCodePoint);
out.writeByte((byte) (UTF8_CONTINUATION | c & LAST_6)); // lowest 6 bits } else if (Character.isSurrogate(c)) {
} else if (!Character.isSurrogate(ch)) { if (outPos + 3 > outSize) { --inPos;
public static boolean isEntirelyInBasicMultilingualPlane(String text) { for (int i = 0; i < text.length(); i++) { if (Character.isSurrogate(text.charAt(i))) { return false; } } return true; }
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("1.txt"), "UTF-8")); for (int c; (c = br.read()) != -1;) { if (Character.isSurrogate((char)c)) { // skip the second surrogate char br.read(); } else { // process char c } }
out.writeByte((byte) (UTF8_CONTINUATION | c & LAST_6)); // lowest 6 bits } else if (Character.isSurrogate(c)) {
if (Character.isSurrogate(c)) { inPos -= 3; result = TCoderResult.malformedForLength(3);
/** * Shorthand for doing boolean isSurrogate as an int. * * @param ch the char to check * @return 1 if it's a surrogate. 0 if not. */ private static int isSurrogate( char ch ) { return Character.isSurrogate(ch) ? 1 : 0; }
/** * Determines if the specified code point is a supplementary * character or unpaired surrogate. */ private static boolean isSupplementary(int ch) { return ch >= Character.MIN_SUPPLEMENTARY_CODE_POINT || Character.isSurrogate((char) ch); }
/** * Determines if the specified code point is a supplementary * character or unpaired surrogate. */ private static final boolean isSupplementary(int ch) { return ch >= Character.MIN_SUPPLEMENTARY_CODE_POINT || Character.isSurrogate((char)ch); }
/** * Determines if the specified code point is a supplementary * character or unpaired surrogate. */ private static final boolean isSupplementary(int ch) { return ch >= Character.MIN_SUPPLEMENTARY_CODE_POINT || Character.isSurrogate((char)ch); }
public boolean needEscapeImpl( char ch ) { return isControl(ch) || isEsc(ch) || Character.isSurrogate(ch); }
public boolean needEscapeImpl( char ch ) { return isControl(ch) || isEvalEsc(ch) || Character.isSurrogate(ch); }
private static int getConsecutiveCodepoints(int codePoint, String pattern, int currentPos) { int lastPos = currentPos; while (lastPos < pattern.length() && pattern.codePointAt(lastPos) == codePoint) { if (Character.isSurrogate(pattern.charAt(lastPos))) lastPos += 2; else lastPos++; } return (lastPos - currentPos + 1); }
Character.isHighSurrogate(myChar); // returns true if myChar is a high surrogate Character.isLowSurrogate(myChar); // same for low surrogate Character.isSurrogate(myChar); // just to know if myChar is a surrogate
public String removeSurrogates(String str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (!Character.isSurrogate(c)) { sb.append(c); } else if (restrictReplacement != null) { sb.append(restrictReplacement); } } return sb.toString(); }
private int putUtf8Internal(CharSequence cs, int hi, int i, char c) { if (c < 2048) { put((char) (192 | c >> 6)).put((char) (128 | c & 63)); } else if (Character.isSurrogate(c)) { i = encodeSurrogate(c, cs, i, hi); } else { put((char) (224 | c >> 12)).put((char) (128 | c >> 6 & 63)).put((char) (128 | c & 63)); } return i; }