OLD | NEW |
1 library java.engine; | 1 library java.engine; |
2 | 2 |
3 import 'java_core.dart'; | 3 import 'java_core.dart'; |
4 | 4 |
5 class StringUtilities { | 5 class StringUtilities { |
6 static const String EMPTY = ''; | 6 static const String EMPTY = ''; |
7 static const List<String> EMPTY_ARRAY = const <String> []; | 7 static const List<String> EMPTY_ARRAY = const <String>[]; |
8 static String intern(String s) => s; | 8 static String intern(String s) => s; |
9 static bool isTagName(String s) { | 9 static bool isTagName(String s) { |
10 if (s == null || s.length == 0) { | 10 if (s == null || s.length == 0) { |
11 return false; | 11 return false; |
12 } | 12 } |
13 int sz = s.length; | 13 int sz = s.length; |
14 for (int i = 0; i < sz; i++) { | 14 for (int i = 0; i < sz; i++) { |
15 int c = s.codeUnitAt(i); | 15 int c = s.codeUnitAt(i); |
16 if (!Character.isLetter(c)) { | 16 if (!Character.isLetter(c)) { |
17 if (i == 0) { | 17 if (i == 0) { |
(...skipping 18 matching lines...) Expand all Loading... |
36 return str; | 36 return str; |
37 } | 37 } |
38 return str.substring(0, pos); | 38 return str.substring(0, pos); |
39 } | 39 } |
40 static endsWithChar(String str, int c) { | 40 static endsWithChar(String str, int c) { |
41 int length = str.length; | 41 int length = str.length; |
42 return length > 0 && str.codeUnitAt(length - 1) == c; | 42 return length > 0 && str.codeUnitAt(length - 1) == c; |
43 } | 43 } |
44 static endsWith3(String str, int c1, int c2, int c3) { | 44 static endsWith3(String str, int c1, int c2, int c3) { |
45 var length = str.length; | 45 var length = str.length; |
46 return length >= 3 && | 46 return length >= 3 && str.codeUnitAt(length - 3) == c1 && str.codeUnitAt( |
47 str.codeUnitAt(length - 3) == c1 && | 47 length - 2) == c2 && str.codeUnitAt(length - 1) == c3; |
48 str.codeUnitAt(length - 2) == c2 && | |
49 str.codeUnitAt(length - 1) == c3; | |
50 } | 48 } |
51 | 49 |
52 static startsWithChar(String str, int c) { | 50 static startsWithChar(String str, int c) { |
53 return str.length != 0 && str.codeUnitAt(0) == c; | 51 return str.length != 0 && str.codeUnitAt(0) == c; |
54 } | 52 } |
55 static startsWith2(String str, int start, int c1, int c2) { | 53 static startsWith2(String str, int start, int c1, int c2) { |
56 return str.length - start >= 2 && | 54 return str.length - start >= 2 && str.codeUnitAt(start) == c1 && |
57 str.codeUnitAt(start) == c1 && | |
58 str.codeUnitAt(start + 1) == c2; | 55 str.codeUnitAt(start + 1) == c2; |
59 } | 56 } |
60 static startsWith3(String str, int start, int c1, int c2, int c3) { | 57 static startsWith3(String str, int start, int c1, int c2, int c3) { |
61 return str.length - start >= 3 && | 58 return str.length - start >= 3 && str.codeUnitAt(start) == c1 && |
62 str.codeUnitAt(start) == c1 && | 59 str.codeUnitAt(start + 1) == c2 && str.codeUnitAt(start + 2) == c3; |
63 str.codeUnitAt(start + 1) == c2 && | |
64 str.codeUnitAt(start + 2) == c3; | |
65 } | 60 } |
66 static startsWith4(String str, int start, int c1, int c2, int c3, int c4) { | 61 static startsWith4(String str, int start, int c1, int c2, int c3, int c4) { |
67 return str.length - start >= 4 && | 62 return str.length - start >= 4 && str.codeUnitAt(start) == c1 && |
68 str.codeUnitAt(start) == c1 && | 63 str.codeUnitAt(start + 1) == c2 && str.codeUnitAt(start + 2) == c3 && |
69 str.codeUnitAt(start + 1) == c2 && | |
70 str.codeUnitAt(start + 2) == c3 && | |
71 str.codeUnitAt(start + 3) == c4; | 64 str.codeUnitAt(start + 3) == c4; |
72 } | 65 } |
73 static startsWith5(String str, int start, int c1, int c2, int c3, int c4, | 66 static startsWith5(String str, int start, int c1, int c2, int c3, int c4, int |
74 int c5) { | 67 c5) { |
75 return str.length - start >= 5 && | 68 return str.length - start >= 5 && str.codeUnitAt(start) == c1 && |
76 str.codeUnitAt(start) == c1 && | 69 str.codeUnitAt(start + 1) == c2 && str.codeUnitAt(start + 2) == c3 && |
77 str.codeUnitAt(start + 1) == c2 && | 70 str.codeUnitAt(start + 3) == c4 && str.codeUnitAt(start + 4) == c5; |
78 str.codeUnitAt(start + 2) == c3 && | |
79 str.codeUnitAt(start + 3) == c4 && | |
80 str.codeUnitAt(start + 4) == c5; | |
81 } | 71 } |
82 static startsWith6(String str, int start, int c1, int c2, int c3, int c4, | 72 static startsWith6(String str, int start, int c1, int c2, int c3, int c4, int |
83 int c5, int c6) { | 73 c5, int c6) { |
84 return str.length - start >= 6 && | 74 return str.length - start >= 6 && str.codeUnitAt(start) == c1 && |
85 str.codeUnitAt(start) == c1 && | 75 str.codeUnitAt(start + 1) == c2 && str.codeUnitAt(start + 2) == c3 && |
86 str.codeUnitAt(start + 1) == c2 && | 76 str.codeUnitAt(start + 3) == c4 && str.codeUnitAt(start + 4) == c5 && |
87 str.codeUnitAt(start + 2) == c3 && | |
88 str.codeUnitAt(start + 3) == c4 && | |
89 str.codeUnitAt(start + 4) == c5 && | |
90 str.codeUnitAt(start + 5) == c6; | 77 str.codeUnitAt(start + 5) == c6; |
91 } | 78 } |
92 static int indexOf1(String str, int start, int c) { | 79 static int indexOf1(String str, int start, int c) { |
93 int index = start; | 80 int index = start; |
94 int last = str.length; | 81 int last = str.length; |
95 while (index < last) { | 82 while (index < last) { |
96 if (str.codeUnitAt(index) == c) { | 83 if (str.codeUnitAt(index) == c) { |
97 return index; | 84 return index; |
98 } | 85 } |
99 index++; | 86 index++; |
100 } | 87 } |
101 return -1; | 88 return -1; |
102 } | 89 } |
103 static int indexOf2(String str, int start, int c1, int c2) { | 90 static int indexOf2(String str, int start, int c1, int c2) { |
104 int index = start; | 91 int index = start; |
105 int last = str.length - 1; | 92 int last = str.length - 1; |
106 while (index < last) { | 93 while (index < last) { |
107 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2) { | 94 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2) { |
108 return index; | 95 return index; |
109 } | 96 } |
110 index++; | 97 index++; |
111 } | 98 } |
112 return -1; | 99 return -1; |
113 } | 100 } |
114 static int indexOf4(String string, int start, int c1, int c2, int c3, int c4)
{ | 101 static int indexOf4(String string, int start, int c1, int c2, int c3, int c4) |
| 102 { |
115 int index = start; | 103 int index = start; |
116 int last = string.length - 3; | 104 int last = string.length - 3; |
117 while (index < last) { | 105 while (index < last) { |
118 if (string.codeUnitAt(index) == c1 && | 106 if (string.codeUnitAt(index) == c1 && string.codeUnitAt(index + 1) == c2 |
119 string.codeUnitAt(index + 1) == c2 && | 107 && string.codeUnitAt(index + 2) == c3 && string.codeUnitAt(index + 3)
== c4) { |
120 string.codeUnitAt(index + 2) == c3 && | |
121 string.codeUnitAt(index + 3) == c4) { | |
122 return index; | 108 return index; |
123 } | 109 } |
124 index++; | 110 index++; |
125 } | 111 } |
126 return -1; | 112 return -1; |
127 } | 113 } |
128 static int indexOf5(String str, int start, int c1, int c2, int c3, int c4, | 114 static int indexOf5(String str, int start, int c1, int c2, int c3, int c4, int |
129 int c5) { | 115 c5) { |
130 int index = start; | 116 int index = start; |
131 int last = str.length - 4; | 117 int last = str.length - 4; |
132 while (index < last) { | 118 while (index < last) { |
133 if (str.codeUnitAt(index) == c1 && | 119 if (str.codeUnitAt(index) == c1 && str.codeUnitAt(index + 1) == c2 && |
134 str.codeUnitAt(index + 1) == c2 && | 120 str.codeUnitAt(index + 2) == c3 && str.codeUnitAt(index + 3) == c4 && |
135 str.codeUnitAt(index + 2) == c3 && | |
136 str.codeUnitAt(index + 3) == c4 && | |
137 str.codeUnitAt(index + 4) == c5) { | 121 str.codeUnitAt(index + 4) == c5) { |
138 return index; | 122 return index; |
139 } | 123 } |
140 index++; | 124 index++; |
141 } | 125 } |
142 return -1; | 126 return -1; |
143 } | 127 } |
144 static String substringBeforeChar(String str, int c) { | 128 static String substringBeforeChar(String str, int c) { |
145 if (isEmpty(str)) { | 129 if (isEmpty(str)) { |
146 return str; | 130 return str; |
147 } | 131 } |
148 int pos = indexOf1(str, 0, c); | 132 int pos = indexOf1(str, 0, c); |
149 if (pos < 0) { | 133 if (pos < 0) { |
150 return str; | 134 return str; |
151 } | 135 } |
152 return str.substring(0, pos); | 136 return str.substring(0, pos); |
153 } | 137 } |
| 138 |
| 139 /** |
| 140 * Return the index of the first not letter/digit character in the [string] |
| 141 * that is at or after the [startIndex]. Return the length of the [string] if |
| 142 * all characters to the end are letters/digits. |
| 143 */ |
| 144 static int indexOfFirstNotLetterDigit(String string, int startIndex) { |
| 145 int index = startIndex; |
| 146 int last = string.length; |
| 147 while (index < last) { |
| 148 int c = string.codeUnitAt(index); |
| 149 if (!Character.isLetterOrDigit(c)) { |
| 150 return index; |
| 151 } |
| 152 index++; |
| 153 } |
| 154 return last; |
| 155 } |
154 } | 156 } |
155 | 157 |
156 class FileNameUtilities { | 158 class FileNameUtilities { |
157 static String getExtension(String fileName) { | 159 static String getExtension(String fileName) { |
158 if (fileName == null) { | 160 if (fileName == null) { |
159 return ""; | 161 return ""; |
160 } | 162 } |
161 int index = fileName.lastIndexOf('.'); | 163 int index = fileName.lastIndexOf('.'); |
162 if (index >= 0) { | 164 if (index >= 0) { |
163 return fileName.substring(index + 1); | 165 return fileName.substring(index + 1); |
(...skipping 14 matching lines...) Expand all Loading... |
178 static int combineHashCodes(int first, int second) => first * 31 + second; | 180 static int combineHashCodes(int first, int second) => first * 31 + second; |
179 } | 181 } |
180 | 182 |
181 class UUID { | 183 class UUID { |
182 static int __nextId = 0; | 184 static int __nextId = 0; |
183 final String id; | 185 final String id; |
184 UUID(this.id); | 186 UUID(this.id); |
185 String toString() => id; | 187 String toString() => id; |
186 static UUID randomUUID() => new UUID((__nextId).toString()); | 188 static UUID randomUUID() => new UUID((__nextId).toString()); |
187 } | 189 } |
OLD | NEW |