mirror of https://github.com/matrix-org/go-neb.git
No known key found for this signature in database
GPG Key ID: E5B89311FAB91B9F
3 changed files with 76 additions and 16 deletions
-
23src/github.com/matrix-org/go-neb/services/circleci/circleci.go
-
8src/github.com/matrix-org/go-neb/services/circleci/circleci_test.go
-
61src/github.com/matrix-org/go-neb/services/circleci/util.go
@ -0,0 +1,61 @@ |
|||
package circleci |
|||
|
|||
import ( |
|||
"unicode" |
|||
"unicode/utf8" |
|||
) |
|||
|
|||
type buffer struct { |
|||
r []byte |
|||
runeBytes [utf8.UTFMax]byte |
|||
} |
|||
|
|||
func (b *buffer) write(r rune) { |
|||
if r < utf8.RuneSelf { |
|||
b.r = append(b.r, byte(r)) |
|||
return |
|||
} |
|||
n := utf8.EncodeRune(b.runeBytes[0:], r) |
|||
b.r = append(b.r, b.runeBytes[0:n]...) |
|||
} |
|||
|
|||
func (b *buffer) indent() { |
|||
if len(b.r) > 0 { |
|||
b.r = append(b.r, '_') |
|||
} |
|||
} |
|||
|
|||
func CamelCaseToUnderscore(s string) string { |
|||
b := buffer{ |
|||
r: make([]byte, 0, len(s)), |
|||
} |
|||
var m rune |
|||
var w bool |
|||
for _, ch := range s { |
|||
if unicode.IsUpper(ch) { |
|||
if m != 0 { |
|||
if !w { |
|||
b.indent() |
|||
w = true |
|||
} |
|||
b.write(m) |
|||
} |
|||
m = unicode.ToLower(ch) |
|||
} else { |
|||
if m != 0 { |
|||
b.indent() |
|||
b.write(m) |
|||
m = 0 |
|||
w = false |
|||
} |
|||
b.write(ch) |
|||
} |
|||
} |
|||
if m != 0 { |
|||
if !w { |
|||
b.indent() |
|||
} |
|||
b.write(m) |
|||
} |
|||
return string(b.r) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue