新增药品订单详情
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// MaskNameStr 用户名掩码
|
||||
func MaskNameStr(str string, maskType int) string {
|
||||
if str == "" {
|
||||
return str
|
||||
}
|
||||
|
||||
// 使用正则表达式判断是否包含中文字符
|
||||
chinesePattern := "[\u4e00-\u9fa5]+"
|
||||
isChinese, _ := regexp.MatchString(chinesePattern, str)
|
||||
|
||||
// 使用正则表达式判断是否包含英文字母
|
||||
englishPattern := "[A-Za-z]+"
|
||||
isEnglish, _ := regexp.MatchString(englishPattern, str)
|
||||
|
||||
// 判断是否包含中文字符
|
||||
if isChinese {
|
||||
// 按照中文字符计算长度
|
||||
strLen := utf8.RuneCountInString(str)
|
||||
|
||||
if strLen >= 3 {
|
||||
if maskType == 1 {
|
||||
// 三个字符或三个字符以上掐头取尾,中间用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
lastChar, _ := utf8.DecodeLastRuneInString(str)
|
||||
str = string(firstChar) + "*" + string(lastChar)
|
||||
} else {
|
||||
// 首字母保留,后两位用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "**"
|
||||
}
|
||||
} else if strLen == 2 {
|
||||
// 两个字符
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "*"
|
||||
}
|
||||
} else if isEnglish {
|
||||
// 按照英文字串计算长度
|
||||
strLen := utf8.RuneCountInString(str)
|
||||
|
||||
if strLen >= 3 {
|
||||
if maskType == 1 {
|
||||
// 三个字符或三个字符以上掐头取尾,中间用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
lastChar, _ := utf8.DecodeLastRuneInString(str)
|
||||
str = string(firstChar) + "*" + string(lastChar)
|
||||
} else {
|
||||
// 首字母保留,后两位用*代替
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "**"
|
||||
}
|
||||
} else if strLen == 2 {
|
||||
// 两个字符
|
||||
firstChar, _ := utf8.DecodeRuneInString(str)
|
||||
str = string(firstChar) + "*"
|
||||
}
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in New Issue
Block a user