mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
Use unicode compat slug engine
This commit is contained in:
parent
91c8b05d89
commit
123fce6c17
18 changed files with 48504 additions and 678 deletions
71
vendor/github.com/rainycape/unidecode/make_table.go
generated
vendored
Normal file
71
vendor/github.com/rainycape/unidecode/make_table.go
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
// +build none
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data, err := ioutil.ReadFile("table.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.HasPrefix(line, "/*") || line == "" {
|
||||
continue
|
||||
}
|
||||
sep := strings.IndexByte(line, ':')
|
||||
if sep == -1 {
|
||||
panic(line)
|
||||
}
|
||||
val, err := strconv.ParseInt(line[:sep], 0, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s, err := strconv.Unquote(line[sep+2:])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
if err := binary.Write(&buf, binary.LittleEndian, uint16(val)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := binary.Write(&buf, binary.LittleEndian, uint8(len(s))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
buf.WriteString(s)
|
||||
}
|
||||
var cbuf bytes.Buffer
|
||||
w, err := zlib.NewWriterLevel(&cbuf, zlib.BestCompression)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if _, err := w.Write(buf.Bytes()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
buf.Reset()
|
||||
buf.WriteString("package unidecode\n")
|
||||
buf.WriteString("// AUTOGENERATED - DO NOT EDIT!\n\n")
|
||||
fmt.Fprintf(&buf, "var tableData = %q;\n", cbuf.String())
|
||||
dst, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := ioutil.WriteFile("table.go", dst, 0644); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue