-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapitalize.go
More file actions
104 lines (97 loc) · 2.02 KB
/
capitalize.go
File metadata and controls
104 lines (97 loc) · 2.02 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package piscine
func Capitalize(s string) string {
str := ""
newWord := true
for i := 0; i <= len(s)-1; i++ {
if newWord {
if isLetter(string(s[i])) {
if i >= 1 {
if isNumeric(string(s[i-1])) {
str += toLower(string(s[i]))
newWord = false
} else {
str += toUpper(string(s[i]))
newWord = false
}
} else {
str += toUpper(string(s[i]))
newWord = false
}
} else {
str += string(s[i])
}
} else if isLetter(string(s[i])) == false {
str += string(s[i])
newWord = true
} else if isUpper(string(s[i])) {
str += toLower(string(s[i]))
} else {
str += string(s[i])
}
}
return str
}
func isLetter(s string) bool {
array := []string{s}
for i := 0; i <= len(array[0])-1; i++ {
if rune(array[0][i]) < 65 {
return false
} else if rune(array[0][i]) > 90 && rune(array[0][i]) < 97 {
return false
} else if rune(array[0][i]) > 122 {
return false
}
}
return true
}
func toUpper(s string) string {
array := []string{s}
new_word := ""
for i := 0; i <= len(array[0])-1; i++ {
if isLower(string(array[0][i])) {
new_word += string(rune(array[0][i] - 32))
} else {
new_word += string(array[0][i])
}
}
return new_word
}
func isLower(s string) bool {
array := []string{s}
for i := 0; i <= len(array[0])-1; i++ {
if rune(array[0][i]) < 97 || rune(array[0][i]) > 122 {
return false
}
}
return true
}
func isUpper(s string) bool {
array := []string{s}
for i := 0; i <= len(array[0])-1; i++ {
if rune(array[0][i]) < 65 || rune(array[0][i]) > 90 {
return false
}
}
return true
}
func toLower(s string) string {
array := []string{s}
new_word := ""
for i := 0; i <= len(array[0])-1; i++ {
if isUpper(string(array[0][i])) {
new_word += string(rune(array[0][i] + 32))
} else {
new_word += string(array[0][i])
}
}
return new_word
}
func isNumeric(s string) bool {
array := []string{s}
for i := 0; i <= len(array[0])-1; i++ {
if rune(array[0][i]) < 48 || rune(array[0][i]) > 57 {
return false
}
}
return true
}