mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 16:04:38 +01:00
remove unused code
This commit is contained in:
@@ -2,62 +2,14 @@ package stringsupport
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/text/encoding"
|
|
||||||
"golang.org/x/text/encoding/japanese"
|
"golang.org/x/text/encoding/japanese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StringConverter is a small helper for encoding/decoding strings.
|
|
||||||
type StringConverter struct {
|
|
||||||
Encoding encoding.Encoding
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode decodes the given bytes as the set encoding.
|
|
||||||
func (sc *StringConverter) Decode(data []byte) (string, error) {
|
|
||||||
decoded, err := ioutil.ReadAll(transform.NewReader(bytes.NewBuffer(data), sc.Encoding.NewDecoder()))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(decoded), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustDecode decodes the given bytes as the set encoding. Panics on decode failure.
|
|
||||||
func (sc *StringConverter) MustDecode(data []byte) string {
|
|
||||||
decoded, err := sc.Decode(data)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return decoded
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode encodes the given string as the set encoding.
|
|
||||||
func (sc *StringConverter) Encode(data string) ([]byte, error) {
|
|
||||||
encoded, err := ioutil.ReadAll(transform.NewReader(bytes.NewBuffer([]byte(data)), sc.Encoding.NewEncoder()))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoded, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustEncode encodes the given string as the set encoding. Panics on encode failure.
|
|
||||||
func (sc *StringConverter) MustEncode(data string) []byte {
|
|
||||||
encoded, err := sc.Encode(data)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoded
|
|
||||||
}
|
|
||||||
|
|
||||||
func UTF8ToSJIS(x string) []byte {
|
func UTF8ToSJIS(x string) []byte {
|
||||||
e := japanese.ShiftJIS.NewEncoder()
|
e := japanese.ShiftJIS.NewEncoder()
|
||||||
xt, _, err := transform.String(e, x)
|
xt, _, err := transform.String(e, x)
|
||||||
@@ -69,7 +21,7 @@ func UTF8ToSJIS(x string) []byte {
|
|||||||
|
|
||||||
func SJISToUTF8(b []byte) string {
|
func SJISToUTF8(b []byte) string {
|
||||||
d := japanese.ShiftJIS.NewDecoder()
|
d := japanese.ShiftJIS.NewDecoder()
|
||||||
result, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(b), d))
|
result, err := io.ReadAll(transform.NewReader(bytes.NewReader(b), d))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user