remove unused "uppercase" param of appendTransliterate(), improve readability (#172)
This commit is contained in:
parent
4c6241ca42
commit
34f39f90b2
@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var normMap map[rune]rune
|
var normMap map[rune]rune
|
||||||
@ -14,19 +14,17 @@ func init() {
|
|||||||
appendTransliterate(
|
appendTransliterate(
|
||||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vietnamese
|
// Vietnamese
|
||||||
appendTransliterate(
|
appendTransliterate(
|
||||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendTransliterate(base, norm string, uppercase bool) {
|
func appendTransliterate(base, norm string) {
|
||||||
normRunes := []rune(norm)
|
normRunes := []rune(norm)
|
||||||
baseRunes := []rune(base)
|
baseRunes := []rune(base)
|
||||||
|
|
||||||
@ -36,24 +34,20 @@ func appendTransliterate(base, norm string, uppercase bool) {
|
|||||||
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, baseRune := range baseRunes {
|
for i := 0; i < lenBase; i++ {
|
||||||
normMap[baseRune] = normRunes[i]
|
normMap[baseRunes[i]] = normRunes[i]
|
||||||
}
|
|
||||||
|
|
||||||
if uppercase {
|
baseUpper := unicode.ToUpper(baseRunes[i])
|
||||||
upperBase := strings.ToUpper(base)
|
normUpper := unicode.ToUpper(normRunes[i])
|
||||||
upperNorm := strings.ToUpper(norm)
|
|
||||||
normRune := []rune(upperNorm)
|
normMap[baseUpper] = normUpper
|
||||||
for i, baseRune := range []rune(upperBase) {
|
|
||||||
normMap[baseRune] = normRune[i]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove diacritics and make lowercase.
|
// Remove diacritics and make lowercase.
|
||||||
func removeDiacritics(baseString string) string {
|
func removeDiacritics(baseString string) string {
|
||||||
var normalizedRunes []rune
|
var normalizedRunes []rune
|
||||||
for _, baseRune := range []rune(baseString) {
|
for _, baseRune := range baseString {
|
||||||
if normRune, ok := normMap[baseRune]; ok {
|
if normRune, ok := normMap[baseRune]; ok {
|
||||||
normalizedRunes = append(normalizedRunes, normRune)
|
normalizedRunes = append(normalizedRunes, normRune)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user