List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:Main.java
/*** This method ensures that the output String has only * * valid XML unicode characters as specified by the * * XML 1.0 standard. For reference, please see * * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the * * standard</a>. This method will return an empty * * String if the input is null or empty. * * @param in The String whose non-valid characters we want to remove. * * @return The in String, stripped of non-valid characters. * *///from www . j a va 2s. co m public static String stripNonValidXMLCharacters(String s) { StringBuilder out = new StringBuilder(); // Used to hold the output. int codePoint; // Used to reference the current character. //String ss = "\ud801\udc00"; // This is actualy one unicode character, represented by two code units!!!. int i = 0; while (i < s.length()) { codePoint = s.codePointAt(i); // This is the unicode code of the character. if ((codePoint == 0x9) || // Consider testing larger ranges first to improve speed. (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { out.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); // Increment with the number of code units(java chars) needed to represent a Unicode char. } return out.toString(); }
From source file:de.vandermeer.asciilist.commons.AlphaLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using ASCII-7 upper case characters. * @param number to convert/*from ww w . jav a2 s.c om*/ * @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 toAscii(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 + 64)); }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Circled Digit/Number characters. * @param number to convert// w w w. j av a 2s . 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 toCircledDigit(int number) { if (number < 1 || number > 20) { throw new NotImplementedException( "Arabic literals - UTF Circled Digit/Number - supported 0<number<21 - number was: " + number); } return new String(Character.toChars(number + 9311)); }
From source file:de.vandermeer.asciilist.commons.AlphaLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using ASCII-7 lower case characters. * @param number to convert//w w w .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 26) */ public final static String toAsciiLC(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 + 96)); }
From source file:Main.java
/** * Converts a single code point into valid XML. Output stream must convert stream * to UTF-8 when saving to disk.// w w w.j av a 2s .c o m */ public static String escapeXMLChars(int cp) { switch (cp) { // case '\'': // return "'"; case '&': return "&"; case '>': return ">"; case '<': return "<"; case '"': return """; default: return String.valueOf(Character.toChars(cp)); } }
From source file:de.uzk.hki.da.passwordEncryptor.passwordEncryptor.java
private static String encryptPasswordForMicroservices(String password) { String result = ""; int cryptTable[] = { 1323, 1213, 4312, 3323, 2034, 3109, 3424, 1214, 1134, 4454, 4599, 3646, 3534, 2523, 2435, 2870, 4345, 3124, 3656, 2777, 3232, 1834, 1235, 1545, 2742, 1099, 3631, 2243, 3173, 2421, 3129, 1037 };//from w w w .j a v a2s . c o m for (int i = 0; i < password.length(); i++) { int c = password.charAt(i); c += cryptTable[i % 32]; String d = new String(Character.toChars(c / 85 + 40)); String e = new String(Character.toChars(c % 85 + 40)); result += e; result += d; } return result; }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Circled Latin Capital (upper case) characters `-?`. * /*www. ja va2s .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 + 9397)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 26; } @Override public String getDescription() { return "numbering scheme using UTF Circled Latin Capital (upper case) characters '-?'"; } }; }
From source file:com.maddyhome.idea.vim.helper.StringHelper.java
@NotNull public static String escape(@NotNull List<KeyStroke> keys) { final StringBuffer res = new StringBuffer(); for (KeyStroke key : keys) { final char c = key.getKeyChar(); final int modifiers = key.getModifiers(); final int code = key.getKeyCode(); if (c < ' ') { res.append('^').append((char) (c + 'A' - 1)); } else if (c == '\n') { res.append("^J"); } else if (c == '\t') { res.append("^I"); } else if (c == '\u0000') { res.append("^@"); } else if ((modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) { final char[] chars = Character.toChars(code); if (chars.length == 1) { res.append("^"); res.append(chars);//from w w w.j a v a 2s .c om } } else { res.append(c); } } return res.toString(); }
From source file:gov.va.vinci.leo.tools.XmiFilterTest.java
@Test public void testXmlStringInput() throws Exception { String text = "this is a test." + String.valueOf(Character.toChars(26)); assertTrue(StringUtils.isNotBlank(text)); XmlFilter xf = new XmlFilter(); String filtered = xf.filter(text); assertTrue("this is a test. ".equals(filtered)); }
From source file:cn.edu.zjnu.acm.judge.config.UnicodeTest.java
@Test public void testUnicode() throws SQLException { int x = 0x1f602; String laughCry = new String(Character.toChars(x)); test0(laughCry);//from ww w.ja v a 2 s . co m for (int i = 2; i < 123; ++i) { test0(Strings.repeat(laughCry, 123)); } }