List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:org.apache.bval.jsr.util.PathNavigation.java
private static String parseQuotedString(CharSequence path, PathPosition pos) throws Exception { int len = path.length(); int start = pos.getIndex(); if (start < len) { char quote = path.charAt(start); pos.next();// w w w .j av a 2 s .c o m StringWriter w = new StringWriter(); while (pos.getIndex() < len) { int here = pos.getIndex(); // look for matching quote if (path.charAt(here) == quote) { pos.next(); return w.toString(); } int codePoints = StringEscapeUtils.UNESCAPE_JAVA.translate(path, here, w); if (codePoints == 0) { w.write(Character.toChars(Character.codePointAt(path, here))); pos.next(); } else { for (int i = 0; i < codePoints; i++) { pos.plus(Character.charCount(Character.codePointAt(path, pos.getIndex()))); } } } // if reached, reset due to no ending quote found pos.setIndex(start); } return null; }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Circled Digit/Number characters `-`. * /* w ww . j a v a 2s . com*/ * ---- * item 1 * item 2 * item 3 * ... * item 20 * ---- * * @return the line */ public static TA_Numbering numberCircledDigit() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 21, "numbering supported 0<number<21 - number was: " + number); return new String(Character.toChars(number + 9311)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 20; } @Override public String getDescription() { return "numbering scheme using UTF Circled Digit/Number characters '-'"; } }; }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Parenthesized Digit/Number characters. * @param number to convert/*from w w w. jav a2s . c o m*/ * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 20) */ public final static String toParenthesized(int number) { if (number < 1 || number > 20) { throw new NotImplementedException( "Arabic literals - UTF Parenthesized Digit/Number - supported 0<number<21 - number was: " + number); } return new String(Character.toChars(number + 9331)); }
From source file:org.languagetool.dev.wikipedia.TextConverter.java
public void visit(XmlCharRef cr) { addMapping(cr); write(Character.toChars(cr.getCodePoint())); }
From source file:net.metanotion.json.StreamingParser.java
private String lexInt(final Reader in, final int firstChar) throws IOException { final StringBuilder sb = new StringBuilder(); int digits = 0; if (firstChar == '-') { sb.append("-"); } else if (Character.isDigit(firstChar)) { sb.append(Character.toChars(firstChar)); digits++;/*from w ww.j a v a 2s . com*/ } else { final String found = new String(Character.toChars(firstChar)); throw new ParserException("Expecting a number, instead found: '" + found + QUOTE); } while (true) { in.mark(MAX_BUFFER); final int c = in.read(); if (Character.isDigit(c)) { digits++; sb.append(Character.toChars(c)); } else { in.reset(); if (digits == 0) { throw new ParserException(EXPECTED_DIGIT); } return sb.toString(); } } }
From source file:org.omegat.tokenizer.BaseTokenizer.java
protected Token[] tokenizeByCodePoint(String strOrig) { // See http://www.ibm.com/developerworks/library/j-unicode/#1-5 // Example 1-5 appears to be faster than 1-6 for us (because our strings are short?) Token[] tokens = new Token[strOrig.codePointCount(0, strOrig.length())]; for (int cp, i = 0, j = 0; i < strOrig.length(); i += Character.charCount(cp)) { cp = strOrig.codePointAt(i);/*from w w w . j a va 2s .c om*/ tokens[j++] = new Token(String.valueOf(Character.toChars(cp)), i); } return tokens; }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Fullwidth characters. * @param number to convert//from w w w . j av a 2 s. co m * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 9) */ public final static String toFullwidth(int number) { if (number < 1 || number > 9) { throw new NotImplementedException( "Arabic literals - UTF Fullwidth - supported 0<number<10 - number was: " + number); } return new String(Character.toChars(number + 65296)); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.pdf.Pdf2CasConverter.java
private StringBuilder sanitize(final StringBuilder aContent) { int i = 0;/*w w w .j a v a2 s .c o m*/ int lastBreak = 0; while (i < aContent.length()) { // Check valid unicode char if (!isValidXMLChar(aContent.codePointAt(i))) { aContent.setCharAt(i, ' '); i++; continue; } // Set up how many characters we want to skip int seek = i + 1; // Do we maybe have an entity? if (aContent.charAt(i) == '&') { // REC 2006-10-21 Some PDFs seem to have entities and others // don't // so we may encounter &'s that do not introduce an entity and // just ignore them. final int end = aContent.indexOf(";", i); if (end != -1) { final String cand = aContent.substring(i, end + 1); String r = null; try { if (cand.startsWith("&#x")) { final int cp = Integer.parseInt(cand.substring(2, cand.length() - 1), 16); r = isValidXMLChar(cp) ? String.valueOf(Character.toChars(cp)) : " "; } else if (cand.startsWith("&#")) { final int cp = Integer.parseInt(cand.substring(2, cand.length() - 1)); r = isValidXMLChar(cp) ? String.valueOf(Character.toChars(cp)) : " "; } else { // RE 2006-10-22 The chance that there is a & and a // ; // together in a string is quite big. Let's be // tolerant. } } catch (final NumberFormatException e) { log.warn("Invalid numeric entity in fragment [" + cand + "] - Dropping it."); } // Expand the entity and set proper skip (if found) if (r != null) { aContent.replace(i, i + cand.length(), r); seek = i + r.length(); } } } // Match against the Trie after numeric entity expansion is over if (substitutionTable != null) { final Trie<String>.Node match = substitutionTable.getNode(aContent, i); if (match != null) { aContent.replace(i, i + match.level, match.value); seek = i + match.value.length(); } } // Check line breaks while (i < seek) { if (aContent.charAt(i) == '\n') { lastBreak = i; } else if (Character.isWhitespace(aContent.codePointAt(i)) && (i > (lastBreak + 79))) { lastBreak = i; aContent.replace(i, i + 1, "\n"); } i++; } } return aContent; }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Double Circled Digit/Number characters `-`. * //www. j a v a 2 s . co m * ---- * item 1 * item 2 * item 3 * ... * item 10 * ---- * * @return the line */ public static TA_Numbering numberDoubleCircledDigit() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 11, "numbering supported 0<number<11 - number was: " + number); return new String(Character.toChars(number + 9460)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 10; } @Override public String getDescription() { return "numbering scheme using UTF Double Circled Digit/Number characters '-'"; } }; }
From source file:org.omegat.tokenizer.BaseTokenizer.java
protected String[] tokenizeByCodePointToStrings(String strOrig) { // See http://www.ibm.com/developerworks/library/j-unicode/#1-5 // Example 1-5 appears to be faster than 1-6 for us (because our strings are short?) String[] tokens = new String[strOrig.codePointCount(0, strOrig.length())]; for (int cp, i = 0, j = 0; i < strOrig.length(); i += Character.charCount(cp)) { cp = strOrig.codePointAt(i);/*ww w . j a v a 2 s .co m*/ tokens[j++] = String.valueOf(Character.toChars(cp)); } return tokens; }