List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:de.vandermeer.asciithemes.a7.A7_NumberingSchemes.java
/** * Numbering scheme using upper case alphanumeric ASCII characters `A-Z`. * //from ww w .jav a2s .c om * ---- * A item 1 * B item 2 * C item 3 * ... * Z item 26 * ---- * * @return the line */ public static TA_Numbering Alpha() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 27, "numbering supported 0<number<27 - number was: " + number); return new String(Character.toChars(number + 64)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 26; } @Override public String getDescription() { return "numbering scheme upper case alphanumeric ASCII characters 'A-Z'"; } }; }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Double Circled Digit/Number characters. * @param number to convert//from www . j a v a 2s.c om * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 10) */ public final static String toDoubleCircledDigit(int number) { if (number < 1 || number > 20) { throw new NotImplementedException( "Arabic literals - UTF Double Circled Digit/Number - supported 0<number<10 - number was: " + number); } return new String(Character.toChars(number + 9460)); }
From source file:com.evolveum.midpoint.common.Utils.java
/** * Removing non-printable UTF characters from the string. * /*from w w w . j av a 2 s .com*/ * This is not really used now. It was done as a kind of prototype for * filters. But may come handy and it in fact tests that the pattern is * doing what expected, so it may be useful. * * @param bad * string with bad chars * @return string without bad chars */ public static String cleanupUtf(String bad) { StringBuilder sb = new StringBuilder(bad.length()); for (int cp, i = 0; i < bad.length(); i += Character.charCount(cp)) { cp = bad.codePointAt(i); if (isValidXmlCodepoint(cp)) { sb.append(Character.toChars(cp)); } } return sb.toString(); }
From source file:com.seajas.search.utilities.web.WebResourceLocators.java
/** * Gets a resource locator./*from w w w .ja va 2s. co m*/ * * @param uri * @throws URISyntaxException */ public static URI parseURI(String uri) throws URISyntaxException { if (!StringUtils.hasText(uri)) throw new URISyntaxException("", "No content"); uri = uri.trim(); // Escape illegal characters for (int i = 0; i < uri.length(); ++i) { char c = uri.charAt(i); if (ASCII_ESCAPE_SET.indexOf(c) >= 0) uri = String.format("%s%%%02X%s", uri.substring(0, i), c & 0xFF, uri.substring(i + 1)); } // Parse XML entities for (int start = uri.indexOf('&'); start >= 0; start = uri.indexOf('&', start + 1)) { int end = uri.indexOf(';', start); if (end < 0) break; String entity = uri.substring(start + 1, end); String replacement = null; if (entity.startsWith("#")) { try { int codepoint = entity.startsWith("#x") ? Integer.parseInt(entity.substring(2), 16) : Integer.parseInt(entity.substring(1)); if (codepoint <= 0xFF) replacement = String.format("%%%02X", codepoint); else replacement = new String(Character.toChars(codepoint)); } catch (Exception e) { logger.trace("Unparseable numeric entity.", e); } } else { replacement = xmlEntityPercentEscapes.get(entity); } if (replacement != null) { if (logger.isDebugEnabled()) logger.debug(String.format("Replaced entity %s with %s for %s", entity, replacement, uri)); uri = uri.substring(0, start) + replacement + uri.substring(end + 1); } else if (logger.isDebugEnabled()) { logger.debug(String.format("Skiped entity %s for %s", entity, uri)); } } // Multiple fragments while (uri.indexOf('#') != uri.lastIndexOf('#')) { int i = uri.lastIndexOf('#'); // Escape last hash mark uri = uri.substring(0, i) + "%23" + uri.substring(i + 1); } return new URI(uri).normalize(); }
From source file:de.vandermeer.asciilist.commons.AlphaLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Circled Latin Capital (upper case) characters. * @param number to convert//from w ww. ja v a 2s . com * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 26) */ public final static String toCircledLatinCapital(int number) { if (number < 1 || number > 26) { throw new NotImplementedException( "Alphanumeric literals supported 0<number<27 - number was: " + number); } return new String(Character.toChars(number + 9397)); }
From source file:dk.dr.radio.data.EoDiverse.java
/** * Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports only HTML 3.0 entities. * Kilde: http://stackoverflow.com/questions/994331/java-how-to-decode-html-character-entities-in-java-like-httputility-htmldecode *//*from w ww .j a va 2 s. c o m*/ public static final String unescapeHtml3(final String input) { StringWriter writer = null; int len = input.length(); int i = 1; int st = 0; while (true) { // look for '&' while (i < len && input.charAt(i - 1) != '&') i++; if (i >= len) break; // found '&', look for ';' int j = i; while (j < len && j < i + MAX_ESCAPE + 1 && input.charAt(j) != ';') j++; if (j == len || j < i + MIN_ESCAPE || j == i + MAX_ESCAPE + 1) { i++; continue; } // found escape if (input.charAt(i) == '#') { // numeric escape int k = i + 1; int radix = 10; final char firstChar = input.charAt(k); if (firstChar == 'x' || firstChar == 'X') { k++; radix = 16; } try { int entityValue = Integer.parseInt(input.substring(k, j), radix); if (writer == null) writer = new StringWriter(input.length()); writer.append(input.substring(st, i - 1)); if (entityValue > 0xFFFF) { final char[] chrs = Character.toChars(entityValue); writer.write(chrs[0]); writer.write(chrs[1]); } else { writer.write(entityValue); } } catch (NumberFormatException ex) { i++; continue; } } else { // named escape CharSequence value = lookupMap.get(input.substring(i, j)); if (value == null) { i++; continue; } if (writer == null) writer = new StringWriter(input.length()); writer.append(input.substring(st, i - 1)); writer.append(value); } // skip escape st = j + 1; i = st; } if (writer != null) { writer.append(input.substring(st, len)); return writer.toString(); } return input; }
From source file:gov.va.vinci.leo.tools.XmiFilterTest.java
@Test public void testToXml10() throws Exception { String text = "this is a test." + String.valueOf(Character.toChars(26)); assertTrue(StringUtils.isNotBlank(text)); String filtered = XmlFilter.toXml10(text); assertTrue("this is a test. ".equals(filtered)); }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Circled Latin Capital (lower case) characters `?-`. * //from w w w. j a v a 2 s. c o m * ---- * ? item 1 * item 2 * item 3 * ... * item 26 * ---- * * @return the line */ public static TA_Numbering alphaCircledLatin() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 27, "numbering supported 0<number<27 - number was: " + number); return new String(Character.toChars(number + 9423)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 26; } @Override public String getDescription() { return "numbering scheme using UTF Circled Latin Capital (lower case) characters '?-'"; } }; }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Dingbat Negative Circled Digit characters. * @param number to convert//from ww w.ja v a 2 s . com * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 10) */ public final static String toDingbatNegativeCircledDigit(int number) { if (number < 1 || number > 10) { throw new NotImplementedException( "Arabic literals - UTF Dingbat Negative Circled - supported 0<number<11 - number was: " + number); } return new String(Character.toChars(number + 10101)); }
From source file:de.vandermeer.asciilist.commons.AlphaLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Circled Latin Small (lower case) characters. * @param number to convert// w w w . j a va2s . co m * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 26) */ public final static String toCircledLatinSmall(int number) { if (number < 1 || number > 26) { throw new NotImplementedException( "Alphanumeric literals supported 0<number<27 - number was: " + number); } return new String(Character.toChars(number + 9423)); }