detect

package
v0.0.0-...-15c7053 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package detect provides types that perform string detection and replacement on byte streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashModuloReader

type HashModuloReader struct {
	// contains filtered or unexported fields
}

HashModuloReader wraps an underlying reader to replace any occurrences of a search string with a same-sized replacement string and record the offsets of those occurrences.

func NewHashModuloReader

func NewHashModuloReader(old, new string, r io.Reader) *HashModuloReader

NewHashModuloReader returns a new HashModuloReader that reads from r and replaces old with new. NewHashModuloReader panics if len(old) != len(new).

func (*HashModuloReader) Offsets

func (hmr *HashModuloReader) Offsets() []int64

Offsets returns a list of the offsets in the reader where the search string has occurred in ascending order.

func (*HashModuloReader) Read

func (hmr *HashModuloReader) Read(p []byte) (n int, err error)

Read implements io.Reader. Read may read more bytes from the underlying reader than the number of bytes returned to the caller in order to determine whether the bytes are part of the reader's search string.

type RefFinder

type RefFinder struct {
	// contains filtered or unexported fields
}

A RefFinder records which elements in a set of search strings occur in a byte stream.

func NewRefFinder

func NewRefFinder(search iter.Seq[string]) *RefFinder

NewRefFinder returns a new RefFinder that searches for strings from the given sequence.

func (*RefFinder) Found

func (rf *RefFinder) Found() *sets.Sorted[string]

Found returns the set of references found in the written content so far.

func (*RefFinder) Write

func (rf *RefFinder) Write(p []byte) (int, error)

Write implements io.Writer by recording any occurrences of the strings the RefFinder is searching for that are found in p. The bytes written to the RefFinder are considered a contiguous stream: occurrences may span multiple calls to Write or RefFinder.WriteString.

func (*RefFinder) WriteString

func (rf *RefFinder) WriteString(s string) (int, error)

WriteString implements io.StringWriter by recording any occurrences of the strings the RefFinder is searching for that are found in s. The bytes written to the RefFinder are considered a contiguous stream: occurrences may span multiple calls to WriteString or RefFinder.Write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL