Harden item occurrence grounding
This commit is contained in:
28
internal/modules/dnd/shared/text_comparison.go
Normal file
28
internal/modules/dnd/shared/text_comparison.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
// TextComparisonPolicy identifies the shared D&D text-comparison semantics.
|
||||
// A semantic change requires a new value and a review of every dependent
|
||||
// identity, mapping, normalization, and validator policy.
|
||||
const TextComparisonPolicy = "dnd.text_comparison.v1"
|
||||
|
||||
// ComparisonKey returns the D&D Unicode- and case-insensitive comparison key.
|
||||
func ComparisonKey(value string) string {
|
||||
value = norm.NFKC.String(value)
|
||||
value = strings.Map(func(r rune) rune {
|
||||
switch r {
|
||||
case '\u2018', '\u2019', '\u02bc':
|
||||
return '\''
|
||||
default:
|
||||
return r
|
||||
}
|
||||
}, value)
|
||||
value = strings.Join(strings.Fields(value), " ")
|
||||
return cases.Fold().String(value)
|
||||
}
|
||||
Reference in New Issue
Block a user