Merge branch 'master' of git.zhangdeman.cn:zhangdeman/util
This commit is contained in:
15
string.go
15
string.go
@@ -13,6 +13,8 @@ import (
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/axgle/mahonia"
|
||||
)
|
||||
|
||||
// stringOperate ...
|
||||
@@ -97,3 +99,16 @@ func (s *stringOperate) SnakeCaseToCamel(str string) string {
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Convert 字符串编码转换
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:38 2022/7/9
|
||||
func (s *stringOperate) Convert(str string, sourceCode string, targetCode string) string {
|
||||
sourceCoder := mahonia.NewDecoder(sourceCode)
|
||||
sourceResult := sourceCoder.ConvertString(str)
|
||||
targetCoder := mahonia.NewDecoder(targetCode)
|
||||
_, cdata, _ := targetCoder.Translate([]byte(sourceResult), true)
|
||||
return string(cdata)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user