Skip to content

Commit

Permalink
tocase: add alternating case, clean up help dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Aug 30, 2024
1 parent e78e657 commit 9ed9213
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/go/util/tocase.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
"unicode"
)

func toAlternatingCase(input string) string {
var result strings.Builder
for i, r := range input {
if i%2 == 0 {
result.WriteRune(unicode.ToUpper(r))
} else {
result.WriteRune(unicode.ToLower(r))
}
}
return result.String()
}

func toCamelCase(input string) string {
words := splitWords(input)
for i := range words {
Expand Down Expand Up @@ -56,9 +68,10 @@ func splitWords(input string) []string {
}

func main() {
camel := flag.Bool("camel", false, "Convert to CamelCase")
alternating := flag.Bool("alternating", false, "Convert to AlTeRnAtInG CaSe")
camel := flag.Bool("camel", false, "Convert to camelCase")
pascal := flag.Bool("pascal", false, "Convert to PascalCase")
random := flag.Bool("random", false, "Convert to rAnDoM")
random := flag.Bool("random", false, "Convert to RaNDOm CAsE")
snake := flag.Bool("snake", false, "Convert to snake_case")
flag.Parse()

Expand All @@ -69,7 +82,9 @@ func main() {

input := strings.Join(flag.Args(), " ")

if *camel {
if *alternating {
fmt.Println(toAlternatingCase(input))
} else if *camel {
fmt.Println(toCamelCase(input))
} else if *pascal {
fmt.Println(toPascalCase(input))
Expand Down

0 comments on commit 9ed9213

Please sign in to comment.