-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.go
51 lines (40 loc) · 782 Bytes
/
text.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package timist
import "strings"
type Text struct {
s string
}
func NewText(s string) *Text {
return &Text{
s: s,
}
}
func (txt *Text) Lowercase() *Text {
txt.s = strings.ToLower(txt.s)
return txt
}
func (txt *Text) Uppercase() *Text {
txt.s = strings.ToUpper(txt.s)
return txt
}
func (txt *Text) Capitalize() *Text {
str := strings.ToLower(txt.s)
newStr := []byte(str)
upStr := strings.ToUpper(txt.s)
upStrBytes := []byte(upStr)
caps := false
for i := 0; i < len(str); i++ {
if i == 0 || str[i] == ' ' {
caps = true
}
if (str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z') &&
caps {
newStr[i] = upStrBytes[i]
caps = false
}
}
txt.s = string(newStr)
return txt
}
func (txt *Text) GetString() string {
return txt.s
}