mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 10:10:08 -08:00
bump irc-go to include new ircutils function
This commit is contained in:
parent
e447c61c73
commit
074a5a077e
7 changed files with 136 additions and 2 deletions
25
vendor/github.com/goshuirc/irc-go/ircutils/unicode.go
generated
vendored
Normal file
25
vendor/github.com/goshuirc/irc-go/ircutils/unicode.go
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2021 Shivaram Lingamneni
|
||||
// Released under the MIT License
|
||||
|
||||
package ircutils
|
||||
|
||||
import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// truncate a message, taking care not to make valid UTF8 into invalid UTF8
|
||||
func TruncateUTF8Safe(message string, byteLimit int) (result string) {
|
||||
if len(message) <= byteLimit {
|
||||
return message
|
||||
}
|
||||
message = message[:byteLimit]
|
||||
for i := 0; i < (utf8.UTFMax - 1); i++ {
|
||||
r, n := utf8.DecodeLastRuneInString(message)
|
||||
if r == utf8.RuneError && n <= 1 {
|
||||
message = message[:len(message)-1]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue