| 63 | } |
| 64 | |
| 65 | private abstract static class Parser { |
| 66 | private StringBuilder key = null; |
| 67 | private StringBuilder value = null; |
| 68 | private StringBuilder current = null; |
| 69 | |
| 70 | private void append(int c) { |
| 71 | if (current == null) { |
| 72 | if (key == null) { |
| 73 | current = key = new StringBuilder(); |
| 74 | } else { |
| 75 | current = value = new StringBuilder(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | current.append((char) c); |
| 80 | } |
| 81 | |
| 82 | private void finishLine(Map<String, Object> map) { |
| 83 | if (key != null) { |
| 84 | map.put(key.toString(), |
| 85 | (value == null ? "" : value.toString().trim())); |
| 86 | } |
| 87 | |
| 88 | key = value = current = null; |
| 89 | } |
| 90 | |
| 91 | abstract int readCharacter() throws IOException; |
| 92 | |
| 93 | char readUtf16() throws IOException { |
| 94 | char c = 0; |
| 95 | for (int i = 0; i < 4; ++i) { |
| 96 | int digit = Character.digit((char)readCharacter(), 16); |
| 97 | if (digit == -1) throw new IOException("Invalid Unicode escape encountered."); |
| 98 | c <<= 4; |
| 99 | c |= digit; |
| 100 | } |
| 101 | return c; |
| 102 | } |
| 103 | |
| 104 | void parse(Map map) |
| 105 | throws IOException |
| 106 | { |
| 107 | boolean escaped = false; |
| 108 | |
| 109 | int c; |
| 110 | while ((c = readCharacter()) != -1) { |
| 111 | if (c == '\\') { |
| 112 | if (escaped) { |
| 113 | escaped = false; |
| 114 | append(c); |
| 115 | } else { |
| 116 | escaped = true; |
| 117 | } |
| 118 | } else { |
| 119 | switch (c) { |
| 120 | case '#': |
| 121 | case '!': |
| 122 | if (key == null) { |
nothing calls this directly
no outgoing calls
no test coverage detected