Documentation ¶
Overview ¶
Package mem provides the mem.RO type that allows you to cheaply pass & access either a read-only []byte or a string.
Index ¶
- func Append(dest []byte, m RO) []byte
- func Contains(m, substr RO) bool
- func ContainsFold(s, substr RO) bool
- func DecodeLastRune(m RO) (r rune, size int)
- func DecodeRune(m RO) (r rune, size int)
- func EqualFold(m, m2 RO) bool
- func FullRune(m RO) bool
- func HasPrefix(m, prefix RO) bool
- func HasPrefixFold(s, prefix RO) bool
- func HasSuffix(m, suffix RO) bool
- func HasSuffixFold(s, suffix RO) bool
- func Index(m, substr RO) int
- func IndexByte(m RO, c byte) int
- func LastIndex(m, substr RO) int
- func LastIndexByte(m RO, c byte) int
- func ParseFloat(m RO, bitSize int) (float64, error)
- func ParseInt(m RO, base, bitSize int) (int64, error)
- func ParseUint(m RO, base, bitSize int) (uint64, error)
- func RuneCount(m RO) int
- func ValidUTF8(m RO) bool
- type RO
- func AppendFields(dst []RO, m RO) []RO
- func AppendFieldsFunc(dst []RO, m RO, f func(rune) bool) []RO
- func B(b []byte) RO
- func Cut(m, sep RO) (before, after RO, found bool)
- func CutPrefix(m, prefix RO) (after RO, found bool)
- func CutSuffix(m, suffix RO) (before RO, found bool)
- func S(s string) RO
- func TrimCutset(m, cutset RO) RO
- func TrimFunc(m RO, f func(rune) bool) RO
- func TrimLeftCutset(m, cutset RO) RO
- func TrimLeftFunc(m RO, f func(rune) bool) RO
- func TrimPrefix(m, prefix RO) RO
- func TrimRightCutset(m, cutset RO) RO
- func TrimRightFunc(m RO, f func(rune) bool) RO
- func TrimSpace(m RO) RO
- func TrimSuffix(m, suffix RO) RO
- func (r RO) At(i int) byte
- func (r RO) Copy(dest []byte) int
- func (r RO) Equal(r2 RO) bool
- func (r RO) EqualBytes(b []byte) bool
- func (r RO) EqualString(s string) bool
- func (r RO) Len() int
- func (r RO) Less(r2 RO) bool
- func (r RO) MapHash() uint64
- func (r RO) Slice(from, to int) RO
- func (r RO) SliceFrom(from int) RO
- func (r RO) SliceTo(to int) RO
- func (r RO) StringCopy() string
- type Reader
- func (r *Reader) Len() int
- func (r *Reader) Read(b []byte) (int, error)
- func (r *Reader) ReadAt(b []byte, off int64) (int, error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadRune() (ch rune, size int, err error)
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- func (r *Reader) Size() int64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsFold ¶
ContainsFold is like Contains but uses Unicode case-folding for a case insensitive substring search.
func DecodeLastRune ¶
DecodeLastRune unpacks the last UTF-8 encoding in m and returns the rune and its width in bytes. If m is empty it returns (utf8.RuneError, 0). Otherwise, if the encoding is invalid, it returns (utf8.RuneError, 1). Both are impossible results for correct, non-empty UTF-8.
An encoding is invalid if it is incorrect UTF-8, encodes a rune that is out of range, or is not the shortest possible UTF-8 encoding for the value. No other validation is performed.
func DecodeRune ¶
DecodeRune unpacks the first UTF-8 encoding in m and returns the rune and its width in bytes. If m is empty it returns (utf8.RuneError, 0). Otherwise, if the encoding is invalid, it returns (utf8.RuneError, 1). Both are impossible results for correct, non-empty UTF-8.
An encoding is invalid if it is incorrect UTF-8, encodes a rune that is out of range, or is not the shortest possible UTF-8 encoding for the value. No other validation is performed.
func EqualFold ¶
EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding, which is a more general form of case-insensitivity.
func FullRune ¶
FullRune reports whether the bytes in m begin with a full UTF-8 encoding of a rune. An invalid encoding is considered a full Rune since it will convert as a width-1 error rune.
func HasPrefixFold ¶
HasPrefixFold is like HasPrefix but uses Unicode case-folding, matching case insensitively.
func HasSuffixFold ¶
HasSuffixFold is like HasSuffix but uses Unicode case-folding, matching case insensitively.
func Index ¶
Index returns the index of the first instance of substr in m, or -1 if substr is not present in m.
func IndexByte ¶
IndexByte returns the index of the first instance of c in m, or -1 if c is not present in m.
func LastIndex ¶
LastIndex returns the index of the last instance of substr in m, or -1 if substr is not present in m.
func LastIndexByte ¶
LastIndexByte returns the index into m of the last Unicode code point satisfying f(c), or -1 if none do.
func ParseFloat ¶
ParseFloat returns a float from, using strconv.ParseFloat.
Types ¶
type RO ¶
type RO struct {
// contains filtered or unexported fields
}
RO is a read-only view of some bytes of memory. It may be be backed by a string or []byte. Notably, unlike a string, the memory is not guaranteed to be immutable. While the length is fixed, the underlying bytes might change if interleaved with code that's modifying the underlying memory.
RO is a value type that's the same size of a Go string. Its various methods should inline & compile to the equivalent operations working on a string or []byte directly.
Unlike a Go string, RO is not 'comparable' (it can't be a map key or support ==). Use its Equal method to compare. This is done so an RO backed by a later-mutating []byte doesn't break invariants in Go's map implementation.
func AppendFields ¶
AppendFields is like strings.Fields, but is append-like and uses a mem.RO instead of a string.
func AppendFieldsFunc ¶
AppendFieldsFunc is like strings.FieldsFunc, but is append-like and uses a mem.RO instead of a string.
func B ¶
B returns a read-only view of the byte slice b.
The compiler should compile this call to nothing. Think of it as a free type conversion. The returned value is actually smaller than a []byte though (16 bytes instead of 24 bytes on 64-bit architectures).
func S ¶
S returns a read-only view of the string s.
The compiler should compile this call to nothing. Think of it as a free type conversion. The returned RO view is the same size as a string.
func TrimCutset ¶
TrimCutset returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func TrimFunc ¶
TrimFunc returns a slice of m with all leading and trailing Unicode code points c satisfying f(c) removed.
func TrimLeftCutset ¶
TrimLeftCutset returns a slice of m with all leading Unicode code points contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
func TrimLeftFunc ¶
TrimLeftFunc returns a slice of m with all leading Unicode code points c satisfying f(c) removed.
func TrimPrefix ¶
TrimPrefix returns m without the provided leading prefix. If m doesn't start with prefix, m is returned unchanged.
func TrimRightCutset ¶
TrimRightCutset returns a slice of m with all trailing Unicode code points contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
func TrimRightFunc ¶
TrimRightFunc returns a slice of m with all trailing Unicode code points c satisfying f(c) removed.
func TrimSpace ¶
TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
func TrimSuffix ¶
TrimSuffix returns m without the provided trailing suffix. If m doesn't end with suffix, m is returned unchanged.
func (RO) Copy ¶
Copy copies up to len(dest) bytes into dest from r and returns the number of bytes copied, the min(r.Len(), len(dest)).
func (RO) EqualBytes ¶
EqualBytes reports whether r and b are the same length and contain the same bytes.
func (RO) EqualString ¶
EqualString reports whether r and s are the same length and contain the same bytes.
func (RO) MapHash ¶
MapHash returns a hash of r's contents using runtime/maphash. The hash is stable for the lifetime of a process.
func (RO) StringCopy ¶
StringCopy returns m's contents in a newly allocated string.