diff options
Diffstat (limited to 'internal/render/ascii.go')
| -rw-r--r-- | internal/render/ascii.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/render/ascii.go b/internal/render/ascii.go index 4203bc9..077a418 100644 --- a/internal/render/ascii.go +++ b/internal/render/ascii.go @@ -25,6 +25,26 @@ var asciiMap = map[rune]string{ '│': "|", } +// Transliterate maps non-ASCII characters to their ASCII equivalents where one +// is defined, leaving ASCII alone. For contexts that must not carry diacritics +// at all -- a generated filename, say -- where "Góra" should become "Gora" +// rather than losing the letter. +func Transliterate(s string) string { + var b strings.Builder + b.Grow(len(s)) + for _, r := range s { + switch { + case r < 128: + b.WriteRune(r) + default: + if sub, ok := asciiMap[r]; ok { + b.WriteString(sub) + } + } + } + return b.String() +} + // ASCII rewrites output to pure ASCII, one character for one character. // // The point is SMS: a single non-ASCII character forces the whole message from |
