( codePoints: readonly number[], start: number )
| 200 | } |
| 201 | |
| 202 | function lookupRootElements( |
| 203 | codePoints: readonly number[], |
| 204 | start: number |
| 205 | ): {elements: readonly PackedCollationElement[]; length: number} { |
| 206 | const prefixMatch = lookupPrefixElements(codePoints, start) |
| 207 | if (prefixMatch) { |
| 208 | return prefixMatch |
| 209 | } |
| 210 | |
| 211 | let node: PackedTrieNode | undefined = rootTrie |
| 212 | let matchedElements: readonly PackedCollationElement[] | undefined |
| 213 | let matchedLength = 0 |
| 214 | |
| 215 | // UCA collation element lookup is longest-match so contractions such as |
| 216 | // multi-code-point sequences beat their shorter prefixes. |
| 217 | // https://www.unicode.org/reports/tr10/#Contractions |
| 218 | for (let i = start; i < codePoints.length; i++) { |
| 219 | node = node.next?.[codePoints[i]] |
| 220 | if (!node) { |
| 221 | break |
| 222 | } |
| 223 | if (node.value !== undefined) { |
| 224 | matchedElements = rootElements[node.value] |
| 225 | matchedLength = i - start + 1 |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return matchedElements |
| 230 | ? {elements: matchedElements, length: matchedLength} |
| 231 | : {elements: [fallbackElement(codePoints[start])], length: 1} |
| 232 | } |
| 233 | |
| 234 | function rootElementsForString(input: string): PackedCollationElement[] { |
| 235 | const codePoints = stringToCodePoints(input) |
no test coverage detected