List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:Main.java
public static void main(String[] args) { int cp = 0x006f; char[] ch = Character.toChars(cp); System.out.print("Char array having cp's UTF-16 representation is "); for (int i = 0; i < ch.length; i++) { System.out.print(ch[i]);//from ww w . j a va 2 s. co m } }
From source file:Main.java
public static void main(String[] args) { int cp = 0x0036; char dst[] = Character.toChars(cp); int res = Character.toChars(cp, dst, 0); if (res == 1) { System.out.println("It is a BMP code point"); } else if (res == 2) { System.out.println("It is a is a supplementary code point"); }/*from ww w . ja v a2 s. c om*/ }
From source file:Main.java
public static void main(final String[] args) throws IOException { File infile = new File("/tmp/utf16.txt"); FileInputStream inputStream = new FileInputStream(infile); Reader in = new InputStreamReader(inputStream, "UTF-16"); int read;//w w w. j ava2 s.com while ((read = in.read()) != -1) { System.out.print(Character.toChars(read)); } in.close(); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(2, 2)); ui.setBorder(new EmptyBorder(4, 4, 4, 4)); JPanel controls = new JPanel(new BorderLayout(2, 2)); ui.add(controls, BorderLayout.PAGE_START); String s = new String(Character.toChars(8594)); String[] items = { "Choice: right " + s + " arrow" }; JComboBox cb = new JComboBox(items); controls.add(cb, BorderLayout.CENTER); controls.add(new JButton("Button"), BorderLayout.LINE_END); JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40)); ui.add(sp, BorderLayout.CENTER); JFrame f = new JFrame("Stretch Combo Layout"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(ui);/* w ww. jav a2 s .co m*/ f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
static String getEmojiByUnicode(int unicode) { return new String(Character.toChars(unicode)); }
From source file:Main.java
public static String getDayFromNumber(int day) { if (day < 0 || day > 30) throw new IllegalArgumentException(); if (day <= 10) return String.valueOf(Character.toChars(1487 + day)); else if ((day >= 11 && day <= 14) || (day >= 16 && day <= 19)) { char yod = Character.toChars(1497)[0]; return String.valueOf(new char[] { yod, Character.toChars(1487 + (day - 10))[0] }); } else if (day == 15 || day == 16) { char tet = Character.toChars(1498)[0]; return String.valueOf(new char[] { tet, Character.toChars(1487 + (day - 9))[0] }); } else if (day == 20) { return String.valueOf(Character.toChars(1499)[0]); } else if (day >= 21 && day <= 29) { char chaf = Character.toChars(1499)[0]; return String.valueOf(chaf + Character.toChars(1487 + (day - 20))[0]); } else {/* ww w .jav a 2 s. co m*/ return String.valueOf(Character.toChars(1500)[0]); } }
From source file:Main.java
public static String getEmojiByUnicode(int unicode) { return new String(Character.toChars(unicode)); }
From source file:Main.java
public static String removeUnprintableCharacters(String str) { int len = str.length(); StringBuffer buf = new StringBuffer(); try {//from w ww .j a v a 2 s .c o m for (int i = 0; i < len; i++) { String rep = ""; char cp = str.charAt(i);// the code point // Replace invisible control characters and unused code points switch (Character.getType(cp)) { case Character.CONTROL: // \p{Cc} case Character.FORMAT: // \p{Cf} case Character.PRIVATE_USE: // \p{Co} case Character.SURROGATE: // \p{Cs} case Character.UNASSIGNED: // \p{Cn} buf = buf.append(rep); break; default: char[] chars = Character.toChars(cp); buf = buf.append(chars); break; } } } catch (NullPointerException e) { e.printStackTrace(); System.err.println("Confused: " + e); } catch (IllegalArgumentException e) { e.printStackTrace(); System.err.println("Confused: " + e); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); System.err.println("Confused: " + e); } catch (Exception e) { e.printStackTrace(); System.err.println("Confused: " + e); } return buf.toString(); }
From source file:Main.java
/** * Escapes the given text such that it can be safely embedded in a string literal * in Java source code.// w w w. j a v a 2s. co m * * @param text the text to escape * * @return the escaped text */ public static String escapeToJavaString(String text) { if (text == null) { return null; } String result = text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"").replace("\b", "\\b") .replace("\f", "\\f").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t"); StringBuilder complete = new StringBuilder(); for (int i = 0; i < result.length(); i++) { int codePointI = result.codePointAt(i); if (codePointI >= 32 && codePointI <= 127) { complete.append(Character.toChars(codePointI)); } else { // use Unicode representation complete.append("\\u"); String hex = Integer.toHexString(codePointI); complete.append(getRepeatingString(4 - hex.length(), '0')); complete.append(hex); } } return complete.toString(); }
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 the * standard. This method will return an empty String if the input is null or empty. * * @param s - The String whose non-valid characters we want to replace. * @return The in String, where non-valid characters are replace by spaces. * @author Nuno Freire/*from w w w . j av a 2 s . com*/ */ public static String removeInvalidXMLCharacters(String s) { StringBuilder out = new StringBuilder(); // Used to hold the output. int codePoint; // Used to reference the current character. 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)); } else { out.append(' '); } i += Character.charCount(codePoint); // Increment with the number of code units(java chars) needed to represent a Unicode char. } return out.toString(); }