1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-14 02:12:42 +00:00
mondash/vendor/github.com/rainycape/unidecode/unidecode.go
Knut Ahlers f3c31476b4
Major: Rework frontend, API and improve code quality (#5)
* Update dependencies
* Improve code quality
* Apply linter advices
* Add gzip compression to all requests
* Rework frontend
* Apply bootswatch theme
* Hide historic details when not requested
* Remove debugging header
* Apply auto-migration of meta fields
* Fix broken "last update" time
* Pre-sort metrics for frontend / API
* Add tooltip with absolute time
* Some design fixes
* Add tooltip with absolute date to last ok
* Implement filters
* Apply eslint --fix
* Remove unused var
* Remove remains of old template engine
* Update baked in assets
* Update Dockerfile for new version

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-05-25 00:03:06 +02:00

58 lines
1.2 KiB
Go

// Package unidecode implements a unicode transliterator
// which replaces non-ASCII characters with their ASCII
// approximations.
package unidecode
//go:generate go run make_table.go
import (
"sync"
"unicode"
)
const pooledCapacity = 64
var (
slicePool sync.Pool
decodingOnce sync.Once
)
// Unidecode implements a unicode transliterator, which
// replaces non-ASCII characters with their ASCII
// counterparts.
// Given an unicode encoded string, returns
// another string with non-ASCII characters replaced
// with their closest ASCII counterparts.
// e.g. Unicode("áéíóú") => "aeiou"
func Unidecode(s string) string {
decodingOnce.Do(decodeTransliterations)
l := len(s)
var r []rune
if l > pooledCapacity {
r = make([]rune, 0, len(s))
} else {
if x := slicePool.Get(); x != nil {
r = x.([]rune)[:0]
} else {
r = make([]rune, 0, pooledCapacity)
}
}
for _, c := range s {
if c <= unicode.MaxASCII {
r = append(r, c)
continue
}
if c > unicode.MaxRune || c > transCount {
/* Ignore reserved chars */
continue
}
if d := transliterations[c]; d != nil {
r = append(r, d...)
}
}
res := string(r)
if l <= pooledCapacity {
slicePool.Put(r)
}
return res
}