MCPcopy Create free account
hub / github.com/Noumena-Network/code / segmentPrintableGraphemes

Function segmentPrintableGraphemes

src/ink/termio/parser.ts:98–121  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

96}
97
98function* 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

Callers 1

segmentGraphemesFunction · 0.85

Calls 3

getGraphemeSegmenterFunction · 0.85
graphemeWidthFunction · 0.85
segmentMethod · 0.80

Tested by

no test coverage detected