// FindCommonSuffix returns the longest common suffix from the given
// strings.
337232
func FindCommonSuffix(input []string) string {
	rv := ""
	if len(input) < 2 {
		return ""
	}
	from := input
	for i := len(input[0]); i > 0; i-- {
		common := true
		suffix := input[0][i:]
		for _, s := range from {
			if !strings.HasSuffix(s, suffix) {
				common = false
				break
			}
		}
		if common {
			rv = suffix
		}
	}
	return rv
}
1323147
func suffix(pathToBucket string, bucketPrefix string) (string, error) {
	full, err := url.QueryUnescape(pathToBucket)
	if err != nil {
		return "", trace.Wrap(err)
	}
	prefix, err := url.QueryUnescape(bucketPrefix)
	if err != nil {
		return "", trace.Wrap(err)
	}

	remain := full[len(prefix)+1:]
	if remain == "" {
		return "", trace.BadParameter("unable to split %v", remain)
	}

	vals := strings.Split(remain, string(filepath.Separator))
	if len(vals) == 0 {
		return "", trace.BadParameter("unable to split %v", remain)
	}

	return vals[0], nil
}
869535
func matchPrefix(row chunk.Row, colIdx int, ad *types.Datum) bool {
	switch ad.Kind() {
	case types.KindString, types.KindBytes, types.KindBinaryLiteral, types.KindMysqlBit:
		return strings.HasPrefix(row.GetString(colIdx), ad.GetString())
	}
	return false
}
470645
func hasPrefix(buf []byte, prefix []byte) bool {
	trim := bytes.TrimLeftFunc(buf, unicode.IsSpace)
	return bytes.HasPrefix(trim, prefix)
}
978865
func HasSuffix(s, suffix []rune) bool {
	return len(s) >= len(suffix) && Equal(s[len(s)-len(suffix):], suffix)
}
437590
func parseMethodConfigAndSuffix(c string) (service, method, suffix string, _ error) {
	// Regexp result:
	//
	// in:  "p.s/m{h:123,m:123}",
	// out: []string{"p.s/m{h:123,m:123}", "p.s", "m", "{h:123,m:123}"},
	match := longMethodConfigRegexp.FindStringSubmatch(c)
	if match == nil {
		return "", "", "", fmt.Errorf("%q contains invalid substring", c)
	}
	service = match[1]
	method = match[2]
	suffix = match[3]
	return
}
1295310
func CheckPrefixFactory(prefixes ...string) func(string) (string, bool) {
	return func(content string) (string, bool) {
		for _, prefix := range prefixes {
			if strings.HasPrefix(content, prefix) {
				return strings.TrimPrefix(content, prefix), true
			}
		}
		return "", false
	}
}
311841
func findCommaFromEnd(b []byte, offset int) int {
	for i := len(b) - 1; i > offset; i-- {
		if b[i] == ',' {
			return i
		}
	}
	panic(fmt.Errorf("no comma found in %q after offset %d", b, offset))
}
869036
func pathSuffix(path string) string {
	const pathSep = "/"
	lastSep := strings.LastIndex(path, pathSep)
	if lastSep == -1 {
		return path
	}
	return path[strings.LastIndex(path[:lastSep], pathSep)+1:]
}
1022854
func getSuffix(c context.Context) string {
	const allowed = "abcdefghijklmnopqrstuvwxyz0123456789"
	suf := make([]byte, 4)
	for i := range suf {
		suf[i] = allowed[mathrand.Intn(c, len(allowed))]
	}
	return string(suf)
}
408961
func longestCommonPrefix(strs []string) string {
	if len(strs) == 0 {
		return ""
	}
	lcp := strs[0]
	for _, str := range strs {
		lcp = strlcp(lcp, str)
	}
	return lcp
}
85048
func splitSheetIntoPrefixAndSuffix(data string) (string, string, error) {
	// Split the sheet at the end of its SheetData tag so that more rows can be added inside.
	sheetParts := strings.Split(data, endSheetDataTag)
	if len(sheetParts) != 2 {
		return "", "", errors.New("unexpected Sheet XML: SheetData close tag not found")
	}
	return sheetParts[0], sheetParts[1], nil
}
479893
func getSubPrefix(curPrefix, subField string) string {
	if curPrefix != "" {
		return fmt.Sprintf("%s.%s", curPrefix, subField)
	}
	return fmt.Sprintf("%s", subField)
}
1079085
func commonSuffixes(vs []string, minLength int) (result map[string]commonSs) {
	result = make(map[string]commonSs)
	for i := 0; i < len(vs)-1; i++ {
		j := i + 1
		k := 0
		for ; k < len(vs[i]) && k < len(vs[j]); k++ {
			if vs[i][len(vs[i])-k-1] != vs[j][len(vs[j])-k-1] {
				break
			}
		}
		if k < minLength {
			continue
		}
		suffix := vs[i][len(vs[i])-k:]
		if _, exists := result[suffix]; !exists {
			first := suffixStart(vs[:i], suffix)
			//debugf("suffixStart<%#q>(%#q) == %v", suffix, vs[:i], first)
			// suffixEnd(vs, suffix) - first + 1
			// == suffixEnd(vs[first:], suffix) + 1
			// == suffixEnd(vs[first+1:], suffix) + 2
			end := first + 1 + suffixEnd(vs[first+1:], suffix)
			result[suffix] = commonSs{
				first, end,
			}
			//debugf("suffixEnd  <%#q>(%#q) == %v", suffix, vs, result[suffix].end)
			//debugf("selected(%#q): %q\n\n", suffix, vs[first:result[suffix].end])
		}
	}
	// debugf("# ..%v", result)
	return result
}
103317
func commonPrefix(l, r []string) []string {
	var i int
	for i = 0; i < len(l) && i < len(r); i++ {
		if l[i] != r[i] {
			break
		}
	}
	return l[:i]
}
147611
func newHandleExtensionSuffix(
	extensions []HandleExtension, isBackedByTeam bool) string {
	var suffix string
	for _, extension := range extensions {
		suffix += HandleExtensionSep
		suffix += extension.string(isBackedByTeam)
	}
	return suffix
}
103431
func (p *parser) parseComprehensionSuffix(lbrace Position, body Expr, endBrace Token) Expr {
	var clauses []Node
	for p.tok != endBrace {
		if p.tok == FOR {
			pos := p.nextToken()
			vars := p.parseForLoopVariables()
			in := p.consume(IN)
			// Following Python 3, the operand of IN cannot be:
			// - a conditional expression ('x if y else z'),
			//   due to conflicts in Python grammar
			//  ('if' is used by the comprehension);
			// - a lambda expression
			// - an unparenthesized tuple.
			x := p.parseTestPrec(0)
			clauses = append(clauses, &ForClause{For: pos, Vars: vars, In: in, X: x})
		} else if p.tok == IF {
			pos := p.nextToken()
			cond := p.parseTestNoCond()
			clauses = append(clauses, &IfClause{If: pos, Cond: cond})
		} else {
			p.in.errorf(p.in.pos, "got %#v, want '%s', for, or if", p.tok, endBrace)
		}
	}
	rbrace := p.nextToken()

	return &Comprehension{
		Curly:   endBrace == RBRACE,
		Lbrack:  lbrace,
		Body:    body,
		Clauses: clauses,
		Rbrack:  rbrace,
	}
}