// Copyright (c) 2017, A. Stoewer <adrian.stoewer@rz.ifi.lmu.de>// All rights reserved.package strcaseimport ()// SnakeCase converts a string into snake case.func ( string) string {returndelimiterCase(, '_', false)}// UpperSnakeCase converts a string into snake case with capital letters.func ( string) string {returndelimiterCase(, '_', true)}// delimiterCase converts a string into snake_case or kebab-case depending on the delimiter passed// as second argument. When upperCase is true the result will be UPPER_SNAKE_CASE or UPPER-KEBAB-CASE.func delimiterCase( string, rune, bool) string { = strings.TrimSpace() := make([]rune, 0, len()+3) := toLowerif { = toUpper }varrunevarrunefor , := range {ifisDelimiter() {if !isDelimiter() { = append(, ) } } elseifisUpper() {ifisLower() || (isUpper() && isLower()) { = append(, ) } = append(, ()) } elseif != 0 { = append(, ()) } = = }iflen() > 0 {ifisUpper() && isLower() && != 0 { = append(, ) } = append(, ()) }returnstring()}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.