List of usage examples for java.lang Character isValidCodePoint
public static boolean isValidCodePoint(int codePoint)
From source file:Main.java
public static void main(String[] args) { int cp1 = 0x0123, cp2 = 0x123fff; boolean b1 = Character.isValidCodePoint(cp1); boolean b2 = Character.isValidCodePoint(cp2); System.out.println(b1);//from w w w. ja v a2 s.com System.out.println(b2); }
From source file:Strings.java
/** * Returns {@code true} if the specified character sequence is a * valid sequence of UTF-16 {@code char} values. A sequence is * legal if each high surrogate {@code char} value is followed by * a low surrogate value (as defined by {@link * Character#isHighSurrogate(char)} and {@link * Character#isLowSurrogate(char)}).// w w w .j a v a 2 s . c o m * * <p>This method does <b>not</b> check to see if the sequence of * code points defined by the UTF-16 consists only of code points * defined in the latest Unicode standard. The method only tests * the validity of the UTF-16 encoding sequence. * * @param cs Character sequence to test. * @return {@code true} if the sequence of characters is * legal in UTF-16. */ public static boolean isLegalUtf16(CharSequence cs) { for (int i = 0; i < cs.length(); ++i) { char high = cs.charAt(i); if (Character.isLowSurrogate(high)) return false; if (!Character.isHighSurrogate(high)) continue; ++i; if (i >= cs.length()) return false; char low = cs.charAt(i); if (!Character.isLowSurrogate(low)) return false; int codePoint = Character.toCodePoint(high, low); if (!Character.isValidCodePoint(codePoint)) return false; } return true; }
From source file:com.legstar.c2ws.servlet.C2wsProxy.java
/** * Produce a dump-like report of a data buffer content. * @param requestID a correlation id//from w ww .ja v a 2 s . c o m * @param data the raw data to trace * @param log where to log */ public static void traceData(final String requestID, final byte[] data, final Log log) { StringBuilder dumpLine = new StringBuilder(); // 128 String dumpChar; //[5]; StringBuilder dumpString = new StringBuilder(); //[17]; for (int i = 0; i < data.length && i < MAX_TRACES_BYTES; i++) { /* print every 16 byte on a different line */ dumpChar = String.format("%02X ", data[i] & 0xff); dumpLine.append(dumpChar); if (Character.isValidCodePoint(data[i])) { dumpChar = String.format("%c", data[i]); } else { dumpChar = "?"; } if (dumpChar.length() > 0) { dumpString.append(dumpChar); } else { dumpString.append(" "); } if (i % 16 == 15 || i == data.length - 1) { while (i % 16 < 15) { dumpLine.append(" "); i++; } dumpLine.append(" -- "); dumpLine.append(dumpString); log.debug(dumpLine); dumpString = new StringBuilder(); dumpLine = new StringBuilder(); } } if (data.length > MAX_TRACES_BYTES) { dumpLine.append(String.format("...data was truncated at %d bytes", MAX_TRACES_BYTES)); log.debug(dumpLine); } }
From source file:CodePointInputMethod.java
private void finishComposition() { int len = buffer.length(); if (len == 6 && format != SPECIAL_ESCAPE) { char codePoint = (char) getCodePoint(buffer, 2, 5); if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) { buffer.setLength(0);/*from w ww . j a v a 2 s. co m*/ buffer.append(codePoint); sendCommittedText(); return; } } else if (len == 8 && format == SPECIAL_ESCAPE) { int codePoint = getCodePoint(buffer, 2, 7); if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) { buffer.setLength(0); buffer.appendCodePoint(codePoint); sendCommittedText(); return; } } else if (len == 12 && format == SURROGATE_PAIR) { char[] codePoint = { (char) getCodePoint(buffer, 2, 5), (char) getCodePoint(buffer, 8, 11) }; if (Character.isHighSurrogate(codePoint[0]) && Character.isLowSurrogate(codePoint[1])) { buffer.setLength(0); buffer.append(codePoint); sendCommittedText(); return; } } beep(); }
From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java
@Override public String toString() { StringBuffer sb = new StringBuffer("Packet #").append(this.getPacketNumber()); sb.append(" size=").append(this.getDataLength()); sb.append(" pos=").append(this.getPacketPosition()); sb.append(" data="); if (getDataLength() < 1024) { sb.append(Utils.byteArrayToHexString(byteBuffer)); sb.append(" text data="); for (int i = 0; i < this.byteBuffer.length; i++) { if (this.byteBuffer[i] != 0) sb.append((char) this.byteBuffer[i]); else//from www . j av a 2 s. com sb.append(' '); sb.append(" "); } } else { for (int i = 0; i < 1024; i++) { sb.append(Utils.byteToHexString(this.byteBuffer[i])); sb.append(' '); // separate bytes with a space } sb.append(" ... - text data="); for (int i = 0; i < 1024; i++) { if (Character.isValidCodePoint(this.byteBuffer[i])) { sb.append((char) this.byteBuffer[i]); sb.append(' '); } } sb.append("... [data above 1Kb not displayed]"); } return sb.toString(); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.CFLibXmlUtil.java
public static String formatXmlString(String str) { final String S_ProcName = "formatXmlString"; if (str == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(CFLibXmlUtil.class, S_ProcName, 1, "str"); }/*from w w w.j a v a 2 s. co m*/ StringBuffer buff = new StringBuffer(); char ch; int idx; int len = str.length(); for (idx = 0; idx < len; idx++) { ch = str.charAt(idx); if (Character.isWhitespace(ch)) { buff.append(ch); } else { switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '~': case '!': case '#': case '$': case '%': case '^': case '*': case '(': case ')': case '-': case '_': case '+': case '=': case '{': case '}': case '[': case ']': case ':': case ';': case ',': case '.': case '?': case '/': case '\\': case '|': buff.append(ch); break; case '\'': buff.append("'"); break; case '"': buff.append("""); break; case '&': buff.append("&"); break; case '<': buff.append("<"); break; case '>': buff.append(">"); break; default: if (!Character.isValidCodePoint(ch)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(CFLibXmlUtil.class, S_ProcName, "Only valid code points can be formatted, ch is out of range"); } StringBuffer fmtbuff = new StringBuffer(); fmtbuff.append("&#"); Formatter fmt = new Formatter(fmtbuff); fmt.format("%1$d", ch); fmtbuff.append(";"); String tmp = fmtbuff.toString(); buff.append(tmp); fmt.close(); break; } } } String retval = buff.toString(); return (retval); }
From source file:org.archive.io.warc.WARCWriter.java
protected void baseCharacterCheck(final char c, final String parameter) throws IllegalArgumentException { // TODO: Too strict? UNICODE control characters? if (Character.isISOControl(c) || !Character.isValidCodePoint(c)) { throw new IllegalArgumentException( "Contains illegal character 0x" + Integer.toHexString(c) + ": " + parameter); }/*from ww w . j a v a2 s.c om*/ }
From source file:org.codelibs.fess.crawler.util.UnsafeStringBuilder.java
public StrBuilder appendCodePoint(int codePoint) { if (Character.isBmpCodePoint(codePoint)) { append((char) codePoint); } else if (Character.isValidCodePoint(codePoint)) { append(Character.highSurrogate(codePoint)); append(Character.lowSurrogate(codePoint)); } else {/*from ww w . jav a 2s .c om*/ throw new IllegalArgumentException(); } return this; }
From source file:org.eclipse.rdf4j.rio.turtle.TurtleParser.java
/** * Appends the characters from codepoint into the string builder. This is * the same as Character#toChars but prevents the additional char array * garbage for BMP codepoints.//ww w . ja va 2s .c om * * @param dst * the destination in which to append the characters * @param codePoint * the codepoint to be appended */ private static void appendCodepoint(StringBuilder dst, int codePoint) { if (Character.isBmpCodePoint(codePoint)) { dst.append((char) codePoint); } else if (Character.isValidCodePoint(codePoint)) { dst.append(Character.highSurrogate(codePoint)); dst.append(Character.lowSurrogate(codePoint)); } else { throw new IllegalArgumentException("Invalid codepoint " + codePoint); } }
From source file:org.rascalmpl.library.Prelude.java
public IBool isValidCharacter(IInteger i) { return values.bool(Character.isValidCodePoint(i.intValue())); }