aboutsummaryrefslogtreecommitdiff
path: root/internal/norm/norm.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:30:59 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-15 00:30:59 +0200
commit2f4e6dd8dfc7e18064e087c65ff9d28b4833cce2 (patch)
tree7ebcbec83f0f6ee41d8541bfbcff18eba7af10fa /internal/norm/norm.go
parent17e933a16ff7de1b06d62504e78c40e615c8b553 (diff)
downloadkrino-2f4e6dd8dfc7e18064e087c65ff9d28b4833cce2.tar.gz
krino-2f4e6dd8dfc7e18064e087c65ff9d28b4833cce2.zip
captures keep the combining marks of a decomposed name; test sources escape invisible characters
Diffstat (limited to 'internal/norm/norm.go')
-rw-r--r--internal/norm/norm.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/internal/norm/norm.go b/internal/norm/norm.go
index bff2127..1c2f61d 100644
--- a/internal/norm/norm.go
+++ b/internal/norm/norm.go
@@ -123,7 +123,9 @@ func FoldMapped(s string) Folded {
}
// Source returns the original text that Text[a:b] was folded from, widened
-// to whole characters; without a map, Text[a:b] itself.
+// to whole characters and to the characters right after them that fold to
+// nothing - the combining marks of a decomposed name, which belong to the
+// letter before them (plan 11 review L5); without a map, Text[a:b] itself.
func (f Folded) Source(a, b int) string {
switch {
case f.same || f.start == nil:
@@ -131,7 +133,15 @@ func (f Folded) Source(a, b int) string {
case a >= b:
return ""
}
- return f.src[f.start[a]:f.end[b-1]]
+ end := f.end[b-1]
+ for end < len(f.src) {
+ r, w := utf8.DecodeRuneInString(f.src[end:])
+ if r == utf8.RuneError && w == 1 || Fold(f.src[end:end+w]) != "" {
+ break
+ }
+ end += w
+ }
+ return f.src[f.start[a]:end]
}
// Text puts s into the form content and keywords are compared in: Fold if