mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
770 B
47 lines
770 B
package main |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"strings" |
|
) |
|
|
|
func isAlphaNumerical(r rune) bool { |
|
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') |
|
} |
|
|
|
func isLowerRune(r rune) bool { |
|
return r >= 'a' && r <= 'z' |
|
} |
|
|
|
func toUpperRune(r rune) rune { |
|
if r >= 'a' && r <= 'z' { |
|
return r - 32 |
|
} |
|
return r |
|
} |
|
|
|
func capitalize(s string) string { |
|
r := []rune(strings.ToLower(s)) |
|
|
|
if isLowerRune(r[0]) { |
|
r[0] = toUpperRune(r[0]) |
|
} |
|
|
|
for i := 1; i < len(r); i++ { |
|
if (!isAlphaNumerical(r[i-1])) && (isLowerRune(r[i])) { |
|
r[i] = toUpperRune(r[i]) |
|
} |
|
} |
|
return string(r) |
|
} |
|
|
|
func main() { |
|
if len(os.Args) == 2 { |
|
fmt.Println(capitalize(os.Args[1])) |
|
} else if len(os.Args) > 2 { |
|
fmt.Println("Too many arguments") |
|
} else { |
|
fmt.Println() |
|
} |
|
}
|
|
|