refactor & format code (#255)

This commit is contained in:
Kevin Wan
2020-12-08 23:01:25 +08:00
committed by GitHub
parent b060867009
commit 65ee877236
10 changed files with 33 additions and 35 deletions

View File

@@ -6,11 +6,9 @@ import (
"unicode"
)
type (
String struct {
source string
}
)
type String struct {
source string
}
func From(data string) String {
return String{source: data}
@@ -30,8 +28,12 @@ func (s String) Lower() string {
return strings.ToLower(s.source)
}
func (s String) Upper() string {
return strings.ToUpper(s.source)
func (s String) ReplaceAll(old, new string) string {
return strings.ReplaceAll(s.source, old, new)
}
func (s String) Source() string {
return s.source
}
func (s String) Title() string {
@@ -64,7 +66,7 @@ func (s String) ToSnake() string {
}
// return original string if rune is not letter at index 0
func (s String) UnTitle() string {
func (s String) Untitle() string {
if s.IsEmptyOrSpace() {
return s.source
}
@@ -75,6 +77,10 @@ func (s String) UnTitle() string {
return string(unicode.ToLower(r)) + s.source[1:]
}
func (s String) Upper() string {
return strings.ToUpper(s.source)
}
// it will not ignore spaces
func (s String) splitBy(fn func(r rune) bool, remove bool) []string {
if s.IsEmptyOrSpace() {
@@ -100,11 +106,3 @@ func (s String) splitBy(fn func(r rune) bool, remove bool) []string {
}
return list
}
func (s String) ReplaceAll(old, new string) string {
return strings.ReplaceAll(s.source, old, new)
}
func (s String) Source() string {
return s.source
}