| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.yaml.snakeyaml.scanner; |
| 18 | |
|
| 19 | |
import java.util.Arrays; |
| 20 | |
|
| 21 | |
public final class Constant { |
| 22 | |
private final static String ALPHA_S = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; |
| 23 | |
|
| 24 | |
private final static String LINEBR_S = "\n\u0085\u2028\u2029"; |
| 25 | |
private final static String FULL_LINEBR_S = "\r" + LINEBR_S; |
| 26 | |
private final static String NULL_OR_LINEBR_S = "\0" + FULL_LINEBR_S; |
| 27 | |
private final static String NULL_BL_LINEBR_S = " " + NULL_OR_LINEBR_S; |
| 28 | |
private final static String NULL_BL_T_LINEBR_S = "\t" + NULL_BL_LINEBR_S; |
| 29 | |
private final static String NULL_BL_T_S = "\0 \t"; |
| 30 | |
private final static String URI_CHARS_S = ALPHA_S + "-;/?:@&=+$,_.!~*\'()[]%"; |
| 31 | |
|
| 32 | 1 | public final static Constant LINEBR = new Constant(LINEBR_S); |
| 33 | 1 | public final static Constant FULL_LINEBR = new Constant(FULL_LINEBR_S); |
| 34 | 1 | public final static Constant NULL_OR_LINEBR = new Constant(NULL_OR_LINEBR_S); |
| 35 | 1 | public final static Constant NULL_BL_LINEBR = new Constant(NULL_BL_LINEBR_S); |
| 36 | 1 | public final static Constant NULL_BL_T_LINEBR = new Constant(NULL_BL_T_LINEBR_S); |
| 37 | 1 | public final static Constant NULL_BL_T = new Constant(NULL_BL_T_S); |
| 38 | 1 | public final static Constant URI_CHARS = new Constant(URI_CHARS_S); |
| 39 | |
|
| 40 | 1 | public final static Constant ALPHA = new Constant(ALPHA_S); |
| 41 | |
|
| 42 | |
private String content; |
| 43 | 8 | boolean[] contains = new boolean[128]; |
| 44 | 8 | boolean noASCII = false; |
| 45 | |
|
| 46 | 8 | private Constant(String content) { |
| 47 | 8 | Arrays.fill(contains, false); |
| 48 | 8 | StringBuilder sb = new StringBuilder(); |
| 49 | 191 | for (int i = 0; i < content.length(); i++) { |
| 50 | 183 | char ch = content.charAt(i); |
| 51 | 183 | if (ch < 128) |
| 52 | 168 | contains[ch] = true; |
| 53 | |
else |
| 54 | 15 | sb.append(ch); |
| 55 | |
} |
| 56 | 8 | if (sb.length() > 0) { |
| 57 | 5 | noASCII = true; |
| 58 | 5 | this.content = sb.toString(); |
| 59 | |
} |
| 60 | 8 | } |
| 61 | |
|
| 62 | |
public boolean has(char ch) { |
| 63 | 19168626 | return (ch < 128) ? contains[ch] : noASCII && content.indexOf(ch, 0) != -1; |
| 64 | |
} |
| 65 | |
|
| 66 | |
public boolean hasNo(char ch) { |
| 67 | 106407 | return !has(ch); |
| 68 | |
} |
| 69 | |
|
| 70 | |
public boolean has(char ch, String additional) { |
| 71 | 1872260 | return has(ch) || additional.indexOf(ch, 0) != -1; |
| 72 | |
} |
| 73 | |
|
| 74 | |
public boolean hasNo(char ch, String additional) { |
| 75 | 924628 | return !has(ch, additional); |
| 76 | |
} |
| 77 | |
} |