func (i *Interpolator) InterpWriter(w io.Writer, formatBytes []byte, args ...interface{}) error {
	buf := bytes.NewBuffer(formatBytes)
	for {
		untilDelim, err := readBytesUntilUnescDelim(buf, '%')
		if err == io.EOF {
			_, err = w.Write(untilDelim)
			return err
		}
		_, err = w.Write(untilDelim)
		if err != nil {
			return err
		}
		rawFormat, err := readBytesUntilUnescDelim(buf, ';')
		if err == io.EOF {
			return errIncompleteFormatString
		}
		if len(rawFormat) == 1 && rawFormat[0] == '%' {
			_, err = w.Write([]byte("%"))
			if err != nil {
				return err
			}
			continue
		}
		formatSpecs := splitHonoringEscaping(bytes.NewBuffer(rawFormat), '|')
		writer := NewWriterStack(w)
		for j := len(formatSpecs) - 1; j >= 1; j-- {
			encoder, formatArgs, err := i.parseEncoder(formatSpecs[j])
			if err != nil {
				return err
			}
			err = writer.Push(encoder, formatArgs)
			if err != nil {
				return err
			}
		}
		thisFormatter := formatSpecs[0]
		formatChunks := bytes.SplitN(thisFormatter, []byte(":"), 2)
		format := string(formatChunks[0])
		var formatArgs []byte
		if len(formatChunks) > 1 {
			formatArgs = formatChunks[1]
		}
		formatter := i.formatters[format]
		encoder := i.encoders[format]
		if formatter == nil && encoder == nil {
			return errUnknownFormatter(format)
		}
		var thisArg interface{}
		if len(args) > 0 {
			thisArg = args[0]
			args = args[1:]
		} else {
			thisArg = NotGiven
		}
		if formatter != nil {
			err = formatter(writer, thisArg, formatArgs)
			err2 := writer.Finish()
			if err != nil {
				return err
			}
			if err2 != nil {
				return err2
			}
		}
		if encoder != nil {
			err = writer.Push(encoder, formatArgs)
			if err != nil {
				return err
			}
			err = i.writeArgument(thisArg, writer)
			err2 := writer.Finish()
			if err != nil {
				return err
			}
			if err2 != nil {
				return err2
			}
		}
	}
}
InterpWriter interpolates the format []byte into the passed io.Writer.
package strinterp
import (
	"bytes"
	"io"
)
type Interpolator struct {
	formatters map[string]Formatter
	encoders   map[string]Encoder
}
type Encoder func(io.Writer, []byte) (io.Writer, error)
func NewInterpolator() *Interpolator {
	return &Interpolator{
		map[string]Formatter{},
		map[string]Encoder{
			"RAW": raw,
		},
	}
}
func NewDefaultInterpolator() *Interpolator {
	return &Interpolator{
		map[string]Formatter{
			"json": JSON,
		},
		map[string]Encoder{
			"RAW":    raw,
			"cdata":  CDATA,
			"base64": Base64,
		},
	}
}
func (i *Interpolator) AddFormatter(format string, handler Formatter) error {
	if i.formatters[format] != nil {
		return errAlreadyExists(format)
	}
	if i.encoders[format] != nil {
		return errAlreadyExists(format)
	}
	i.formatters[format] = handler
	return nil
}
func (i *Interpolator) AddEncoder(format string, handler Encoder) error {
	if i.formatters[format] != nil {
		return errAlreadyExists(format)
	}
	if i.encoders[format] != nil {
		return errAlreadyExists(format)
	}
	i.encoders[format] = handler
	return nil
}
func (i *Interpolator) InterpStr(format string, args ...interface{}) (string, error) {
	buf := new(bytes.Buffer)
	err := i.InterpWriter(buf, []byte(format), args...)
	if err != nil {
		return "", err
	}
	return buf.String(), nil
}