Select protected spelling findings without sorting

This commit is contained in:
2026-11-11 12:31:44 +00:00
parent 04e0c2f913
commit 73ef2c6083
2 changed files with 18 additions and 11 deletions

View File

@@ -96,35 +96,40 @@ func (v ProtectedVocabulary) occurrences(text string) []protectedOccurrence {
}
func validateIdentityPreservation(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string {
var spellings []string
var selected string
found := false
for identity, beforeItems := range beforeByID {
if len(afterByID[identity]) < len(beforeItems) && len(beforeItems) > 0 {
spellings = append(spellings, beforeItems[0].canonical)
if spelling := beforeItems[0].canonical; !found || spelling < selected {
selected, found = spelling, true
}
}
}
return protectedSpellingMessage(spellings)
return protectedSpellingMessage(selected, found)
}
func validateCapitalizationTransitions(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string {
var spellings []string
var selected string
found := false
for identity, afterItems := range afterByID {
beforeItems := beforeByID[identity]
for i, afterItem := range afterItems {
if i >= len(beforeItems) || afterItem.text == beforeItems[i].text || afterItem.text == afterItem.canonical {
continue
}
spellings = append(spellings, afterItem.canonical)
if !found || afterItem.canonical < selected {
selected, found = afterItem.canonical, true
}
}
}
return protectedSpellingMessage(spellings)
return protectedSpellingMessage(selected, found)
}
func protectedSpellingMessage(spellings []string) string {
if len(spellings) == 0 {
func protectedSpellingMessage(spelling string, found bool) string {
if !found {
return ""
}
sort.Strings(spellings)
return fmt.Sprintf("proposal may alter protected glossary spelling %q", spellings[0])
return fmt.Sprintf("proposal may alter protected glossary spelling %q", spelling)
}
// preservesRepeatedIdentities permits a spoken-word proposal to reduce repeated