소스 검색

Reintroduce strings.TrimCase in snake

tags/v0.1.2^2
Nathan Baulch 3 년 전
부모
커밋
e6c294d87b
1개의 변경된 파일1개의 추가작업 그리고 18개의 파일을 삭제
  1. +1
    -18
      snake.go

+ 1
- 18
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 {


불러오는 중...
취소
저장