// Underscore converts "CamelCasedString" to "camel_cased_string".
557281
func Underscore(s string) string {
	r := make([]byte, 0, len(s)+5)
	for i := 0; i < len(s); i++ {
		c := s[i]
		if IsUpper(c) {
			if i > 0 && i+1 < len(s) && (IsLower(s[i-1]) || IsLower(s[i+1])) {
				r = append(r, '_', ToLower(c))
			} else {
				r = append(r, ToLower(c))
			}
		} else {
			r = append(r, c)
		}
	}
	return string(r)
}
960603
func pascalCase(allowAllCaps bool, words ...string) string {
	for i, chunk := range words {
		if len(chunk) == 0 {
			// foo__bar
			continue
		}

		// known initalism
		init := strings.ToUpper(chunk)
		if _, ok := commonInitialisms[init]; ok {
			words[i] = init
			continue
		}

		// Was SCREAMING_SNAKE_CASE and not a known initialism so Titlecase it.
		if isAllCaps(chunk) && !allowAllCaps {
			// A single ALLCAPS word does not count as SCREAMING_SNAKE_CASE.
			// There must be at least one underscore.
			words[i] = strings.Title(strings.ToLower(chunk))
			continue
		}

		// Just another word, but could already be camelCased somehow, so just
		// change the first letter.
		head, headIndex := utf8.DecodeRuneInString(chunk)
		words[i] = string(unicode.ToUpper(head)) + string(chunk[headIndex:])
	}

	return strings.Join(words, "")
}
887550
func convertUnderscoresToCamelCase(s string) string {
	if len(s) == 0 {
		return ""
	}
	result := ""
	shouldUpper := false
	for _, char := range s {
		if char == '_' {
			shouldUpper = true
			continue
		}
		if shouldUpper {
			result += strings.ToUpper(string(char))
		} else {
			result += string(char)
		}
		shouldUpper = false
	}
	return result
}
699695
func PascalCase(s string) string {
	n := ""
	capNext := true
	for _, v := range s {
		if v >= 'a' && v <= 'z' {
			if capNext {
				n += strings.ToUpper(string(v))
				capNext = false
			} else {
				n += string(v)
			}
			continue
		}
		if v == '_' || v == ' ' {
			capNext = true
		} else {
			capNext = false
			n += string(v)
		}
	}
	return n
}
792889
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, "")
}
1043131
func (c *CharSet) addLowercase() {
	if c.anything {
		return
	}
	toAdd := []singleRange{}
	for i := 0; i < len(c.ranges); i++ {
		r := c.ranges[i]
		if r.first == r.last {
			lower := unicode.ToLower(r.first)
			c.ranges[i] = singleRange{first: lower, last: lower}
		} else {
			toAdd = append(toAdd, r)
		}
	}

	for _, r := range toAdd {
		c.addLowercaseRange(r.first, r.last)
	}
	c.canonicalize()
}
228615
func CamelToSnake(s string) string {
	if s == "" {
		return ""
	}

	rs := []rune(s)

	var r string
	var lastWasUpper, lastWasLetter, lastWasIsm, isUpper, isLetter bool
	for i := 0; i < len(rs); {
		isUpper = unicode.IsUpper(rs[i])
		isLetter = unicode.IsLetter(rs[i])

		// append _ when last was not upper and not letter
		if (lastWasLetter && isUpper) || (lastWasIsm && isLetter) {
			r += "_"
		}

		// determine next to append to r
		var next string
		if ism := peekInitialism(rs[i:]); ism != "" && (!lastWasUpper || lastWasIsm) {
			next = ism
		} else {
			next = string(rs[i])
		}

		// save for next iteration
		lastWasIsm = false
		if len(next) > 1 {
			lastWasIsm = true
		}
		lastWasUpper = isUpper
		lastWasLetter = isLetter

		r += next
		i += len(next)
	}

	return strings.ToLower(r)
}
382152
func Capitalize(s string) string {
	if len(s) == 1 {
		return strings.ToUpper(s)
	}
	return strings.ToUpper(s[0:1]) + s[1:]
}
493085
func ToCamelCase(input string) string {
	parts := strings.Split(input, "_")
	for i, s := range parts {
		if len(s) > 0 {
			parts[i] = strings.ToUpper(s[:1]) + s[1:]
		}
	}
	return strings.Join(parts, "")
}
664285
func string_islower(fnname string, recv_ Value, args Tuple, kwargs []Tuple) (Value, error) {
	if err := UnpackPositionalArgs(fnname, args, kwargs, 0); err != nil {
		return nil, err
	}
	recv := string(recv_.(String))
	return Bool(isCasedString(recv) && recv == strings.ToLower(recv)), nil
}
1037059
func (s *SearchService) MinScore(minScore float64) *SearchService {
	s.searchSource = s.searchSource.MinScore(minScore)
	return s
}
134205
func renderPatternString(pat string, sub func(name string) (string, error)) (pattern.Pattern, error) {
	var errs errors.MultiError
	out := placeholderRe.ReplaceAllStringFunc(pat, func(match string) string {
		name := match[2 : len(match)-1] // strip ${...}
		val, err := sub(name)
		if err != nil {
			errs = append(errs, err)
		}
		return val
	})
	if len(errs) != 0 {
		return nil, errs
	}
	return pattern.Parse(out)
}
528607
func ToDashCase(str string) string {
	if len(str) == 0 {
		return ""
	}

	buf := &bytes.Buffer{}
	var prev, r0, r1 rune
	var size int

	r0 = '-'

	for len(str) > 0 {
		prev = r0
		r0, size = utf8.DecodeRuneInString(str)
		str = str[size:]

		switch {
		case r0 == utf8.RuneError:
			buf.WriteByte(byte(str[0]))

		case unicode.IsUpper(r0):
			if prev != '-' {
				buf.WriteRune('-')
			}

			buf.WriteRune(unicode.ToLower(r0))

			if len(str) == 0 {
				break
			}

			r0, size = utf8.DecodeRuneInString(str)
			str = str[size:]

			if !unicode.IsUpper(r0) {
				buf.WriteRune(r0)
				break
			}

			// find next non-upper-case character and insert `_` properly.
			// it's designed to convert `HTTPServer` to `http_server`.
			// if there are more than 2 adjacent upper case characters in a word,
			// treat them as an abbreviation plus a normal word.
			for len(str) > 0 {
				r1 = r0
				r0, size = utf8.DecodeRuneInString(str)
				str = str[size:]

				if r0 == utf8.RuneError {
					buf.WriteRune(unicode.ToLower(r1))
					buf.WriteByte(byte(str[0]))
					break
				}

				if !unicode.IsUpper(r0) {
					if r0 == '_' || r0 == ' ' || r0 == '-' {
						r0 = '-'

						buf.WriteRune(unicode.ToLower(r1))
					} else {
						buf.WriteRune('-')
						buf.WriteRune(unicode.ToLower(r1))
						buf.WriteRune(r0)
					}

					break
				}

				buf.WriteRune(unicode.ToLower(r1))
			}

			if len(str) == 0 || r0 == '-' {
				buf.WriteRune(unicode.ToLower(r0))
				break
			}

		default:
			if r0 == ' ' || r0 == '_' {
				r0 = '-'
			}

			buf.WriteRune(r0)
		}
	}

	return buf.String()
}
747317
func Capitalize(s1 string) string {
	s2 := strings.ToLower(s1)
	return ToUpperFirst(s2)
}
316970
func LowercaseKey(handler cfg.Handler) cfg.Handler {
	return Apply(func(key string) (string, error) { return strings.ToLower(key), nil }, nil, handler)
}
1122077
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)
}
960727
func (r *rule) sub(text string) string {
	if !r.pattern.MatchString(text) {
		return text
	}

	orig := len(text)
	diff := 0
	for _, submat := range r.pattern.FindAllStringSubmatchIndex(text, -1) {
		for idx, mat := range submat {
			if mat != -1 && idx > 0 && idx%2 == 0 {
				loc := []int{mat - diff, submat[idx+1] - diff}
				text = text[:loc[0]] + r.replacement + text[loc[1]:]
				diff = orig - len(text)
			}
		}
	}

	return text
}