From e6c294d87b8e80dec5ba4b9cf0f65c7b189354f4 Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Mon, 21 Sep 2020 13:34:39 +1000 Subject: [PATCH] Reintroduce strings.TrimCase in snake --- snake.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/snake.go b/snake.go index b849a58..cc9ffcb 100644 --- a/snake.go +++ b/snake.go @@ -64,27 +64,10 @@ func ToDelimited(s string, delimiter uint8) string { // or delimited.snake.case // (in this case `delimiter = '.'; screaming = false`) func ToScreamingDelimited(s string, delimiter uint8, ignore uint8, screaming bool) string { + s = strings.TrimSpace(s) n := strings.Builder{} n.Grow(len(s) + 2) // nominal 2 bytes of extra space for inserted delimiters - start := true - spaces := 0 for i, v := range []byte(s) { - if v == ' ' { - spaces++ - continue - } else if start { - start = false - spaces = 0 - } else { - for ; spaces > 0; spaces-- { - if ignore == ' ' { - n.WriteByte(' ') - } else { - n.WriteByte(delimiter) - } - } - } - vIsCap := v >= 'A' && v <= 'Z' vIsLow := v >= 'a' && v <= 'z' if vIsLow && screaming {