mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 13:38:15 -08:00
chore: initial public commit
This commit is contained in:
commit
fc9054b78c
250 changed files with 32809 additions and 0 deletions
27
romanizer/romanizer.go
Normal file
27
romanizer/romanizer.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// unused
|
||||
package romanizer
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gosimple/unidecode"
|
||||
)
|
||||
|
||||
// regex to match only Latin letters, numbers, basic punctuation and spaces
|
||||
var latinCharset = regexp.MustCompile(`^[\p{Latin}\p{P}\p{N}\p{Zs}]+$`)
|
||||
|
||||
// Romanize returns a romanized version of the input string if it contains non-Latin characters.
|
||||
// If the input is already in Latin script, it returns an empty string.
|
||||
func Romanize(input string) string {
|
||||
trimmed := strings.TrimSpace(input)
|
||||
if trimmed == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if latinCharset.MatchString(trimmed) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimSpace(unidecode.Unidecode(trimmed))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue