fork(2) download
  1. import java.io.InputStreamReader;
  2. import java.io.LineNumberReader;
  3. import java.net.URL;
  4. import java.text.Normalizer;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9.  
  10. public class Main {
  11. private static final String ZEROES = "000";
  12. public static String codePointToHexString(int codePoint) {
  13. assert codePoint >= 0;
  14. String str = Integer.toString(codePoint, 16).toUpperCase();
  15. if (str.length() < 4) str = ZEROES.substring(3 - 4 + str.length()) + str;
  16. return str;
  17. }
  18.  
  19. private static class Block {
  20. public final int startCodePoint;
  21. public final int endCodePoint;
  22. public final String description;
  23.  
  24. public Block(int startCodePoint, int endCodePoint, String description) {
  25. this.startCodePoint = startCodePoint;
  26. this.endCodePoint = endCodePoint;
  27. this.description = description;
  28. }
  29.  
  30. @Override
  31. public String toString() {
  32. return codePointToHexString(startCodePoint) + ".." + codePointToHexString(endCodePoint) + "; " + description;
  33. }
  34. }
  35.  
  36. public static void main(String[] args) throws Throwable {
  37. final URL blocksTxtURL = new URL("http://w...content-available-to-author-only...e.org/Public/UCD/latest/ucd/Blocks.txt");
  38. final LineNumberReader lnr = new LineNumberReader(new InputStreamReader(blocksTxtURL.openStream()));
  39.  
  40. final List<Block> blocks = new ArrayList<Block>();
  41.  
  42. String line;
  43. while ((line = lnr.readLine()) != null) {
  44. if (line.isEmpty() || line.charAt(0) == '#') continue;
  45. final int semicolonPos = line.indexOf(';');
  46. if (semicolonPos < 0) continue;
  47.  
  48. final int dotdotPos = line.lastIndexOf("..", semicolonPos);
  49. if (dotdotPos < 0) continue;
  50.  
  51. final int startCodePoint = Integer.parseInt(line.substring(0, dotdotPos), 16);
  52. final int endCodePoint = Integer.parseInt(line.substring(dotdotPos + 2, semicolonPos), 16);
  53. final String description = line.substring(semicolonPos + 1).trim();
  54. blocks.add(new Block(startCodePoint, endCodePoint, description));
  55. }
  56.  
  57. blocks.add(new Block(0, 0xFFFF, "(BMP)"));
  58.  
  59. for (final Block b : blocks) {
  60. System.out.println(b);
  61.  
  62. final Map<Integer, List<String>> m = new HashMap<Integer, List<String>>();
  63. for (int i = b.startCodePoint; i < b.endCodePoint; ++i) {
  64. final String str = new String(new int[] { i }, 0, 1);
  65. final String normStr = Normalizer.normalize(str, Normalizer.Form.NFC);
  66. final int codePointCount = normStr.codePointCount(0, normStr.length());
  67. if (!m.containsKey(codePointCount)) m.put(codePointCount, new ArrayList<String>());
  68. m.get(codePointCount).add(str);
  69. }
  70.  
  71. for (final Map.Entry<Integer, List<String>> e : m.entrySet()) {
  72. System.out.println(e.getKey() + ": " + e.getValue().size());
  73. if (e.getKey() > 1) {
  74. for (final String str : e.getValue()) {
  75. System.out.print(" " + codePointToHexString(str.codePointAt(0)));
  76. }
  77. System.out.println();
  78. }
  79. }
  80.  
  81. System.out.println();
  82. }
  83. }
  84. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty