MCPcopy Index your code
hub / github.com/formatjs/formatjs / lookupRootElements

Function lookupRootElements

packages/intl-collator/compare.ts:202–232  ·  view source on GitHub ↗
(
  codePoints: readonly number[],
  start: number
)

Source from the content-addressed store, hash-verified

200}
201
202function 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
234function rootElementsForString(input: string): PackedCollationElement[] {
235 const codePoints = stringToCodePoints(input)

Callers 2

rootElementsForStringFunction · 0.85
collationElementsFunction · 0.85

Calls 2

lookupPrefixElementsFunction · 0.85
fallbackElementFunction · 0.85

Tested by

no test coverage detected