shurcooL/graphql · ident.go
go logo
func (n Name) ToLowerCamelCase() string {
	for i, word := range n {
		if i == 0 {
			n[i] = strings.ToLower(word)
			continue
		}
		r, size := utf8.DecodeRuneInString(word)
		n[i] = string(unicode.ToUpper(r)) + strings.ToLower(word[size:])
	}
	return strings.Join(n, "")
}
Similar code snippets
1.
taskcluster/jsonschema2go · text.go
Match rating: 64.55% · See similar code snippets
go logo
func fixCase(word string, makeLower bool) string {
	if word == "" {
		return ""
	}
	if makeLower {
		return strings.ToLower(word)
	}
	upper := strings.ToUpper(word)
	if commonInitialisms[upper] {
		return upper
	}
	firstRune, size := utf8.DecodeRuneInString(word)
	remainingString := word[size:]
	return string(unicode.ToUpper(firstRune)) + remainingString
}
2.
Pallinder/go-randomdata · random_data.go
Match rating: 62.95% · See similar code snippets
go logo
func lowercaseFirstLetter(word string) string {
	a := []rune(word)
	a[0] = unicode.ToLower(a[0])
	return string(a)
}
3.
shurcooL/graphql · ident.go
Match rating: 61.34% · See similar code snippets
go logo
func (n Name) ToMixedCaps() string {
	for i, word := range n {
		if strings.EqualFold(word, "IDs") { // Special case, plural form of ID initialism.
			n[i] = "IDs"
			continue
		}
		if initialism, ok := isInitialism(word); ok {
			n[i] = initialism
			continue
		}
		if brand, ok := isBrand(word); ok {
			n[i] = brand
			continue
		}
		r, size := utf8.DecodeRuneInString(word)
		n[i] = string(unicode.ToUpper(r)) + strings.ToLower(word[size:])
	}
	return strings.Join(n, "")
}
4.
googleapis/gnostic · helpers.go
Match rating: 59.76% · See similar code snippets
go logo
func snakeCaseToCamelCase(input string) string {
	out := ""

	words := strings.Split(input, "_")

	for i, word := range words {
		if (i > 0) && len(word) > 0 {
			w := []rune(word)
			w[0] = unicode.ToUpper(w[0])
			out += string(w)
		} else {
			out += word
		}
	}

	return out
}
5.
mkideal/pkg · namemapper.go
Match rating: 59.3% · See similar code snippets
go logo
func split(s string) ([]string, bool) {
	if s == "" {
		return nil, false
	}
	ret := make([]string, 0)
	ccase := 0
	const UPPER_CASE = 1
	const LOWER_CASE = 2
	word := bytes.NewBufferString("")
	for i := 0; i < len(s); i++ {
		b := s[i]
		if b >= 'A' && b <= 'Z' {
			if ccase != UPPER_CASE {
				if word.Len() > 0 {
					ret = append(ret, word.String())
					word.Reset()
				}
			}
			word.WriteByte(b)
			ccase = UPPER_CASE
		} else if b >= 'a' && b <= 'z' {
			word.WriteByte(b)
			ccase = LOWER_CASE
		} else if b == '_' {
			if word.Len() > 0 {
				ret = append(ret, word.String())
			}
			ccase = 0
			word.Reset()
		} else if b >= '0' && b <= '9' {
			word.WriteByte(b)
		} else {
			return nil, false
		}
		if i+1 == len(s) && word.Len() > 0 {
			ret = append(ret, word.String())
		}
	}
	return ret, true
}
6.
Pallinder/go-randomdata · random_data.go
Match rating: 58.9% · See similar code snippets
go logo
func uppercaseFirstLetter(word string) string {
	a := []rune(word)
	a[0] = unicode.ToUpper(a[0])
	return string(a)
}
7.
markbates/inflect · inflect.go
Match rating: 58.04% · See similar code snippets
go logo
func splitAtCaseChangeWithTitlecase(s string) []string {
	words := make([]string, 0)
	word := make([]rune, 0)

	for _, c := range s {
		spacer := isSpacerChar(c)
		if len(word) > 0 {
			if unicode.IsUpper(c) || spacer {
				words = append(words, string(word))
				word = make([]rune, 0)
			}
		}
		if !spacer {
			if len(word) > 0 {
				word = append(word, unicode.ToLower(c))
			} else {
				word = append(word, unicode.ToUpper(c))
			}
		}
	}

	words = append(words, string(word))
	return words
}
8.
serenize/snaker · snaker.go
Match rating: 55.97% · See similar code snippets
go logo
func snakeToCamel(s string, upperCase bool) string {
	var result string

	words := strings.Split(s, "_")

	for i, word := range words {
		if exception := snakeToCamelExceptions[word]; len(exception) > 0 {
			result += exception
			continue
		}

		if upperCase || i > 0 {
			if upper := strings.ToUpper(word); commonInitialisms[upper] {
				result += upper
				continue
			}
		}

		if (upperCase || i > 0) && len(word) > 0 {
			w := []rune(word)
			w[0] = unicode.ToUpper(w[0])
			result += string(w)
		} else {
			result += word
		}
	}

	return result
}
9.
ardielle/ardielle-go · genutil.go
Match rating: 55.91% · See similar code snippets
go logo
func SnakeToCamel(name string) string {
	// "THIS_IS_IT" -> "ThisIsIt"
	result := make([]rune, 0)
	newWord := true
	for _, c := range name {
		if c == '_' {
			newWord = true
		} else if newWord {
			result = append(result, unicode.ToUpper(c))
			newWord = false
		} else {
			result = append(result, unicode.ToLower(c))
		}
	}
	s := string(result)
	return strings.Replace(strings.Replace(s, "Uuid", "UUID", -1), "Uri", "URI", -1)
}
10.
coryb/figtree · figtree.go
Match rating: 55.52% · See similar code snippets
go logo
func camelCase(name string) string {
	words := camelCaseWords.FindAllString(name, -1)
	for i, word := range words {
		words[i] = strings.Title(word)
	}
	return strings.Join(words, "")

}