mirror of
https://github.com/Luzifer/slugify.git
synced 2024-11-14 02:52:42 +00:00
41 lines
771 B
Go
41 lines
771 B
Go
package unidecode
|
|
|
|
import (
|
|
"compress/zlib"
|
|
"encoding/binary"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
transliterations [65536][]rune
|
|
transCount = rune(len(transliterations))
|
|
getUint16 = binary.LittleEndian.Uint16
|
|
)
|
|
|
|
func decodeTransliterations() {
|
|
r, err := zlib.NewReader(strings.NewReader(tableData))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer r.Close()
|
|
tmp1 := make([]byte, 2)
|
|
tmp2 := tmp1[:1]
|
|
for {
|
|
if _, err := io.ReadAtLeast(r, tmp1, 2); err != nil {
|
|
if err == io.EOF {
|
|
break
|
|
}
|
|
panic(err)
|
|
}
|
|
chr := getUint16(tmp1)
|
|
if _, err := io.ReadAtLeast(r, tmp2, 1); err != nil {
|
|
panic(err)
|
|
}
|
|
b := make([]byte, int(tmp2[0]))
|
|
if _, err := io.ReadFull(r, b); err != nil {
|
|
panic(err)
|
|
}
|
|
transliterations[int(chr)] = []rune(string(b))
|
|
}
|
|
}
|