Initial commit

This commit is contained in:
dennis 2023-08-18 23:54:06 +08:00
commit 35a7205d1c
2 changed files with 38 additions and 0 deletions

35
StringUtils.go Normal file
View File

@ -0,0 +1,35 @@
package golanghelper
import "strings"
const (
EMPTY = ""
SPACE = " "
)
type StringUtils struct {
}
// IsEmpty 會檢查 str 是否為空值
func (s *StringUtils) IsEmpty(str string) bool {
return len(str) == 0
}
// LeftPad 將 padStr 以 size 做為長度,向左填滿 str
func (s *StringUtils) LeftPad(str string, size int, padStr string) string {
if s.IsEmpty(padStr) {
padStr = SPACE
}
padStrLen := len(padStr)
padCount := size - len(str)
if padCount <= 0 || padCount < padStrLen {
return str
}
if padCount == padStrLen {
return padStr + str
}
return strings.Repeat(padStr, padCount) + str
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitlab-ce.niaulang.com/niau-lang/golanghelper
go 1.20