(text: string, numUtf8Bytes?: number)
| 38 | } |
| 39 | |
| 40 | export function numUtf8BytesToNumCodeUnits(text: string, numUtf8Bytes?: number): number { |
| 41 | if (numUtf8Bytes === 0) { |
| 42 | return 0; |
| 43 | } |
| 44 | let curNumCodeUnits = 0; |
| 45 | let curNumUtf8Bytes = 0; |
| 46 | for (const codePoint of text) { |
| 47 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 48 | curNumUtf8Bytes += numUtf8BytesForCodePoint(codePoint.codePointAt(0)!); |
| 49 | curNumCodeUnits += codePoint.length; |
| 50 | if (numUtf8Bytes !== undefined && curNumUtf8Bytes >= numUtf8Bytes) { |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | return curNumCodeUnits; |
| 55 | } |
no test coverage detected