Changeset 498 in code for trunk/irc.go


Ignore:
Timestamp:
Apr 13, 2021, 4:54:58 PM (4 years ago)
Author:
contact
Message:

Move isHighlight to irc.go

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/irc.go

    r492 r498  
    55        "sort"
    66        "strings"
     7        "unicode"
     8        "unicode/utf8"
    79
    810        "gopkg.in/irc.v3"
     
    602604        return entry.value.(deliveredClientMap)
    603605}
     606
     607func isWordBoundary(r rune) bool {
     608        switch r {
     609        case '-', '_', '|':
     610                return false
     611        case '\u00A0':
     612                return true
     613        default:
     614                return !unicode.IsLetter(r) && !unicode.IsNumber(r)
     615        }
     616}
     617
     618func isHighlight(text, nick string) bool {
     619        for {
     620                i := strings.Index(text, nick)
     621                if i < 0 {
     622                        return false
     623                }
     624
     625                // Detect word boundaries
     626                var left, right rune
     627                if i > 0 {
     628                        left, _ = utf8.DecodeLastRuneInString(text[:i])
     629                }
     630                if i < len(text) {
     631                        right, _ = utf8.DecodeRuneInString(text[i+len(nick):])
     632                }
     633                if isWordBoundary(left) && isWordBoundary(right) {
     634                        return true
     635                }
     636
     637                text = text[i+len(nick):]
     638        }
     639}
Note: See TracChangeset for help on using the changeset viewer.