Switch to crc32 as TOML cannot encode MaxUint64
This commit is contained in:
parent
928b5e8bab
commit
9442934541
@ -1,8 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"hash/crc64"
|
||||
"io"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
@ -28,17 +27,8 @@ func genIDCmd(c *cli.Context) error {
|
||||
}
|
||||
fl.Close()
|
||||
|
||||
hash := crc64.New(crc64.MakeTable(crc64.ISO))
|
||||
|
||||
for i, item := range tr.Items {
|
||||
hash.Reset()
|
||||
|
||||
_, err := io.WriteString(hash, item.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tr.Items[i].ID = hash.Sum64()
|
||||
tr.Items[i].ID = crc32.ChecksumIEEE([]byte(item.Value))
|
||||
}
|
||||
|
||||
fl, err = os.Create(c.Args().First())
|
||||
|
16
translate.go
16
translate.go
@ -1,8 +1,7 @@
|
||||
package translate
|
||||
|
||||
import (
|
||||
"hash/crc64"
|
||||
"io"
|
||||
"hash/crc32"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -17,11 +16,11 @@ type Translations struct {
|
||||
}
|
||||
|
||||
type Translation struct {
|
||||
ID uint64 `toml:"id"`
|
||||
ID uint32 `toml:"id"`
|
||||
Value string `toml:"value"`
|
||||
}
|
||||
|
||||
type Dictionary map[uint64]string
|
||||
type Dictionary map[uint32]string
|
||||
type Catalog map[language.Tag]Dictionary
|
||||
|
||||
type Translator struct {
|
||||
@ -107,11 +106,6 @@ func toDict(tr Translations) Dictionary {
|
||||
return out
|
||||
}
|
||||
|
||||
func hashString(s string) uint64 {
|
||||
hash := crc64.New(crc64.MakeTable(crc64.ISO))
|
||||
_, err := io.WriteString(hash, s)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return hash.Sum64()
|
||||
func hashString(s string) uint32 {
|
||||
return crc32.ChecksumIEEE([]byte(s))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user