diff options
| author | Jonas Knobloch <jonas.knobloch@t-online.de> | 2026-03-24 20:44:23 +0100 |
|---|---|---|
| committer | Jonas Knobloch <jonas.knobloch@t-online.de> | 2026-03-24 20:44:23 +0100 |
| commit | 87bbece7e0400af29c52e34ebb794d74498d13a9 (patch) | |
| tree | ae9035ce9fd9c20cb8f5ebb8f2dd3e8d20b5acdb /tokenizer/bpe/split/fsa.go | |
| parent | 8079a927dcb69e8046a9187a73d1e2d8da2307f9 (diff) | |
Preserve per-byte error replacements
Diffstat (limited to 'tokenizer/bpe/split/fsa.go')
| -rw-r--r-- | tokenizer/bpe/split/fsa.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tokenizer/bpe/split/fsa.go b/tokenizer/bpe/split/fsa.go index a0c4cd1..b85254b 100644 --- a/tokenizer/bpe/split/fsa.go +++ b/tokenizer/bpe/split/fsa.go @@ -155,6 +155,13 @@ func (f *FSA) Read(next rune) bool { } func (f *FSA) FindAll(s string) []string { + if !utf8.ValidString(s) { + // s = strings.ToValidUTF8(s, string(utf8.RuneError)) replaces with a single utf8.RuneError + // s = strings.Map(func(r rune) rune { return r }, s) should be identical to s = string([]rune(s)) + + s = string([]rune(s)) // replaces each invalid byte with utf8.RuneError during decoding + } + var findAll func(start int, matches []string) []string findAll = func(start int, matches []string) []string { |
