( left: readonly PackedCollationElement[], right: readonly PackedCollationElement[], levels: number, ignoreVariable: boolean )
| 416 | } |
| 417 | |
| 418 | function compareCollationElements( |
| 419 | left: readonly PackedCollationElement[], |
| 420 | right: readonly PackedCollationElement[], |
| 421 | levels: number, |
| 422 | ignoreVariable: boolean |
| 423 | ): number { |
| 424 | // UCA compares level by level. ignorePunctuation maps to shifted handling for |
| 425 | // variable elements, approximated here by filtering variable weights. |
| 426 | // https://www.unicode.org/reports/tr10/#Multi_Level_Comparison |
| 427 | // https://www.unicode.org/reports/tr35/tr35-collation.html#Setting_Options |
| 428 | for (let level = 0; level < levels; level++) { |
| 429 | const leftWeights = left |
| 430 | .filter(element => !ignoreVariable || (element[4] & 1) === 0) |
| 431 | .map(element => element[level]) |
| 432 | .filter(weight => weight !== 0) |
| 433 | const rightWeights = right |
| 434 | .filter(element => !ignoreVariable || (element[4] & 1) === 0) |
| 435 | .map(element => element[level]) |
| 436 | .filter(weight => weight !== 0) |
| 437 | const length = Math.max(leftWeights.length, rightWeights.length) |
| 438 | for (let i = 0; i < length; i++) { |
| 439 | const result = compareNumbers(leftWeights[i] || 0, rightWeights[i] || 0) |
| 440 | if (result) { |
| 441 | return result |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | return 0 |
| 446 | } |
| 447 | |
| 448 | function comparePreparedStrings( |
| 449 | left: string, |
no test coverage detected