forked from mtusi2026/mtusi2026lab2
23 lines
396 B
Go
23 lines
396 B
Go
package db
|
|
|
|
import "strings"
|
|
|
|
var (
|
|
textEncoder = strings.NewReplacer(`\`, `\\`, "\x00", `\0`)
|
|
textDecoder = strings.NewReplacer(`\\`, `\`, `\0`, "\x00")
|
|
)
|
|
|
|
func encodeText(s string) string {
|
|
if !strings.ContainsAny(s, "\\\x00") {
|
|
return s
|
|
}
|
|
return textEncoder.Replace(s)
|
|
}
|
|
|
|
func decodeText(s string) string {
|
|
if !strings.Contains(s, `\`) {
|
|
return s
|
|
}
|
|
return textDecoder.Replace(s)
|
|
}
|