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