( left: string, right: string, locale: string, caseFirst: IntlCollatorInternal['caseFirst'] )
| 514 | } |
| 515 | |
| 516 | function compareCaseFirst( |
| 517 | left: string, |
| 518 | right: string, |
| 519 | locale: string, |
| 520 | caseFirst: IntlCollatorInternal['caseFirst'] |
| 521 | ): number { |
| 522 | if (caseFirst === 'false') { |
| 523 | return 0 |
| 524 | } |
| 525 | const length = Math.min(left.length, right.length) |
| 526 | for (let i = 0; i < length; i++) { |
| 527 | const leftChar = left.charAt(i) |
| 528 | const rightChar = right.charAt(i) |
| 529 | const lowerLeft = leftChar.toLocaleLowerCase(locale) |
| 530 | const lowerRight = rightChar.toLocaleLowerCase(locale) |
| 531 | if (lowerLeft !== lowerRight) { |
| 532 | continue |
| 533 | } |
| 534 | const leftIsUpper = leftChar !== lowerLeft |
| 535 | const rightIsUpper = rightChar !== lowerRight |
| 536 | if (leftIsUpper !== rightIsUpper) { |
| 537 | // ECMA-402 caseFirst / Unicode extension kf determines whether upper or |
| 538 | // lower case sorts first once base collation weights compare equal. |
| 539 | // https://tc39.es/ecma402/#sec-initializecollator |
| 540 | const upperResult = leftIsUpper ? -1 : 1 |
| 541 | return caseFirst === 'upper' ? upperResult : -upperResult |
| 542 | } |
| 543 | } |
| 544 | return 0 |
| 545 | } |
| 546 | |
| 547 | export function compareCollatorStrings( |
| 548 | slots: IntlCollatorInternal, |
no outgoing calls
no test coverage detected