This commit is contained in:
hitzhangjie 2025-06-20 15:37:06 -04:00 committed by GitHub
commit 03df2c6e27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -81,7 +81,7 @@ func marshalCorpusFile(vals ...any) []byte {
// We arbitrarily draw the line at UTF-8 validity, which biases toward the
// "rune" interpretation. (However, we accept either format as input.)
if utf8.ValidRune(t) {
fmt.Fprintf(b, "rune(%q)\n", t)
fmt.Fprintf(b, "int32(%v)/rune(%q)\n", t, t)
} else {
fmt.Fprintf(b, "int32(%v)\n", t)
}
@ -117,6 +117,12 @@ func unmarshalCorpusFile(b []byte) ([]any, error) {
if len(line) == 0 {
continue
}
if bytes.HasPrefix(line, []byte("int32")) ||
bytes.HasPrefix(line, []byte("rune")) {
if idx := bytes.IndexByte(line, '/'); idx != -1 {
line = line[:idx]
}
}
v, err := parseCorpusValue(line)
if err != nil {
return nil, fmt.Errorf("malformed line %q: %v", line, err)