- LimitUTF8StringLen
This commit is contained in:
@@ -246,3 +246,24 @@ func Base64DecodeMultiString(strs ...string) (decodedData [][]byte, err error) {
|
||||
}
|
||||
return decodedData, nil
|
||||
}
|
||||
|
||||
func LimitStringLen(str string, maxLen int) (limitedStr string) {
|
||||
if maxLen > 0 {
|
||||
if strLen := len(str); strLen > maxLen {
|
||||
str = str[:maxLen]
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func LimitUTF8StringLen(str string, maxLen int) (limitedStr string) {
|
||||
if maxLen > 0 {
|
||||
if len(str) > maxLen {
|
||||
runeList := []rune(str)
|
||||
if len(runeList) > maxLen {
|
||||
str = string(runeList[:maxLen])
|
||||
}
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user