(String spec, long n)
| 94 | } |
| 95 | |
| 96 | private String |
| 97 | substitute(String spec, long n) throws IOException { |
| 98 | boolean escaped = false; |
| 99 | byte [] str = spec.getBytes(); |
| 100 | StringBuffer sb = new StringBuffer(); |
| 101 | |
| 102 | for (int i = 0; i < str.length; i++) { |
| 103 | char c = (char)(str[i] & 0xFF); |
| 104 | if (escaped) { |
| 105 | sb.append(c); |
| 106 | escaped = false; |
| 107 | } else if (c == '\\') { |
| 108 | if (i + 1 == str.length) |
| 109 | throw new TextParseException |
| 110 | ("invalid escape character"); |
| 111 | escaped = true; |
| 112 | } else if (c == '$') { |
| 113 | boolean negative = false; |
| 114 | long offset = 0; |
| 115 | long width = 0; |
| 116 | long base = 10; |
| 117 | boolean wantUpperCase = false; |
| 118 | if (i + 1 < str.length && str[i + 1] == '$') { |
| 119 | // '$$' == literal '$' for backwards |
| 120 | // compatibility with old versions of BIND. |
| 121 | c = (char)(str[++i] & 0xFF); |
| 122 | sb.append(c); |
| 123 | continue; |
| 124 | } else if (i + 1 < str.length && str[i + 1] == '{') { |
| 125 | // It's a substitution with modifiers. |
| 126 | i++; |
| 127 | if (i + 1 < str.length && str[i + 1] == '-') { |
| 128 | negative = true; |
| 129 | i++; |
| 130 | } |
| 131 | while (i + 1 < str.length) { |
| 132 | c = (char)(str[++i] & 0xFF); |
| 133 | if (c == ',' || c == '}') |
| 134 | break; |
| 135 | if (c < '0' || c > '9') |
| 136 | throw new TextParseException( |
| 137 | "invalid offset"); |
| 138 | c -= '0'; |
| 139 | offset *= 10; |
| 140 | offset += c; |
| 141 | } |
| 142 | if (negative) |
| 143 | offset = -offset; |
| 144 | |
| 145 | if (c == ',') { |
| 146 | while (i + 1 < str.length) { |
| 147 | c = (char)(str[++i] & 0xFF); |
| 148 | if (c == ',' || c == '}') |
| 149 | break; |
| 150 | if (c < '0' || c > '9') |
| 151 | throw new |
| 152 | TextParseException( |
| 153 | "invalid width"); |
no test coverage detected