// ApplyIndent mutates a JSON document according to the patch, and returns the new
// document indented.
325472
func (p Patch) ApplyIndent(doc []byte, indent string) ([]byte, error) {
	var pd container
	if doc[0] == '[' {
		pd = &partialArray{}
	} else {
		pd = &partialDoc{}
	}

	err := json.Unmarshal(doc, pd)

	if err != nil {
		return nil, err
	}

	err = nil

	var accumulatedCopySize int64

	for _, op := range p {
		switch op.kind() {
		case "add":
			err = p.add(&pd, op)
		case "remove":
			err = p.remove(&pd, op)
		case "replace":
			err = p.replace(&pd, op)
		case "move":
			err = p.move(&pd, op)
		case "test":
			err = p.test(&pd, op)
		case "copy":
			err = p.copy(&pd, op, &accumulatedCopySize)
		default:
			err = fmt.Errorf("Unexpected kind: %s", op.kind())
		}

		if err != nil {
			return nil, err
		}
	}

	if indent != "" {
		return json.MarshalIndent(pd, "", indent)
	}

	return json.Marshal(pd)
}
261477
func (obj *GenericBookmark) Apply(ctx context.Context) (bool, error) {
	result := &struct {
		Success bool	`json:"qSuccess"`
	} {}
	err := obj.rpc(ctx, "Apply", result)
	return result.Success, err 
}
37042
func (format *MetadataCopy) ApplyFormatter(msg *core.Message) error {

	if len(format.metaDataKeys) > 0 {
		// DEPRECATED
		// This codepath will be removed in 0.6
		meta := msg.GetMetadata()
		data := format.GetAppliedContent(msg)

		for _, key := range format.metaDataKeys {
			bufferCopy := make([]byte, len(data))
			copy(bufferCopy, data)
			meta.SetValue(key, bufferCopy)
		}
		return nil
	}

	getSourceData := core.GetAppliedContentGetFunction(format.key)
	srcData := getSourceData(msg)

	cloneSrcData := make([]byte, len(srcData))
	copy(cloneSrcData, srcData)

	switch format.mode {
	case metadataCopyModeReplace:
		format.SetAppliedContent(msg, cloneSrcData)

	case metadataCopyModePrepend:
		dstData := format.GetAppliedContent(msg)
		if len(format.separator) != 0 {
			cloneSrcData = append(cloneSrcData, format.separator...)
		}
		format.SetAppliedContent(msg, append(cloneSrcData, dstData...))

	case metadataCopyModeAppend:
		dstData := format.GetAppliedContent(msg)
		if len(format.separator) != 0 {
			dstData = append(dstData, format.separator...)
		}
		format.SetAppliedContent(msg, append(dstData, cloneSrcData...))
	}

	return nil
}
675871
func (ctx *Context) JSONIndent(obj interface{}, prefix, indent string) *Context {
	data, err := json.MarshalIndent(obj, prefix, indent)
	if err == nil {
		fmt.Fprint(ctx.Writer(), string(data))
	}
	return ctx
}
432614
func (b *bulkVersionEdit) apply(base *version, icmp db.Comparer) (*version, error) {
	v := new(version)
	for level := range v.files {
		combined := [2][]fileMetadata{
			nil,
			b.added[level],
		}
		if base != nil {
			combined[0] = base.files[level]
		}
		n := len(combined[0]) + len(combined[1])
		if n == 0 {
			continue
		}
		v.files[level] = make([]fileMetadata, 0, n)
		dmap := b.deleted[level]

		for _, ff := range combined {
			for _, f := range ff {
				if dmap != nil && dmap[f.fileNum] {
					continue
				}
				v.files[level] = append(v.files[level], f)
			}
		}

		// TODO: base.files[level] is already sorted. Instead of appending
		// b.addFiles[level] to the end and sorting afterwards, it might be more
		// efficient to sort b.addFiles[level] and then merge the two sorted slices.
		if level == 0 {
			sort.Sort(byFileNum(v.files[level]))
		} else {
			sort.Sort(bySmallest{v.files[level], icmp})
		}
	}
	if err := v.checkOrdering(icmp); err != nil {
		return nil, fmt.Errorf("leveldb: internal error: %v", err)
	}
	v.updateCompactionScore()
	return v, nil
}
426218
func (ce *CoordinatesElement) WriteIndent(w io.Writer, prefix, indent string) error {
	return write(w, prefix, indent, ce)
}
773924
func ApplyString(ch *Changeset, field string, fn func(string) string) {
	if val, ok := ch.changes[field]; ok && val != nil && ch.types[field].Kind() == reflect.String {
		ch.changes[field] = fn(val.(string))
	}
}
137555
func (r IndentedJSON) Render(w http.ResponseWriter) error {
	r.WriteContentType(w)
	jsonBytes, err := json.MarshalIndent(r.Data, "", "    ")
	if err != nil {
		return err
	}
	_, err = w.Write(jsonBytes)
	return err
}
542352
func (rule *Rule) indent() string {
	result := ""

	for i := 0; i < ((rule.EmbedLevel + 1) * indentSpace); i++ {
		result += " "
	}

	return result
}
80575
func (format *SplitToJSON) ApplyFormatter(msg *core.Message) error {
	components := bytes.Split(format.GetAppliedContent(msg), format.token)
	maxIdx := tmath.MinI(len(format.keys), len(components))
	jsonData := ""

	switch {
	case maxIdx == 0:
	case maxIdx == 1:
		jsonData = fmt.Sprintf("{%s:\"%s\"}", format.keys[0], components[0])
	default:
		for i := 0; i < maxIdx; i++ {
			key := tstrings.EscapeJSON(format.keys[i])
			value := string(components[i])
			if isJSON, _, _ := tstrings.IsJSON(components[i]); !format.keepJSON || !isJSON {
				value = "\"" + tstrings.EscapeJSON(value) + "\""
			}

			switch {
			case i == 0:
				jsonData = fmt.Sprintf("{\"%s\":%s", key, value)
			case i == maxIdx-1:
				jsonData = fmt.Sprintf("%s,\"%s\":%s}", jsonData, key, value)
			default:
				jsonData = fmt.Sprintf("%s,\"%s\":%s", jsonData, key, value)
			}
		}
	}

	format.SetAppliedContent(msg, []byte(jsonData))
	return nil
}
883371
func Indent(spaces, str cty.Value) (cty.Value, error) {
	return IndentFunc.Call([]cty.Value{spaces, str})
}
800762
func indent(s string, n int) string {
	i := strings.Repeat("  ", n)
	return i + strings.Replace(s, "\n", "\n"+i, -1)
}
553628
func Indent(s, prefix string) string {
	return string(IndentBytes([]byte(s), []byte(prefix)))
}
547889
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
	b, err := Marshal(v)
	if err != nil {
		return nil, err
	}
	if !isatty.IsTerminal(os.Stdout.Fd()) {
		return b, err
	}
	var buf bytes.Buffer
	err = Indent(&buf, b, prefix, indent)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
399138
func (u *Update) ApplyPatch(patchType PatchType) *Update {
	u.PatchType = patchType
	return u
}
1299956
func (enc *Encoder) SetIndent(prefix, indent string) {
	enc.indentPrefix = prefix
	enc.indentValue = indent
}
152737
func (format *Identifier) ApplyFormatter(msg *core.Message) error {
	format.SetAppliedContent(msg, format.hash(msg))
	return nil
}