Merge branch 'master' of git.zhangdeman.cn:zhangdeman/util

This commit is contained in:
2022-07-12 20:12:06 +08:00
3 changed files with 33 additions and 3 deletions

View File

@@ -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)
}