Documentation
¶
Index ¶
- func DoChainReplace(rp *Replacer) (int, error)
- func DoSequentialReplace(rp *Replacer) (int, error)
- type BytesReplacer
- type BytesReplacingReader
- func (r *BytesReplacingReader) GetOccurrences() int
- func (r *BytesReplacingReader) Read(p []byte) (int, error)
- func (r *BytesReplacingReader) Reset(r1 io.Reader, search1, replace1 []byte) *BytesReplacingReader
- func (r *BytesReplacingReader) ResetEx(r1 io.Reader, replacer BytesReplacer) *BytesReplacingReader
- func (r *BytesReplacingReader) SetBufferSize(newBufSize int)
- type Replacer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoChainReplace ¶
DoChainReplace does the replace operation with reader chaining, which is faster but more resource intensive.
func DoSequentialReplace ¶
DoSequentialReplace does the replace operation without reader chaining, which is slower but less resource intensive.
Types ¶
type BytesReplacer ¶
type BytesReplacer interface {
// GetSizingHints returns hints for BytesReplacingReader to do sizing estimate and allocation.
// Return values:
// - 1st: max search token len
// - 2nd: max replace token len
// - 3rd: max (search_len / replace_len) ratio that is less than 1,
// if none of the search/replace ratio is less than 1, then return a negative number.
// will only be called once during BytesReplacingReader initialization/reset.
GetSizingHints() (int, int, float64)
// BestIndex does token search for BytesReplacingReader.
// Return values:
// - 1st: index of the first found search token; -1, if not found;
// - 2nd: the found search token; ignored if not found;
// - 3rd: the matching replace token; ignored if not found;
BestIndex(buf []byte) (int, []byte, []byte)
}
BytesReplacer allows customization on how BytesReplacingReader does sizing estimate during initialization/reset and does search and replacement during the execution.
type BytesReplacingReader ¶
type BytesReplacingReader struct {
// contains filtered or unexported fields
}
BytesReplacingReader allows transparent replacement of a given token during read operation.
func NewBytesReplacingReader ¶
func NewBytesReplacingReader(r io.Reader, search, replace []byte) *BytesReplacingReader
NewBytesReplacingReader creates a new `*BytesReplacingReader` for a single pair of search:replace token replacement. `search` cannot be nil/empty. `replace` can.
func NewBytesReplacingReaderEx ¶
func NewBytesReplacingReaderEx(r io.Reader, replacer BytesReplacer) *BytesReplacingReader
NewBytesReplacingReaderEx creates a new `*BytesReplacingReader` for a given BytesReplacer customization.
func (*BytesReplacingReader) GetOccurrences ¶
func (r *BytesReplacingReader) GetOccurrences() int
func (*BytesReplacingReader) Read ¶
func (r *BytesReplacingReader) Read(p []byte) (int, error)
Read implements the `io.Reader` interface.
func (*BytesReplacingReader) Reset ¶
func (r *BytesReplacingReader) Reset(r1 io.Reader, search1, replace1 []byte) *BytesReplacingReader
Reset allows reuse of a previous allocated `*BytesReplacingReader` for buf allocation optimization. `search` cannot be nil/empty. `replace` can.
func (*BytesReplacingReader) ResetEx ¶
func (r *BytesReplacingReader) ResetEx(r1 io.Reader, replacer BytesReplacer) *BytesReplacingReader
ResetEx allows reuse of a previous allocated `*BytesReplacingReader` for buf allocation optimization.
func (*BytesReplacingReader) SetBufferSize ¶
func (r *BytesReplacingReader) SetBufferSize(newBufSize int)
SetBufferSize sets the buffer size of the current `*BytesReplacingReader`. If newBufSize is smaller than the current buffer, nothing is changed.
type Replacer ¶
type Replacer struct {
Config *replacerConfig
}
Replacer contains all of the methods needed to properly execute replace operations
func NewReplacer ¶
NewReplacer returns a new *Replacer type
func (*Replacer) NewMapping ¶
NewMapping maps a new oldString:newString []byte entry
func (*Replacer) NewStringMapping ¶
NewStringMapping maps a new oldString:newString string entry
func (*Replacer) Replace ¶
Replace does the replace operation with a concurrent (sequential) reader --> tmpfile model
func (*Replacer) ReplaceChained ¶
ReplaceChained does the replace operation with a chained reader model