irc: simplify isHighlight
This commit is contained in:
parent
6033725eca
commit
379e07f7d8
14
irc.go
14
irc.go
@ -681,10 +681,8 @@ func (cm *monitorCasemapMap) Value(name string) (online bool) {
|
|||||||
|
|
||||||
func isWordBoundary(r rune) bool {
|
func isWordBoundary(r rune) bool {
|
||||||
switch r {
|
switch r {
|
||||||
case '-', '_', '|':
|
case '-', '_', '|': // inspired from weechat.look.highlight_regex
|
||||||
return false
|
return false
|
||||||
case '\u00A0':
|
|
||||||
return true
|
|
||||||
default:
|
default:
|
||||||
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
|
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
|
||||||
}
|
}
|
||||||
@ -697,14 +695,8 @@ func isHighlight(text, nick string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect word boundaries
|
left, _ := utf8.DecodeLastRuneInString(text[:i])
|
||||||
var left, right rune
|
right, _ := utf8.DecodeRuneInString(text[i+len(nick):])
|
||||||
if i > 0 {
|
|
||||||
left, _ = utf8.DecodeLastRuneInString(text[:i])
|
|
||||||
}
|
|
||||||
if i < len(text) {
|
|
||||||
right, _ = utf8.DecodeRuneInString(text[i+len(nick):])
|
|
||||||
}
|
|
||||||
if isWordBoundary(left) && isWordBoundary(right) {
|
if isWordBoundary(left) && isWordBoundary(right) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user