当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

Simbory / mego
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Simbory 提交于 2020-02-09 23:51 . 添加gzip压缩
package mego
import (
"log"
"os"
"path"
"path/filepath"
"strings"
"unsafe"
)
// Bytes2Str convert the byte array to string quickly
func Bytes2Str(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
// Str2Bytes convert the string to byte array quickly
func Str2Bytes(s string) []byte {
x := (*[2]uintptr)(unsafe.Pointer(&s))
h := [3]uintptr{x[0], x[1], x[1]}
return *(*[]byte)(unsafe.Pointer(&h))
}
// StrJoin combine some strings to a single string
func StrJoin(arr ...string) string {
if len(arr) == 0 {
return ""
}
return strings.Join(arr, "")
}
// ClearFilePath clear the pathStr and return the shortest path.
func ClearFilePath(pathStr string) string {
return path.Clean(strings.Replace(pathStr, "\\", "/", -1))
}
// GetExeDir get the current directory that the executable file is located in.
func GetExeDir() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return dir
}
// GetWD get the current working directory
func GetWD() string {
str, err := os.Getwd()
panicErr(err)
return str
}
func isA2Z(c byte) bool {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
}
func isNumber(c byte) bool {
return c >= '0' && c <= '9'
}
func ensurePostFix(str, postFix string) string {
if strings.HasSuffix(str, postFix) {
return str
}
return StrJoin(str, postFix)
}
Go
1
https://gitee.com/simbory/mego.git
git@gitee.com:simbory/mego.git
simbory
mego
mego
v1.1.1

搜索帮助