favclip/qbg · generator.go
go logo
func (st *BuildStruct) Name() string {
	// FooBar -> fooBar
	// IIS -> iis
	// AEData -> aeData

	name := st.SimpleName()

	if !st.Private {
		return name
	}
	if len(name) <= 1 {
		return strings.ToLower(name)
	}
	if name == strings.ToUpper(name) {
		return strings.ToLower(name)
	}

	runeNames := []rune(name)
	if unicode.IsLower(runeNames[0]) {
		return name
	} else if unicode.IsLower(runeNames[1]) {
		return string(unicode.ToLower(runeNames[0])) + string(runeNames[1:])
	}

	var idx int
	for idx = 0; idx < len(runeNames); idx++ {
		r := runeNames[idx]
		if unicode.IsLower(r) {
			break
		}
	}

	return strings.ToLower(string(runeNames[0:idx-1])) + string(runeNames[idx-1:])
}
Similar code snippets
1.
webx-top/com · string.go
Match rating: 62.92% · See similar code snippets
go logo
func LowerCaseFirst(name string) string {
	s := []rune(name)
	if len(s) > 0 {
		s[0] = unicode.ToLower(s[0])
		name = string(s)
	}
	return name
}
2.
influxdata/telegraf · internal.go
Match rating: 60.51% · See similar code snippets
go logo
func SnakeCase(in string) string {
	runes := []rune(in)
	length := len(runes)

	var out []rune
	for i := 0; i < length; i++ {
		if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {
			out = append(out, '_')
		}
		out = append(out, unicode.ToLower(runes[i]))
	}

	return string(out)
}
3.
goadesign/gorma · relationalmodel.go
Match rating: 60.18% · See similar code snippets
go logo
func (f *RelationalModelDefinition) Underscore() string {
	runes := []rune(f.ModelName)
	length := len(runes)

	var out []rune
	for i := 0; i < length; i++ {
		if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {
			out = append(out, '_')
		}
		out = append(out, unicode.ToLower(runes[i]))
	}

	return string(out)
}
4.
mota/klash · utils.go
Match rating: 59.85% · See similar code snippets
go logo
func DecomposeName(name string, lower bool) string {
	length := len(name)
	var buf bytes.Buffer
	var caseChange func(rune) rune
	var joinRune rune

	if lower {
		caseChange = unicode.ToLower
		joinRune = '-'
	} else {
		caseChange = unicode.ToUpper
		joinRune = '_'
	}

	for idx, c := range name {
		if idx > 0 && unicode.IsUpper(c) && idx != length-1 {
			buf.WriteRune(joinRune)
		}
		buf.WriteRune(caseChange(c))
	}
	return buf.String()
}
5.
codemodus/kace · kace.go
Match rating: 59.75% · See similar code snippets
go logo
func delimitedCase(s string, delim rune, upper bool) string {
	buf := make([]rune, 0, len(s)*2)

	for i := len(s); i > 0; i-- {
		switch {
		case unicode.IsLetter(rune(s[i-1])):
			if i < len(s) && unicode.IsUpper(rune(s[i])) {
				if i > 1 && unicode.IsLower(rune(s[i-1])) || i < len(s)-2 && unicode.IsLower(rune(s[i+1])) {
					buf = append(buf, delim)
				}
			}

			buf = appendCased(buf, upper, rune(s[i-1]))

		case unicode.IsNumber(rune(s[i-1])):
			if i == len(s) || i == 1 || unicode.IsNumber(rune(s[i])) {
				buf = append(buf, rune(s[i-1]))
				continue
			}

			buf = append(buf, delim, rune(s[i-1]))

		default:
			if i == len(s) {
				continue
			}

			buf = append(buf, delim)
		}
	}

	reverse(buf)

	return string(buf)
}
6.
goadesign/gorma · relationalfield.go
Match rating: 59.29% · See similar code snippets
go logo
func (f *RelationalFieldDefinition) Underscore() string {
	runes := []rune(f.FieldName)
	length := len(runes)

	var out []rune
	for i := 0; i < length; i++ {
		if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {
			out = append(out, '_')
		}
		out = append(out, unicode.ToLower(runes[i]))
	}

	return string(out)
}
7.
ghetzel/pivot · file_backend.go
Match rating: 58.82% · See similar code snippets
go logo
func (self *FileBackend) normcol(name string) string {
	name = strings.TrimSpace(name)
	name = strings.ToLower(name)
	name = strings.TrimFunc(name, func(r rune) bool {
		if unicode.IsLetter(r) || unicode.IsNumber(r) {
			return false
		} else {
			return true
		}
	})

	return name
}
8.
maxbrunsfeld/counterfeiter · parser.go
Match rating: 58.26% · See similar code snippets
go logo
func fixupUnexportedNames(interfaceName string) string {
	asRunes := []rune(interfaceName)
	if len(asRunes) == 0 || !unicode.IsLower(asRunes[0]) {
		return interfaceName
	}
	asRunes[0] = unicode.ToUpper(asRunes[0])
	return string(asRunes)
}
9.
hajimehoshi/ebiten · genkeys.go
Match rating: 58.21% · See similar code snippets
go logo
func (k KeyNames) alphabet(name string) rune {
	if len(name) != 1 {
		return -1
	}
	c := rune(name[0])
	if c < 'A' || 'Z' < c {
		return -1
	}
	return c
}
10.
alioygur/godash · to.go
Match rating: 58.15% · See similar code snippets
go logo
func ToSnakeCase(s string) string {
	s = ToCamelCase(s)
	runes := []rune(s)
	length := len(runes)
	var out []rune
	for i := 0; i < length; i++ {
		out = append(out, unicode.ToLower(runes[i]))
		if i+1 < length && (unicode.IsUpper(runes[i+1]) && unicode.IsLower(runes[i])) {
			out = append(out, '_')
		}
	}

	return string(out)
}