mem
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
go4.org/mem
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¶
funcContainsFold¶
ContainsFold is like Contains but uses Unicode case-folding for a case insensitive substring search.
funcDecodeLastRune¶
DecodeLastRune unpacks the last UTF-8 encoding in m and returns the rune andits width in bytes. If m is empty it returns (utf8.RuneError, 0). Otherwise, ifthe encoding is invalid, it returns (utf8.RuneError, 1). Both are impossibleresults for correct, non-empty UTF-8.
An encoding is invalid if it is incorrect UTF-8, encodes a rune that isout of range, or is not the shortest possible UTF-8 encoding for thevalue. No other validation is performed.
funcDecodeRune¶
DecodeRune unpacks the first UTF-8 encoding in m and returns the rune andits width in bytes. If m is empty it returns (utf8.RuneError, 0). Otherwise, ifthe encoding is invalid, it returns (utf8.RuneError, 1). Both are impossibleresults for correct, non-empty UTF-8.
An encoding is invalid if it is incorrect UTF-8, encodes a rune that isout of range, or is not the shortest possible UTF-8 encoding for thevalue. No other validation is performed.
funcEqualFold¶
EqualFold reports whether s and t, interpreted as UTF-8 strings,are equal under Unicode case-folding, which is a more general formof case-insensitivity.
funcFullRune¶
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.
funcHasPrefixFold¶
HasPrefixFold is like HasPrefix but uses Unicode case-folding,matching case insensitively.
funcHasSuffixFold¶
HasSuffixFold is like HasSuffix but uses Unicode case-folding,matching case insensitively.
funcIndex¶
Index returns the index of the first instance of substr in m, or -1if substr is not present in m.
funcIndexByte¶
IndexByte returns the index of the first instance of c in m, or -1if c is not present in m.
funcLastIndex¶
LastIndex returns the index of the last instance of substr in m, or-1 if substr is not present in m.
funcLastIndexByte¶
LastIndexByte returns the index into m of the last Unicode codepoint satisfying f(c), or -1 if none do.
funcParseFloat¶
ParseFloat returns a float from, using strconv.ParseFloat.
Types¶
typeRO¶
type RO struct {// contains filtered or unexported fields}RO is a read-only view of some bytes of memory. It may be be backedby a string or []byte. Notably, unlike a string, the memory is notguaranteed to be immutable. While the length is fixed, theunderlying bytes might change if interleaved with code that'smodifying the underlying memory.
RO is a value type that's the same size of a Go string. Its variousmethods should inline & compile to the equivalent operationsworking on a string or []byte directly.
Unlike a Go string, RO is not 'comparable' (it can't be a map keyor support ==). Use its Equal method to compare. This is done so anRO backed by a later-mutating []byte doesn't break invariants inGo's map implementation.
funcAppendFields¶
AppendFields is like strings.Fields, but is append-like and uses a mem.RO instead of a string.
funcAppendFieldsFunc¶
AppendFieldsFunc is like strings.FieldsFunc, but is append-like and uses a mem.RO instead of a string.
funcB¶
B returns a read-only view of the byte slice b.
The compiler should compile this call to nothing. Think of it as afree type conversion. The returned value is actually smaller than a[]byte though (16 bytes instead of 24 bytes on 64-bitarchitectures).
funcS¶
S returns a read-only view of the string s.
The compiler should compile this call to nothing. Think of it as afree type conversion. The returned RO view is the same size as astring.
funcTrimCutset¶
TrimCutset returns a slice of the string s with all leading andtrailing Unicode code points contained in cutset removed.
funcTrimFunc¶
TrimFunc returns a slice of m with all leading and trailing Unicodecode points c satisfying f(c) removed.
funcTrimLeftCutset¶
TrimLeftCutset returns a slice of m with all leading Unicode codepoints contained in cutset removed.
To remove a prefix, use TrimPrefix instead.
funcTrimLeftFunc¶
TrimLeftFunc returns a slice of m with all leading Unicodecode points c satisfying f(c) removed.
funcTrimPrefix¶
TrimPrefix returns m without the provided leading prefix.If m doesn't start with prefix, m is returned unchanged.
funcTrimRightCutset¶
TrimRightCutset returns a slice of m with all trailing Unicode codepoints contained in cutset removed.
To remove a suffix, use TrimSuffix instead.
funcTrimRightFunc¶
TrimRightFunc returns a slice of m with all trailing Unicodecode points c satisfying f(c) removed.
funcTrimSpace¶
TrimSpace returns a slice of the string s, with all leading andtrailing white space removed, as defined by Unicode.
funcTrimSuffix¶
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 thenumber of bytes copied, the min(r.Len(), len(dest)).
func (RO)EqualBytes¶
EqualBytes reports whether r and b are the same length and containthe same bytes.
func (RO)EqualString¶
EqualString reports whether r and s are the same length and containthe 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.