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