From 8387dd440052ef434c7147dd6c03c9b683857d84 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 30 Jul 2023 21:01:45 -0400 Subject: [PATCH] mixed case hashtag complicates things a bit --- honk.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/honk.go b/honk.go index 80b3584..daf6526 100644 --- a/honk.go +++ b/honk.go @@ -145,8 +145,29 @@ func (mention *Mention) IsPresent(noise string) bool { } func OntIsPresent(ont, noise string) bool { - ont = ont[1:] - return strings.Contains(noise, ">#"+ont) || strings.Contains(noise, "#"+ont) + ont = strings.ToLower(ont[1:] + "<") + idx := strings.IndexByte(noise, '#') + for idx >= 0 { + if strings.HasPrefix(noise[idx:], "#") { + idx += 5 + } else { + idx += 1 + } + if idx + len(ont) + 1 > len(noise) { + return false + } + test := noise[idx:idx+len(ont)] + test = strings.ToLower(test) + if test == ont { + return true + } + newidx := strings.IndexByte(noise[idx:], '#') + if newidx == -1 { + return false + } + idx += newidx + } + return false } type OldRevision struct {