- LimitUTF8StringLen

This commit is contained in:
gazebo
2019-03-31 12:13:47 +08:00
parent 12781c14be
commit d2fafe5ec0
4 changed files with 3 additions and 18 deletions

View File

@@ -279,13 +279,7 @@ func ComposeSpuName(prefix, name string, maxLen int) (spuName string) {
spuName = "[" + prefix + "]"
}
spuName += name
if maxLen > 0 {
runeList := []rune(spuName)
if len(runeList) > maxLen {
spuName = string(runeList[:maxLen])
}
}
return spuName
return utils.LimitUTF8StringLen(spuName, maxLen)
}
func ComposeSkuSpec(spec_quality float32, spec_unit string) (spec string) {

View File

@@ -311,12 +311,3 @@ func AddVendorInfo2Err(inErr error, vendorID int) (outErr error) {
}
return outErr
}
func LimitStringLen(str string, maxLen int) (limitedStr string) {
if maxLen > 0 {
if strLen := len(str); strLen > maxLen {
str = str[:maxLen]
}
}
return str
}