MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / normalizeUnicode

Function normalizeUnicode

src/core/tools/apply-patch/seek-sequence.ts:12–36  ·  view source on GitHub ↗

* Normalize common Unicode punctuation to ASCII equivalents. * This allows patches written with plain ASCII to match source files * containing typographic characters.

(s: string)

Source from the content-addressed store, hash-verified

10 * containing typographic characters.
11 */
12function normalizeUnicode(s: string): string {
13 return s
14 .trim()
15 .split("")
16 .map((c) => {
17 // Various dash/hyphen code-points → ASCII '-'
18 if ("\u2010\u2011\u2012\u2013\u2014\u2015\u2212".includes(c)) {
19 return "-"
20 }
21 // Fancy single quotes → '\''
22 if ("\u2018\u2019\u201A\u201B".includes(c)) {
23 return "'"
24 }
25 // Fancy double quotes → '"'
26 if ("\u201C\u201D\u201E\u201F".includes(c)) {
27 return '"'
28 }
29 // Non-breaking space and other odd spaces → normal space
30 if ("\u00A0\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000".includes(c)) {
31 return " "
32 }
33 return c
34 })
35 .join("")
36}
37
38/**
39 * Check if two arrays of lines match exactly.

Callers 1

normalizedMatchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected