package jetbrains.buildServer.serverSide; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; import org.apache.commons.codec.binary.Hex; /** * @author Pavel.Sher * Date: 31.03.2008 */ public class Converter { public static void main(String[] args) throws UnsupportedEncodingException { Map single = new HashMap(); Map h = new HashMap(); single.put("a", "à"); single.put("b", "á"); single.put("v", "â"); single.put("g", "ã"); single.put("d", "ä"); single.put("e", "å"); single.put("z", "ç"); single.put("i", "è"); single.put("k", "ê"); single.put("l", "ë"); single.put("m", "ì"); single.put("n", "í"); single.put("o", "î"); single.put("p", "ï"); single.put("r", "ð"); single.put("s", "ñ"); single.put("t", "ò"); single.put("u", "ó"); single.put("f", "ô"); single.put("c", "ê"); single.put("y", "û"); single.put("", "ú"); single.put("", "ü"); single.put("j", "äæ"); single.put("w", "â"); single.put("q", "êé"); single.put("x", "êc"); single.put("A", "À"); single.put("B", "Á"); single.put("V", "Â"); single.put("G", "Ã"); single.put("D", "Ä"); single.put("E", "Å"); single.put("Z", "Ç"); single.put("I", "È"); single.put("K", "Ê"); single.put("L", "Ë"); single.put("M", "Ì"); single.put("N", "Í"); single.put("O", "Î"); single.put("P", "Ï"); single.put("R", "Ð"); single.put("S", "Ñ"); single.put("T", "Ò"); single.put("U", "Ó"); single.put("F", "Ô"); single.put("C", "Ê"); single.put("Y", "Û"); single.put("J", "Äæ"); single.put("W", "Â"); single.put("Q", "Êé"); single.put("X", "Êc"); h.put("z", "æ"); h.put("k", "õ"); h.put("c", "÷"); h.put("s", "ø"); h.put("sh", "ù"); h.put("e", "ý"); h.put("t", "ç"); h.put("w", "â"); h.put("Z", "Æ"); h.put("K", "Õ"); h.put("C", "×"); h.put("S", "Ø"); h.put("SH", "Ù"); h.put("E", "Ý"); h.put("T", "Ç"); h.put("W", "Â"); recodeMap("single", single); recodeMap("h", h); //System.out.println(Hex.encodeHex(toByteArray(0xef8090fe))); System.out.println(Charset.availableCharsets().keySet()); } private static void recodeMap(String prefix, final Map single) throws UnsupportedEncodingException { for (Map.Entry entry: single.entrySet()) { StringBuilder b = new StringBuilder(); String str = new String(entry.getValue().getBytes()); b.append(prefix).append("['").append(entry.getKey()).append("']='"); for (int i=0; i< str.length(); i++) { CharSequence seq = str.subSequence(i, i+1); int cp = Character.codePointAt(seq, 0); b.append("\\u").append(Hex.encodeHex(toByteArray(cp))); } b.append("';\n"); System.out.print(b); } } private static byte[] toByteArray(int i) { byte[] bytes = new byte[4]; bytes[0] = (byte)((i >> 24) & 0xFF); bytes[1] = (byte)((i >> 16) & 0xFF); bytes[2] = (byte)((i >> 8) & 0xFF); bytes[3] = (byte)(i & 0xFF); int idx = 0; while (idx < bytes.length && bytes[idx] == 0 && idx<2) idx++; byte[] res = new byte[4-idx]; System.arraycopy(bytes, idx, res, 0, res.length); return res; } }