// Replace performs a replacement of values on s and returns the string with the replaced values.
762401
func (r Replacer) Replace(ctx context.Context, state request.Request, rr *dnstest.Recorder, s string) string {
	for _, placeholder := range r.labels {
		if strings.Contains(s, placeholder) {
			s = strings.Replace(s, placeholder, r.valueFunc(state, rr, placeholder), -1)
		}
	}

	// Metadata label replacements. Scan for {/ and search for next }, replace that metadata label with
	// any meta data that is available.
	b := strings.Builder{}
	for strings.Contains(s, labelReplacer) {
		idxStart := strings.Index(s, labelReplacer)
		endOffset := idxStart + len(labelReplacer)
		idxEnd := strings.Index(s[endOffset:], "}")
		if idxEnd > -1 {
			label := s[idxStart+2 : endOffset+idxEnd]

			fm := metadata.ValueFunc(ctx, label)
			replacement := EmptyValue
			if fm != nil {
				replacement = fm()
			}

			b.WriteString(s[:idxStart])
			b.WriteString(replacement)
			s = s[endOffset+idxEnd+1:]
		} else {
			break
		}
	}

	b.WriteString(s)
	return b.String()
}
911790
func ReplaceNode(target, newNode, oldNode *js.Object) {
	if newNode == oldNode {
		return
	}
	target.Call("replaceChild", newNode, oldNode)
}
411403
func (s *OrderService) Replace(orderID int64, useRemaining bool, newOrder SubmitOrder) (Order, error) {
	var side string
	if newOrder.Amount < 0 {
		newOrder.Amount = math.Abs(newOrder.Amount)
		side = "sell"
	} else {
		side = "buy"
	}

	payload := map[string]interface{}{
		"order_id":      strconv.FormatInt(orderID, 10),
		"symbol":        newOrder.Symbol,
		"amount":        strconv.FormatFloat(newOrder.Amount, 'f', -1, 32),
		"price":         strconv.FormatFloat(newOrder.Price, 'f', -1, 32),
		"exchange":      "bitfinex",
		"side":          side,
		"type":          newOrder.Type,
		"use_remaining": useRemaining,
	}

	req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/replace", payload)
	if err != nil {
		return Order{}, err
	}

	order := new(Order)
	_, err = s.client.do(req, order)
	if err != nil {
		return *order, err
	}

	return *order, nil
}
208602
func (w *wrapper) Replace(cfg Configuration) (Waiter, error) {
	w.mut.Lock()
	defer w.mut.Unlock()
	return w.replaceLocked(cfg.Copy())
}
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
}
1023487
func (spec MutateInSpec) Replace(path string, val interface{}, opts *MutateInSpecReplaceOptions) MutateInOp {
	if opts == nil {
		opts = &MutateInSpecReplaceOptions{}
	}
	var flags SubdocFlag
	if opts.IsXattr {
		flags |= SubdocFlagXattr
	}

	encoder := opts.Encoder
	if opts.Encoder == nil {
		encoder = JSONEncode
	}

	marshaled, _, err := encoder(val)
	if err != nil {
		return MutateInOp{err: err}
	}

	op := gocbcore.SubDocOp{
		Op:    gocbcore.SubDocOpReplace,
		Path:  path,
		Flags: gocbcore.SubdocFlag(flags),
		Value: marshaled,
	}

	return MutateInOp{op: op}
}
1071912
func (f *FileStore) Replace(oldFiles, newFiles []string) error {
	return f.replace(oldFiles, newFiles, nil)
}
1072102
func (d Ploop) Replace(p *ReplaceParam) error {
	args := []string{"replace"}
	if p.UUID != "" {
		args = append(args, "-u", p.UUID)
	} else if p.CurFile != "" {
		args = append(args, "-o", p.CurFile)
	} else {
		args = append(args, "-l", strconv.Itoa(p.Level))
	}

	if p.Flags != 0 {
		if p.Flags&KeepName == KeepName {
			args = append(args, "-k")
		}
	}
	args = append(args, "-i", p.File)
	args = append(args, d.dd)

	return ploop(args...)
}
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)
}
1049690
func substitute(src, sub, repl string) string {
	idx := strings.Index(src, sub)
	for idx >= 0 {
		src = src[:idx] + repl + src[idx+len(sub):]
		idx = strings.Index(src, sub)
	}
	return src
}
555824
func (pm *poolManager) Replace(name, provider string, attrs map[string]interface{}) error {
	if name == "" {
		return MissingNameError
	}
	var providerType storage.ProviderType
	// Use the existing provider type unless explicitly overwritten.
	if provider != "" {
		providerType = storage.ProviderType(provider)
	} else {
		existingConfig, err := pm.Get(name)
		if err != nil {
			return errors.Trace(err)
		}
		providerType = existingConfig.Provider()
	}
	attrs[Type] = providerType
	attrs[Name] = name
	cfg, err := pm.validatedConfig(name, providerType, attrs)
	if err != nil {
		return errors.Trace(err)
	}
	validatedAttrs := cfg.Attrs()
	validatedAttrs[Name] = name
	validatedAttrs[Type] = string(providerType)
	return pm.settings.ReplaceSettings(globalKey(name), attrs)
}
986038
func ReplaceLiteral(expression, replacement, input string) (string, error) {
	re, err := stdre.Compile(expression)
	if err != nil {
		return "", err
	}
	return re.ReplaceAllLiteralString(input, replacement), nil
}
67134
func (c *RawBinaryClient) Replace(item *Item) MutateResponse {
	if item == nil {
		return NewMutateErrorResponse("", errors.New("item is nil"))
	}

	c.mutex.Lock()
	defer c.mutex.Unlock()

	if resp := c.sendMutateRequest(opReplace, item, true); resp != nil {
		return resp
	}

	return c.receiveMutateResponse(opReplace, item.Key)
}
1357995
func replacePlaceholders(placeholders []string, params Params) ([]interface{}, error) {
	if len(placeholders) == 0 {
		return nil, nil
	}

	var result []interface{}
	for _, name := range placeholders {
		if value, ok := params[name]; ok {
			result = append(result, value)
		} else {
			return nil, errors.New("Named parameter not found: " + name)
		}
	}
	return result, nil
}
555012
func ReplaceAll(source Expr, regex Expr, replacement Expr) Expr {
	regexString := ""
	_regex, ok := regex.(*constant)
	if ok {
		regexString = fmt.Sprint(_regex.Eval(nil))
	} else {
		fmt.Println("Regex is not a constant!")
		regexString = ""
	}
	e := &replaceAll{Source: source, Regex: regexString, Replacement: replacement}
	e.initReplacer()
	return e
}
955630
func ReplacePattern(str, pattern, replace string) string {
	r, _ := regexp.Compile(pattern)
	return r.ReplaceAllString(str, replace)
}
632600
func string_replace(fnname string, recv_ Value, args Tuple, kwargs []Tuple) (Value, error) {
	recv := string(recv_.(String))
	var old, new string
	count := -1
	if err := UnpackPositionalArgs(fnname, args, kwargs, 2, &old, &new, &count); err != nil {
		return nil, err
	}
	return String(strings.Replace(recv, old, new, count)), nil
}