Add a set definition string to the CharSet. @param str set definition string
(final String str)
| 187 | * @param str set definition string |
| 188 | */ |
| 189 | protected void add(final String str) { |
| 190 | if (str == null) { |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | final int len = str.length(); |
| 195 | int pos = 0; |
| 196 | while (pos < len) { |
| 197 | final int remainder = len - pos; |
| 198 | if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') { |
| 199 | // negated range |
| 200 | set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3))); |
| 201 | pos += 4; |
| 202 | } else if (remainder >= 3 && str.charAt(pos + 1) == '-') { |
| 203 | // range |
| 204 | set.add(CharRange.isIn(str.charAt(pos), str.charAt(pos + 2))); |
| 205 | pos += 3; |
| 206 | } else if (remainder >= 2 && str.charAt(pos) == '^') { |
| 207 | // negated char |
| 208 | set.add(CharRange.isNot(str.charAt(pos + 1))); |
| 209 | pos += 2; |
| 210 | } else { |
| 211 | // char |
| 212 | set.add(CharRange.is(str.charAt(pos))); |
| 213 | pos += 1; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | //----------------------------------------------------------------------- |
| 219 | /** |
no test coverage detected