forked from External/ergo
upgrade to irc-go v0.4.0
This commit is contained in:
parent
d14ff9b3d5
commit
ad3ad97047
9 changed files with 178 additions and 82 deletions
19
vendor/github.com/ergochat/irc-go/ircutils/unicode.go
generated
vendored
19
vendor/github.com/ergochat/irc-go/ircutils/unicode.go
generated
vendored
|
|
@ -7,24 +7,11 @@ import (
|
|||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/ergochat/irc-go/ircmsg"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
var TruncateUTF8Safe = ircmsg.TruncateUTF8Safe
|
||||
|
||||
// Sanitizes human-readable text to make it safe for IRC;
|
||||
// assumes UTF-8 and uses the replacement character where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue