File tree 3 files changed +63
-0
lines changed
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bufio"
5
+ "fmt"
6
+ "os"
7
+ sponge_case "sponge-case/sponge-case"
8
+ )
9
+
10
+ func main () {
11
+ if len (os .Args ) == 2 {
12
+ applyToArgs ()
13
+ } else {
14
+ applyToStdin ()
15
+ }
16
+ }
17
+
18
+ func applyToStdin () {
19
+ scanner := bufio .NewScanner (os .Stdin )
20
+ for scanner .Scan () {
21
+ fmt .Println (sponge_case .ApplyStr (scanner .Text ()))
22
+ }
23
+ if err := scanner .Err (); err != nil {
24
+ fmt .Println (err )
25
+ }
26
+ }
27
+
28
+ func applyToArgs () {
29
+ fmt .Println (sponge_case .ApplyStr (os .Args [1 ]))
30
+ }
Original file line number Diff line number Diff line change
1
+ package sponge_case
2
+
3
+ import (
4
+ "math/rand"
5
+ "unicode"
6
+ )
7
+
8
+ func ApplyStr (in string ) string {
9
+ out := make ([]rune , len (in ))
10
+ var newChar rune
11
+
12
+ for pos , char := range []rune (in ) {
13
+ toUpper := rand .Float32 () > 0.5
14
+ if toUpper {
15
+ newChar = unicode .ToUpper (char )
16
+ } else {
17
+ newChar = unicode .ToLower (char )
18
+ }
19
+ out [pos ] = newChar
20
+ }
21
+
22
+ return string (out )
23
+ }
Original file line number Diff line number Diff line change
1
+ package sponge_case
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+ )
7
+
8
+ func TestApplyStr (t * testing.T ) {
9
+ fmt .Println (ApplyStr ("Das ist wirklich nicht witzig!" ))
10
+ }
You can’t perform that action at this time.
0 commit comments