// 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 ( ) 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 ( string) string { decodingOnce.Do(decodeTransliterations) := len() var []rune if > pooledCapacity { = make([]rune, 0, len()) } else { if := slicePool.Get(); != nil { = .([]rune)[:0] } else { = make([]rune, 0, pooledCapacity) } } for , := range { if <= unicode.MaxASCII { = append(, ) continue } if > unicode.MaxRune || >= transCount { /* Ignore reserved chars */ continue } if := transliterations[]; != nil { = append(, ...) } } := string() if <= pooledCapacity { slicePool.Put() } return }