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