// replaceBadChars strips characters and character sequences that are invalid
// characters for Go identifiers.
178347
func replaceBadChars(s string) string {
	// strip bad characters
	r := []rune{}
	for _, ch := range s {
		if isIdentifierChar(ch) {
			r = append(r, ch)
		} else {
			r = append(r, '_')
		}
	}

	return string(r)
}
835805
func replaceArguments(query string, args []driver.Value) string {

	holder := regexp.MustCompile(`[^\$]\$[0-9]+`)
	replacedQuery := ""

	if strings.Count(query, "?") == len(args) {
		return replaceArgumentsODBC(query, args)
	}

	allloc := holder.FindAllIndex([]byte(query), -1)
	queryB := []byte(query)
	for i, loc := range allloc {
		match := queryB[loc[0]+1 : loc[1]]

		index, err := strconv.Atoi(string(match[1:]))
		if err != nil {
			log.Warning("Matched %s as a placeholder but cannot get index: %s\n", match, err)
			return query
		}

		var v string
		if args[index-1] == nil {
			v = "null"
		} else {
			v = fmt.Sprintf("$$%v$$", args[index-1])
		}
		if i == 0 {
			replacedQuery = fmt.Sprintf("%s%s%s", replacedQuery, string(queryB[:loc[0]+1]), v)
		} else {
			replacedQuery = fmt.Sprintf("%s%s%s", replacedQuery, string(queryB[allloc[i-1][1]:loc[0]+1]), v)
		}
	}
	// add remaining query
	replacedQuery = fmt.Sprintf("%s%s", replacedQuery, string(queryB[allloc[len(allloc)-1][1]:]))

	return replacedQuery
}
605317
func (j *Job) Replaces() []string {
	replaces := make([]string, 0)
	replaces = append(replaces, j.requirements()[fleetReplaces]...)
	return replaces
}
1139045
func replaceMapSecrets(obj map[string]interface{}, secretValues map[string]string) map[string]interface{} {
	newObj := make(map[string]interface{})
	for k, v := range obj {
		switch val := v.(type) {
		case map[string]interface{}:
			newObj[k] = replaceMapSecrets(val, secretValues)
		case []interface{}:
			newObj[k] = replaceListSecrets(val, secretValues)
		case string:
			newObj[k] = settings.ReplaceStringSecret(val, secretValues)
		default:
			newObj[k] = val
		}
	}
	return newObj
}
947405
func replacePlaceholders(str string, kv ...string) string {
	for ph, value := range toMap(kv...) {
		str = strings.Replace(str, "!!!"+ph+"!!!", value, -1)
	}
	return str
}
1370992
func (c *ShardedClient) Replace(item *Item) MutateResponse {
	return c.mutate(
		item.Key,
		func(shardClient Client) MutateResponse {
			return shardClient.Replace(item)
		})
}
1328773
func (m MemSettings) ReplaceSettings(key string, settings map[string]interface{}) error {
	if _, ok := m.Settings[key]; !ok {
		return errors.NotFoundf("settings with key %q", key)
	}
	m.Settings[key] = settings
	return nil
}
967535
func (c *Client) Replace(key, val string, flags, exp uint32, ocas uint64) (cas uint64, err error) {
	// Variants: Replace [Q]
	return c.setGeneric(opReplace, key, val, ocas, flags, exp)
}
1283940
func normalizeKeys(key []string) {
	for i, k := range key {
		if !validCharactersRE.MatchString(k) {
			// first replace */* with all
			k = strings.Replace(k, allMatcher, allReplacement, -1)

			// now replace all other invalid characters with a safe one.
			key[i] = invalidCharactersRE.ReplaceAllString(k, normalizedToken)
		}
	}
}
1051749
func StripFormat(s string) string {
	r := regexp.MustCompile(reFormat)
	return r.ReplaceAllString(s, "")
}
1106177
func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) error {
	items := map[string]interface{}{}
	ts := c.clock.Now()
	for _, item := range list {
		key, err := c.keyFunc(item)
		if err != nil {
			return KeyError{item, err}
		}
		items[key] = &timestampedEntry{item, ts}
	}
	c.cacheStorage.Replace(items, resourceVersion)
	return nil
}
1333685
func replaceNonAlpha(s string, replace byte) string {
	byts := []byte(s)
	newByts := make([]byte, len(byts))

	for i := 0; i < len(byts); i++ {
		if byts[i] < 'A' || (byts[i] > 'Z' && byts[i] < 'a') || byts[i] > 'z' {
			newByts[i] = replace
		} else {
			newByts[i] = byts[i]
		}
	}

	return string(newByts)
}
853111
func substitute(
	obj map[string]interface{}, tokenMatcher *regexp.Regexp, replacer func(key string) string,
) map[string]interface{} {
	newObj := make(map[string]interface{})
	for k, v := range obj {
		switch v := v.(type) {
		case string:
			newObj[k] = tokenMatcher.ReplaceAllStringFunc(v, replacer)
		case []string:
			newV := make([]string, len(v))
			for i := 0; i < len(v); i++ {
				newV[i] = tokenMatcher.ReplaceAllStringFunc(v[i], replacer)
			}
			newObj[k] = newV
		default:
			newObj[k] = v
		}
	}
	return newObj
}
1209192
func (s *RedshiftSettings) SetReplaceChars(v string) *RedshiftSettings {
	s.ReplaceChars = &v
	return s
}
432355
func (b *Bucket) Replace(key string, value interface{}, cas Cas, expiry uint32) (Cas, error) {
	cas, _, err := b.replace(key, value, cas, expiry)
	return cas, err
}
445836
func (ns *Namespace) ReplaceRE(pattern, repl, s interface{}) (_ string, err error) {
	sp, err := cast.ToStringE(pattern)
	if err != nil {
		return
	}

	sr, err := cast.ToStringE(repl)
	if err != nil {
		return
	}

	ss, err := cast.ToStringE(s)
	if err != nil {
		return
	}

	re, err := reCache.Get(sp)
	if err != nil {
		return "", err
	}

	return re.ReplaceAllString(ss, sr), nil
}
870659
func strip(s string) string {
	trimmed := strings.TrimSpace(s)

	r := strings.NewReplacer(".", "_", ",", "", "-", "")
	return r.Replace(trimmed)
}