MCPcopy Create free account
hub / github.com/Exafunction/codeium-chrome / numCodeUnitsToNumUtf8Bytes

Function numCodeUnitsToNumUtf8Bytes

src/utf.ts:22–38  ·  view source on GitHub ↗
(text: string, numCodeUnits?: number)

Source from the content-addressed store, hash-verified

20 * @returns The number of bytes.
21 */
22export function numCodeUnitsToNumUtf8Bytes(text: string, numCodeUnits?: number): number {
23 if (numCodeUnits === 0) {
24 return 0;
25 }
26 let curNumUtf8Bytes = 0;
27 let curNumCodeUnits = 0;
28 for (const codePoint of text) {
29 curNumCodeUnits += codePoint.length;
30 // TODO(prem): Is the ! safe here?
31 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
32 curNumUtf8Bytes += numUtf8BytesForCodePoint(codePoint.codePointAt(0)!);
33 if (numCodeUnits !== undefined && curNumCodeUnits >= numCodeUnits) {
34 break;
35 }
36 }
37 return curNumUtf8Bytes;
38}
39
40export function numUtf8BytesToNumCodeUnits(text: string, numUtf8Bytes?: number): number {
41 if (numUtf8Bytes === 0) {

Callers 1

computeTextAndOffsetsFunction · 0.90

Calls 1

numUtf8BytesForCodePointFunction · 0.85

Tested by

no test coverage detected