* Normalize common Unicode punctuation to ASCII equivalents. * This allows patches written with plain ASCII to match source files * containing typographic characters.
(s: string)
| 10 | * containing typographic characters. |
| 11 | */ |
| 12 | function 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. |