OLD | NEW |
| (Empty) |
1 dart_library.library('collection/src/comparators', null, /* Imports */[ | |
2 'dart/_runtime', | |
3 'dart/core' | |
4 ], /* Lazy imports */[ | |
5 ], function(exports, dart, core) { | |
6 'use strict'; | |
7 let dartx = dart.dartx; | |
8 const _zero = 48; | |
9 const _upperCaseA = 65; | |
10 const _upperCaseZ = 90; | |
11 const _lowerCaseA = 97; | |
12 const _lowerCaseZ = 122; | |
13 const _asciiCaseBit = 32; | |
14 function equalsIgnoreAsciiCase(a, b) { | |
15 if (a[dartx.length] != b[dartx.length]) return false; | |
16 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
17 let aChar = a[dartx.codeUnitAt](i); | |
18 let bChar = b[dartx.codeUnitAt](i); | |
19 if (aChar == bChar) continue; | |
20 if ((dart.notNull(aChar) ^ dart.notNull(bChar)) != _asciiCaseBit) return f
alse; | |
21 let aCharUpperCase = dart.notNull(aChar) | dart.notNull(_asciiCaseBit); | |
22 if (dart.notNull(_upperCaseA) <= aCharUpperCase && aCharUpperCase <= dart.
notNull(_upperCaseZ)) { | |
23 continue; | |
24 } | |
25 return false; | |
26 } | |
27 return true; | |
28 } | |
29 dart.fn(equalsIgnoreAsciiCase, core.bool, [core.String, core.String]); | |
30 function hashIgnoreAsciiCase(string) { | |
31 let hash = 0; | |
32 for (let i = 0; i < dart.notNull(string[dartx.length]); i++) { | |
33 let char = string[dartx.codeUnitAt](i); | |
34 if (dart.notNull(_lowerCaseA) <= dart.notNull(char) && dart.notNull(char)
<= dart.notNull(_lowerCaseZ)) { | |
35 char = dart.notNull(char) - dart.notNull(_asciiCaseBit); | |
36 } | |
37 hash = 536870911 & hash + dart.notNull(char); | |
38 hash = 536870911 & hash + ((524287 & hash) << 10); | |
39 hash = hash >> 6; | |
40 } | |
41 hash = 536870911 & hash + ((67108863 & hash) << 3); | |
42 hash = hash >> 11; | |
43 return 536870911 & hash + ((16383 & hash) << 15); | |
44 } | |
45 dart.fn(hashIgnoreAsciiCase, core.int, [core.String]); | |
46 function compareAsciiUpperCase(a, b) { | |
47 let defaultResult = 0; | |
48 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
49 if (i >= dart.notNull(b[dartx.length])) return 1; | |
50 let aChar = a[dartx.codeUnitAt](i); | |
51 let bChar = b[dartx.codeUnitAt](i); | |
52 if (aChar == bChar) continue; | |
53 let aUpperCase = aChar; | |
54 let bUpperCase = bChar; | |
55 if (dart.notNull(_lowerCaseA) <= dart.notNull(aChar) && dart.notNull(aChar
) <= dart.notNull(_lowerCaseZ)) { | |
56 aUpperCase = dart.notNull(aUpperCase) - dart.notNull(_asciiCaseBit); | |
57 } | |
58 if (dart.notNull(_lowerCaseA) <= dart.notNull(bChar) && dart.notNull(bChar
) <= dart.notNull(_lowerCaseZ)) { | |
59 bUpperCase = dart.notNull(bUpperCase) - dart.notNull(_asciiCaseBit); | |
60 } | |
61 if (aUpperCase != bUpperCase) return (dart.notNull(aUpperCase) - dart.notN
ull(bUpperCase))[dartx.sign]; | |
62 if (defaultResult == 0) defaultResult = dart.notNull(aChar) - dart.notNull
(bChar); | |
63 } | |
64 if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length])) return -1
; | |
65 return defaultResult[dartx.sign]; | |
66 } | |
67 dart.fn(compareAsciiUpperCase, core.int, [core.String, core.String]); | |
68 function compareAsciiLowerCase(a, b) { | |
69 let defaultResult = 0; | |
70 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
71 if (i >= dart.notNull(b[dartx.length])) return 1; | |
72 let aChar = a[dartx.codeUnitAt](i); | |
73 let bChar = b[dartx.codeUnitAt](i); | |
74 if (aChar == bChar) continue; | |
75 let aLowerCase = aChar; | |
76 let bLowerCase = bChar; | |
77 if (dart.notNull(_upperCaseA) <= dart.notNull(bChar) && dart.notNull(bChar
) <= dart.notNull(_upperCaseZ)) { | |
78 bLowerCase = dart.notNull(bLowerCase) + dart.notNull(_asciiCaseBit); | |
79 } | |
80 if (dart.notNull(_upperCaseA) <= dart.notNull(aChar) && dart.notNull(aChar
) <= dart.notNull(_upperCaseZ)) { | |
81 aLowerCase = dart.notNull(aLowerCase) + dart.notNull(_asciiCaseBit); | |
82 } | |
83 if (aLowerCase != bLowerCase) return (dart.notNull(aLowerCase) - dart.notN
ull(bLowerCase))[dartx.sign]; | |
84 if (defaultResult == 0) defaultResult = dart.notNull(aChar) - dart.notNull
(bChar); | |
85 } | |
86 if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length])) return -1
; | |
87 return defaultResult[dartx.sign]; | |
88 } | |
89 dart.fn(compareAsciiLowerCase, core.int, [core.String, core.String]); | |
90 function compareNatural(a, b) { | |
91 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
92 if (i >= dart.notNull(b[dartx.length])) return 1; | |
93 let aChar = a[dartx.codeUnitAt](i); | |
94 let bChar = b[dartx.codeUnitAt](i); | |
95 if (aChar != bChar) { | |
96 return _compareNaturally(a, b, i, aChar, bChar); | |
97 } | |
98 } | |
99 if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length])) return -1
; | |
100 return 0; | |
101 } | |
102 dart.fn(compareNatural, core.int, [core.String, core.String]); | |
103 function compareAsciiLowerCaseNatural(a, b) { | |
104 let defaultResult = 0; | |
105 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
106 if (i >= dart.notNull(b[dartx.length])) return 1; | |
107 let aChar = a[dartx.codeUnitAt](i); | |
108 let bChar = b[dartx.codeUnitAt](i); | |
109 if (aChar == bChar) continue; | |
110 let aLowerCase = aChar; | |
111 let bLowerCase = bChar; | |
112 if (dart.notNull(_upperCaseA) <= dart.notNull(aChar) && dart.notNull(aChar
) <= dart.notNull(_upperCaseZ)) { | |
113 aLowerCase = dart.notNull(aLowerCase) + dart.notNull(_asciiCaseBit); | |
114 } | |
115 if (dart.notNull(_upperCaseA) <= dart.notNull(bChar) && dart.notNull(bChar
) <= dart.notNull(_upperCaseZ)) { | |
116 bLowerCase = dart.notNull(bLowerCase) + dart.notNull(_asciiCaseBit); | |
117 } | |
118 if (aLowerCase != bLowerCase) { | |
119 return _compareNaturally(a, b, i, aLowerCase, bLowerCase); | |
120 } | |
121 if (defaultResult == 0) defaultResult = dart.notNull(aChar) - dart.notNull
(bChar); | |
122 } | |
123 if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length])) return -1
; | |
124 return defaultResult[dartx.sign]; | |
125 } | |
126 dart.fn(compareAsciiLowerCaseNatural, core.int, [core.String, core.String]); | |
127 function compareAsciiUpperCaseNatural(a, b) { | |
128 let defaultResult = 0; | |
129 for (let i = 0; i < dart.notNull(a[dartx.length]); i++) { | |
130 if (i >= dart.notNull(b[dartx.length])) return 1; | |
131 let aChar = a[dartx.codeUnitAt](i); | |
132 let bChar = b[dartx.codeUnitAt](i); | |
133 if (aChar == bChar) continue; | |
134 let aUpperCase = aChar; | |
135 let bUpperCase = bChar; | |
136 if (dart.notNull(_lowerCaseA) <= dart.notNull(aChar) && dart.notNull(aChar
) <= dart.notNull(_lowerCaseZ)) { | |
137 aUpperCase = dart.notNull(aUpperCase) - dart.notNull(_asciiCaseBit); | |
138 } | |
139 if (dart.notNull(_lowerCaseA) <= dart.notNull(bChar) && dart.notNull(bChar
) <= dart.notNull(_lowerCaseZ)) { | |
140 bUpperCase = dart.notNull(bUpperCase) - dart.notNull(_asciiCaseBit); | |
141 } | |
142 if (aUpperCase != bUpperCase) { | |
143 return _compareNaturally(a, b, i, aUpperCase, bUpperCase); | |
144 } | |
145 if (defaultResult == 0) defaultResult = dart.notNull(aChar) - dart.notNull
(bChar); | |
146 } | |
147 if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length])) return -1
; | |
148 return defaultResult[dartx.sign]; | |
149 } | |
150 dart.fn(compareAsciiUpperCaseNatural, core.int, [core.String, core.String]); | |
151 function _compareNaturally(a, b, index, aChar, bChar) { | |
152 dart.assert(aChar != bChar); | |
153 let aIsDigit = _isDigit(aChar); | |
154 let bIsDigit = _isDigit(bChar); | |
155 if (dart.notNull(aIsDigit)) { | |
156 if (dart.notNull(bIsDigit)) { | |
157 return _compareNumerically(a, b, aChar, bChar, index); | |
158 } else if (dart.notNull(index) > 0 && dart.notNull(_isDigit(a[dartx.codeUn
itAt](dart.notNull(index) - 1)))) { | |
159 return 1; | |
160 } | |
161 } else if (dart.notNull(bIsDigit) && dart.notNull(index) > 0 && dart.notNull
(_isDigit(b[dartx.codeUnitAt](dart.notNull(index) - 1)))) { | |
162 return -1; | |
163 } | |
164 return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign]; | |
165 } | |
166 dart.fn(_compareNaturally, core.int, [core.String, core.String, core.int, core
.int, core.int]); | |
167 function _compareNumerically(a, b, aChar, bChar, index) { | |
168 if (dart.notNull(_isNonZeroNumberSuffix(a, index))) { | |
169 let result = _compareDigitCount(a, b, index, index); | |
170 if (result != 0) return result; | |
171 return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign]; | |
172 } | |
173 let aIndex = index; | |
174 let bIndex = index; | |
175 if (aChar == _zero) { | |
176 do { | |
177 aIndex = dart.notNull(aIndex) + 1; | |
178 if (aIndex == a[dartx.length]) return -1; | |
179 aChar = a[dartx.codeUnitAt](aIndex); | |
180 } while (aChar == _zero); | |
181 if (!dart.notNull(_isDigit(aChar))) return -1; | |
182 } else if (bChar == _zero) { | |
183 do { | |
184 bIndex = dart.notNull(bIndex) + 1; | |
185 if (bIndex == b[dartx.length]) return 1; | |
186 bChar = b[dartx.codeUnitAt](bIndex); | |
187 } while (bChar == _zero); | |
188 if (!dart.notNull(_isDigit(bChar))) return 1; | |
189 } | |
190 if (aChar != bChar) { | |
191 let result = _compareDigitCount(a, b, aIndex, bIndex); | |
192 if (result != 0) return result; | |
193 return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign]; | |
194 } | |
195 while (true) { | |
196 let aIsDigit = false; | |
197 let bIsDigit = false; | |
198 aChar = 0; | |
199 bChar = 0; | |
200 if ((aIndex = dart.notNull(aIndex) + 1) < dart.notNull(a[dartx.length])) { | |
201 aChar = a[dartx.codeUnitAt](aIndex); | |
202 aIsDigit = _isDigit(aChar); | |
203 } | |
204 if ((bIndex = dart.notNull(bIndex) + 1) < dart.notNull(b[dartx.length])) { | |
205 bChar = b[dartx.codeUnitAt](bIndex); | |
206 bIsDigit = _isDigit(bChar); | |
207 } | |
208 if (dart.notNull(aIsDigit)) { | |
209 if (dart.notNull(bIsDigit)) { | |
210 if (aChar == bChar) continue; | |
211 break; | |
212 } | |
213 return 1; | |
214 } else if (dart.notNull(bIsDigit)) { | |
215 return -1; | |
216 } else { | |
217 return (dart.notNull(aIndex) - dart.notNull(bIndex))[dartx.sign]; | |
218 } | |
219 } | |
220 let result = _compareDigitCount(a, b, aIndex, bIndex); | |
221 if (result != 0) return result; | |
222 return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign]; | |
223 } | |
224 dart.fn(_compareNumerically, core.int, [core.String, core.String, core.int, co
re.int, core.int]); | |
225 function _compareDigitCount(a, b, i, j) { | |
226 while ((i = dart.notNull(i) + 1) < dart.notNull(a[dartx.length])) { | |
227 let aIsDigit = _isDigit(a[dartx.codeUnitAt](i)); | |
228 if ((j = dart.notNull(j) + 1) == b[dartx.length]) return dart.notNull(aIsD
igit) ? 1 : 0; | |
229 let bIsDigit = _isDigit(b[dartx.codeUnitAt](j)); | |
230 if (dart.notNull(aIsDigit)) { | |
231 if (dart.notNull(bIsDigit)) continue; | |
232 return 1; | |
233 } else if (dart.notNull(bIsDigit)) { | |
234 return -1; | |
235 } else { | |
236 return 0; | |
237 } | |
238 } | |
239 if ((j = dart.notNull(j) + 1) < dart.notNull(b[dartx.length]) && dart.notNul
l(_isDigit(b[dartx.codeUnitAt](j)))) { | |
240 return -1; | |
241 } | |
242 return 0; | |
243 } | |
244 dart.fn(_compareDigitCount, core.int, [core.String, core.String, core.int, cor
e.int]); | |
245 function _isDigit(charCode) { | |
246 return (dart.notNull(charCode) ^ dart.notNull(_zero)) <= 9; | |
247 } | |
248 dart.fn(_isDigit, core.bool, [core.int]); | |
249 function _isNonZeroNumberSuffix(string, index) { | |
250 while ((index = dart.notNull(index) - 1) >= 0) { | |
251 let char = string[dartx.codeUnitAt](index); | |
252 if (char != _zero) return _isDigit(char); | |
253 } | |
254 return false; | |
255 } | |
256 dart.fn(_isNonZeroNumberSuffix, core.bool, [core.String, core.int]); | |
257 // Exports: | |
258 exports.equalsIgnoreAsciiCase = equalsIgnoreAsciiCase; | |
259 exports.hashIgnoreAsciiCase = hashIgnoreAsciiCase; | |
260 exports.compareAsciiUpperCase = compareAsciiUpperCase; | |
261 exports.compareAsciiLowerCase = compareAsciiLowerCase; | |
262 exports.compareNatural = compareNatural; | |
263 exports.compareAsciiLowerCaseNatural = compareAsciiLowerCaseNatural; | |
264 exports.compareAsciiUpperCaseNatural = compareAsciiUpperCaseNatural; | |
265 }); | |
OLD | NEW |