(str: string)
| 96 | } |
| 97 | |
| 98 | function* segmentPrintableGraphemes(str: string): Generator<Grapheme> { |
| 99 | // Long-history transcript output is overwhelmingly ASCII source text. |
| 100 | // Bypass Intl.Segmenter on that path: every code unit is already one |
| 101 | // grapheme of width 1, and the fallback path still handles emoji / wide |
| 102 | // / multi-codepoint clusters exactly as before. |
| 103 | let asciiOnly = true |
| 104 | for (let index = 0; index < str.length; index++) { |
| 105 | if (str.charCodeAt(index) > 0x7f) { |
| 106 | asciiOnly = false |
| 107 | break |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (asciiOnly) { |
| 112 | for (let index = 0; index < str.length; index++) { |
| 113 | yield { value: str[index]!, width: 1 } |
| 114 | } |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | for (const { segment } of getGraphemeSegmenter().segment(str)) { |
| 119 | yield { value: segment, width: graphemeWidth(segment) } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // ============================================================================= |
| 124 | // Sequence Parsing |
no test coverage detected