Changeset 498 in code for trunk/upstream.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/upstream.go

    r489 r498  
    1414        "strings"
    1515        "time"
    16         "unicode"
    17         "unicode/utf8"
    1816
    1917        "github.com/emersion/go-sasl"
     
    314312        }
    315313        return &memberships, s[i:]
    316 }
    317 
    318 func isWordBoundary(r rune) bool {
    319         switch r {
    320         case '-', '_', '|':
    321                 return false
    322         case '\u00A0':
    323                 return true
    324         default:
    325                 return !unicode.IsLetter(r) && !unicode.IsNumber(r)
    326         }
    327 }
    328 
    329 func isHighlight(text, nick string) bool {
    330         for {
    331                 i := strings.Index(text, nick)
    332                 if i < 0 {
    333                         return false
    334                 }
    335 
    336                 // Detect word boundaries
    337                 var left, right rune
    338                 if i > 0 {
    339                         left, _ = utf8.DecodeLastRuneInString(text[:i])
    340                 }
    341                 if i < len(text) {
    342                         right, _ = utf8.DecodeRuneInString(text[i+len(nick):])
    343                 }
    344                 if isWordBoundary(left) && isWordBoundary(right) {
    345                         return true
    346                 }
    347 
    348                 text = text[i+len(nick):]
    349         }
    350314}
    351315
Note: See TracChangeset for help on using the changeset viewer.