|
12 | 12 | */ |
13 | 13 | public class TokenStream extends LinkedList<Token> { |
14 | 14 |
|
15 | | - private FileOptions fileOptions; |
16 | | - private String rawFileOptions; |
| 15 | + private FileOptions fileOptions; |
| 16 | + private String rawFileOptions; |
17 | 17 |
|
18 | | - public TokenStream() { |
19 | | - super(); |
20 | | - this.fileOptions = null; |
21 | | - } |
| 18 | + public TokenStream() { |
| 19 | + super(); |
| 20 | + this.fileOptions = null; |
| 21 | + } |
22 | 22 |
|
23 | | - public TokenStream(List<Token> list, FileOptions options) { |
24 | | - super(list); |
25 | | - this.fileOptions = options; |
26 | | - } |
| 23 | + public TokenStream(List<Token> list, FileOptions options) { |
| 24 | + super(list); |
| 25 | + this.fileOptions = options; |
| 26 | + } |
27 | 27 |
|
28 | | - public TokenStream(List<Token> list, String fileOptions) { |
29 | | - super(list); |
30 | | - this.fileOptions = parseFileOptions(fileOptions); |
31 | | - } |
| 28 | + public TokenStream(List<Token> list, String fileOptions) { |
| 29 | + super(list); |
| 30 | + this.fileOptions = parseFileOptions(fileOptions); |
| 31 | + } |
32 | 32 |
|
33 | | - public void setFileOptions(String fileOptions) { |
34 | | - this.rawFileOptions = fileOptions; |
35 | | - this.fileOptions = parseFileOptions(fileOptions); |
36 | | - } |
| 33 | + public void setFileOptions(String fileOptions) { |
| 34 | + this.rawFileOptions = fileOptions; |
| 35 | + this.fileOptions = parseFileOptions(fileOptions); |
| 36 | + } |
37 | 37 |
|
38 | | - public void setFileOptions(FileOptions fileOptions) { |
39 | | - this.fileOptions = fileOptions; |
40 | | - } |
| 38 | + public void setFileOptions(FileOptions fileOptions) { |
| 39 | + this.fileOptions = fileOptions; |
| 40 | + } |
41 | 41 |
|
42 | | - public FileOptions getFileOptions() { |
43 | | - return this.fileOptions; |
44 | | - } |
| 42 | + public FileOptions getFileOptions() { |
| 43 | + return this.fileOptions; |
| 44 | + } |
45 | 45 |
|
46 | | - /** |
47 | | - * Returns the file options as they were originally passed in. This should only be used in special cases (syntax |
48 | | - * highlighters, etc) |
49 | | - * @return |
50 | | - */ |
51 | | - public String getRawFileOptions() { |
52 | | - return rawFileOptions; |
53 | | - } |
| 46 | + /** |
| 47 | + * Returns the file options as they were originally passed in. This should only be used in special cases (syntax |
| 48 | + * highlighters, etc) |
| 49 | + * |
| 50 | + * @return |
| 51 | + */ |
| 52 | + public String getRawFileOptions() { |
| 53 | + return rawFileOptions; |
| 54 | + } |
54 | 55 |
|
55 | | - private static FileOptions parseFileOptions(String options) { |
56 | | - //Only ; needs escaping. Everything else is just trimmed, and added to the map. |
57 | | - Map<String, String> map = new HashMap<String, String>(); |
58 | | - boolean inKey = true; |
59 | | - StringBuilder buffer = new StringBuilder(); |
60 | | - String keyName = ""; |
61 | | - for (int i = 0; i < options.length(); i++) { |
62 | | - Character c = options.charAt(i); |
63 | | - Character c2 = null; |
64 | | - if (i < options.length() - 1) { |
65 | | - c2 = options.charAt(i + 1); |
66 | | - } |
67 | | - if (inKey) { |
68 | | - if (c == ':') { |
69 | | - keyName = buffer.toString(); |
70 | | - buffer = new StringBuilder(); |
71 | | - inKey = false; |
72 | | - } else if (c == ';') { |
73 | | - //Self closed |
74 | | - map.put(buffer.toString().trim().toLowerCase(), "true"); |
75 | | - buffer = new StringBuilder(); |
76 | | - keyName = ""; |
77 | | - //We don't reset the inKey parameter |
78 | | - } else { |
79 | | - buffer.append(c); |
| 56 | + private static FileOptions parseFileOptions(String options) { |
| 57 | + //Only ; needs escaping. Everything else is just trimmed, and added to the map. |
| 58 | + Map<String, String> map = new HashMap<String, String>(); |
| 59 | + boolean inKey = true; |
| 60 | + StringBuilder buffer = new StringBuilder(); |
| 61 | + String keyName = ""; |
| 62 | + for (int i = 0; i < options.length(); i++) { |
| 63 | + Character c = options.charAt(i); |
| 64 | + Character c2 = null; |
| 65 | + if (i < options.length() - 1) { |
| 66 | + c2 = options.charAt(i + 1); |
| 67 | + } |
| 68 | + if (inKey) { |
| 69 | + if (c == ':') { |
| 70 | + keyName = buffer.toString(); |
| 71 | + buffer = new StringBuilder(); |
| 72 | + inKey = false; |
| 73 | + } else if (c == ';') { |
| 74 | + //Self closed |
| 75 | + map.put(buffer.toString().trim().toLowerCase(), "true"); |
| 76 | + buffer = new StringBuilder(); |
| 77 | + keyName = ""; |
| 78 | + //We don't reset the inKey parameter |
| 79 | + } else { |
| 80 | + buffer.append(c); |
| 81 | + } |
| 82 | + } else { |
| 83 | + if (c == '\\' && c2 == ';') { |
| 84 | + buffer.append(';'); |
| 85 | + i++; |
| 86 | + } else if (c == ';') { |
| 87 | + //We're done |
| 88 | + inKey = true; |
| 89 | + map.put(keyName.trim().toLowerCase(), buffer.toString()); |
| 90 | + buffer = new StringBuilder(); |
| 91 | + } else { |
| 92 | + buffer.append(c); |
| 93 | + } |
| 94 | + } |
80 | 95 | } |
81 | | - } else { |
82 | | - if (c == '\\' && c2 == ';') { |
83 | | - buffer.append(';'); |
84 | | - i++; |
85 | | - } else if (c == ';') { |
86 | | - //We're done |
87 | | - inKey = true; |
88 | | - map.put(keyName.trim().toLowerCase(), buffer.toString()); |
89 | | - buffer = new StringBuilder(); |
90 | | - } else { |
91 | | - buffer.append(c); |
92 | | - } |
93 | | - } |
94 | | - } |
95 | | - if (buffer.length() > 0) { |
96 | | - if (!inKey) { |
97 | | - map.put(keyName.trim().toLowerCase(), buffer.toString()); |
98 | | - } else { |
99 | | - if (!buffer.toString().trim().isEmpty()) { |
100 | | - map.put(buffer.toString().trim().toLowerCase(), "true"); |
| 96 | + if (buffer.length() > 0) { |
| 97 | + if (!inKey) { |
| 98 | + map.put(keyName.trim().toLowerCase(), buffer.toString()); |
| 99 | + } else { |
| 100 | + if (!buffer.toString().trim().isEmpty()) { |
| 101 | + map.put(buffer.toString().trim().toLowerCase(), "true"); |
| 102 | + } |
| 103 | + } |
101 | 104 | } |
102 | | - } |
| 105 | + FileOptions fo = new FileOptions(map); |
| 106 | + return fo; |
103 | 107 | } |
104 | | - FileOptions fo = new FileOptions(map); |
105 | | - return fo; |
106 | | - } |
107 | 108 |
|
108 | 109 | } |
0 commit comments