// For a given input string, suggests potential replacements
8670
func (model *Model) Suggestions(input string, exhaustive bool) []string {
	model.RLock()
	suggestions := model.suggestPotential(input, exhaustive)
	model.RUnlock()
	output := make([]string, 0, 10)
	for _, suggestion := range suggestions {
		output = append(output, suggestion.Term)
	}
	return output
}
258952
func string_strip(fnname string, recv_ Value, args Tuple, kwargs []Tuple) (Value, error) {
	var chars string
	if err := UnpackPositionalArgs(fnname, args, kwargs, 0, &chars); err != nil {
		return nil, err
	}
	recv := string(recv_.(String))
	var s string
	switch fnname[0] {
	case 's': // strip
		if chars != "" {
			s = strings.Trim(recv, chars)
		} else {
			s = strings.TrimSpace(recv)
		}
	case 'l': // lstrip
		if chars != "" {
			s = strings.TrimLeft(recv, chars)
		} else {
			s = strings.TrimLeftFunc(recv, unicode.IsSpace)
		}
	case 'r': // rstrip
		if chars != "" {
			s = strings.TrimRight(recv, chars)
		} else {
			s = strings.TrimRightFunc(recv, unicode.IsSpace)
		}
	}
	return String(s), nil
}
985125
func AskForString(ctx context.Context, text, def string) (string, error) {
	if ctxutil.IsAlwaysYes(ctx) || !ctxutil.IsInteractive(ctx) {
		return def, nil
	}

	// check for context cancelation
	select {
	case <-ctx.Done():
		return def, ErrAborted
	default:
	}

	fmt.Fprintf(Stdout, "%s [%s]: ", text, def)
	input, err := NewReader(Stdin).ReadLine()
	if err != nil {
		return "", errors.Wrapf(err, "failed to read user input")
	}
	input = strings.TrimSpace(input)
	if input == "" {
		input = def
	}
	return input, nil
}
336818
func stringFunc(q query, t iterator) interface{} {
	v := q.Evaluate(t)
	return asString(t, v)
}
45964
func (g *Graph) Substitute(s string, v interface{}) {
	if g == nil || g.Out == nil {
		return
	}
	for _, n := range g.Out {
		if _string(n.This) == s {
			n.This = v
		}
		n.Substitute(s, v)
	}

}
947405
func replacePlaceholders(str string, kv ...string) string {
	for ph, value := range toMap(kv...) {
		str = strings.Replace(str, "!!!"+ph+"!!!", value, -1)
	}
	return str
}
237138
func (r *replacer) Replace(s string) string {
	// Do not attempt replacements if no placeholder is found.
	if !strings.ContainsAny(s, "{}") {
		return s
	}

	result := ""
	for {
		idxStart := strings.Index(s, "{")
		if idxStart == -1 {
			// no placeholder anymore
			break
		}
		idxEnd := strings.Index(s[idxStart:], "}")
		if idxEnd == -1 {
			// unpaired placeholder
			break
		}
		idxEnd += idxStart

		// get a replacement
		placeholder := s[idxStart : idxEnd+1]
		replacement := r.getSubstitution(placeholder)

		// append prefix + replacement
		result += s[:idxStart] + replacement

		// strip out scanned parts
		s = s[idxEnd+1:]
	}

	// append unscanned parts
	return result + s
}
1315622
func (t *Tags) Replace(s string) error {
	if s == "" {
		*t = Tags{}
		return nil
	}
	if err := CheckTags(s); err != nil {
		return e.Forward(err)
	}
	*t = Tags{}
	tags := strings.Split(s, ",")
	for _, tag := range tags {
		trim := strings.TrimSpace(tag)
		if trim == "" {
			continue
		}
		err := t.Add(tag)
		if err != nil {
			continue
		}
	}
	return nil
}
110617
func replace(a []string, b string) []string {
	if len(b) > 0 {
		return strings.Fields(b)
	}
	return a
}
686509
func similar(str string, candidates []string) string {
	for _, candidate := range candidates {
		if strings.EqualFold(str, candidate) {
			return candidate
		}
	}
	return ""
}
618656
func FnSub(name string, input interface{}, template interface{}) interface{} {

	// Input can either be a string for this type of Fn::Sub call:
	// { "Fn::Sub": "some-string-with-a-${variable}" }

	// or it will be an array of length two for named replacements
	// { "Fn::Sub": [ "some ${replaced}", { "replaced": "value" } ] }

	switch val := input.(type) {

	case []interface{}:
		// Replace each of the variables in element 0 with the items in element 1
		if src, ok := val[0].(string); ok {
			// The seconds element is a map of variables to replace
			if replacements, ok := val[1].(map[string]interface{}); ok {
				// Loop through the replacements
				for key, replacement := range replacements {
					// Check the replacement is a string
					if value, ok := replacement.(string); ok {
						src = strings.Replace(src, "${"+key+"}", value, -1)
					}
				}
				return src
			}
		}

	case string:
		// Look up references for each of the variables
		regex := regexp.MustCompile(`\$\{([\.0-9A-Za-z]+)\}`)
		variables := regex.FindAllStringSubmatch(val, -1)
		for _, variable := range variables {

			var resolved interface{}
			if strings.Contains(variable[1], ".") {
				// If the variable name has a . in it, use Fn::GetAtt to resolve it
				resolved = FnGetAtt("Fn::GetAtt", strings.Split(variable[1], "."), template)
			} else {
				// The variable name doesn't have a . in it, so use Ref
				resolved = Ref("Ref", variable[1], template)
			}

			if resolved != nil {
				if replacement, ok := resolved.(string); ok {
					val = strings.Replace(val, variable[0], replacement, -1)
				}
			} else {
				// The reference couldn't be resolved, so just strip the variable
				val = strings.Replace(val, variable[0], "", -1)
			}

		}
		return val
	}

	return nil

}
1109250
func StringIn(str string, strs []string) int {
	for i, s := range strs {
		if s == str {
			return i
		}
	}

	return -1
}
1003990
func ShuffleStringsInPlace(strings []string) {
	for i := range strings {
		j := rand.Intn(i + 1)
		strings[i], strings[j] = strings[j], strings[i]
	}
}
699797
func (model *Model) SpellCheckSuggestions(input string, n int) []string {
	model.RLock()
	suggestions := model.suggestPotential(input, true)
	model.RUnlock()
	return bestn(input, suggestions, n)
}
1338567
func substituteSubstr(str, key, val string) string {
	key = fmt.Sprintf("\\${%s:([0-9]*):([0-9]*)}", key)
	reg, err := regexp.Compile(key)
	if err != nil {
		return str
	}
	for _, match := range reg.FindAllStringSubmatch(str, -1) {
		if len(match) != 3 {
			continue
		}
		pos, err := strconv.Atoi(match[1])
		if err != nil {
			continue // skip
		}
		length, err := strconv.Atoi(match[2])
		if err != nil {
			continue // skip
		}
		if pos+length > len(val)-1 {
			continue // skip
		}
		str = strings.Replace(str, match[0], val[pos:pos+length], -1)
	}
	return str
}
108521
func stringToRuneSlice(input string) []rune {
	output := make([]rune, utf8.RuneCountInString(input))
	n := 0
	for _, r := range input {
		output[n] = r
		n++
	}
	return output
}
183483
func (a *VppAdapter) ReplyFor(requestMsgName string) (api.Message, uint16, bool) {
	replType, msgID, foundReplType := a.ReplyTypeFor(requestMsgName)
	if foundReplType {
		msgVal := reflect.New(replType)
		if msg, ok := msgVal.Interface().(api.Message); ok {
			log.Println("FFF ", replType, msgID, foundReplType)
			return msg, msgID, true
		}
	}

	return nil, 0, false
}