Movatterモバイル変換


[0]ホーム

URL:


mem

packagemodule
v0.0.0-...-ae6ca99Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License:Apache-2.0Imports:7Imported by:168

Details

Repository

github.com/go4org/mem

Links

README

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

Constants

This section is empty.

Variables

This section is empty.

Functions

funcAppend

func Append(dest []byte, mRO) []byte

Append appends m to dest, and returns the possibly-reallocateddest.

funcContains

func Contains(m, substrRO)bool

Contains reports whether substr is within m.

funcContainsFold

func ContainsFold(s, substrRO)bool

ContainsFold is like Contains but uses Unicode case-folding for a case insensitive substring search.

funcDecodeLastRune

func DecodeLastRune(mRO) (rrune, sizeint)

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

func DecodeRune(mRO) (rrune, sizeint)

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

func EqualFold(m, m2RO)bool

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

func FullRune(mRO)bool

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.

funcHasPrefix

func HasPrefix(m, prefixRO)bool

HasPrefix reports whether m starts with prefix.

funcHasPrefixFold

func HasPrefixFold(s, prefixRO)bool

HasPrefixFold is like HasPrefix but uses Unicode case-folding,matching case insensitively.

funcHasSuffix

func HasSuffix(m, suffixRO)bool

HasSuffix reports whether m ends with suffix.

funcHasSuffixFold

func HasSuffixFold(s, suffixRO)bool

HasSuffixFold is like HasSuffix but uses Unicode case-folding,matching case insensitively.

funcIndex

func Index(m, substrRO)int

Index returns the index of the first instance of substr in m, or -1if substr is not present in m.

funcIndexByte

func IndexByte(mRO, cbyte)int

IndexByte returns the index of the first instance of c in m, or -1if c is not present in m.

funcLastIndex

func LastIndex(m, substrRO)int

LastIndex returns the index of the last instance of substr in m, or-1 if substr is not present in m.

funcLastIndexByte

func LastIndexByte(mRO, cbyte)int

LastIndexByte returns the index into m of the last Unicode codepoint satisfying f(c), or -1 if none do.

funcParseFloat

func ParseFloat(mRO, bitSizeint) (float64,error)

ParseFloat returns a float from, using strconv.ParseFloat.

funcParseInt

func ParseInt(mRO, base, bitSizeint) (int64,error)

ParseInt returns a signed integer from m, using strconv.ParseInt.

funcParseUint

func ParseUint(mRO, base, bitSizeint) (uint64,error)

ParseUint returns a unsigned integer from m, using strconv.ParseUint.

funcRuneCount

func RuneCount(mRO)int

RuneCount returns the number of UTF-8 encoded runes in m. Erroneous and shortencodings are treated as single runes of width 1 byte.

funcValidUTF8

func ValidUTF8(mRO)bool

ValidUTF8 reports whether m consists entirely of valid UTF-8 encoded runes.

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

func AppendFields(dst []RO, mRO) []RO

AppendFields is like strings.Fields, but is append-like and uses a mem.RO instead of a string.

funcAppendFieldsFunc

func AppendFieldsFunc(dst []RO, mRO, f func(rune)bool) []RO

AppendFieldsFunc is like strings.FieldsFunc, but is append-like and uses a mem.RO instead of a string.

funcB

func B(b []byte)RO

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).

funcCut

func Cut(m, sepRO) (before, afterRO, foundbool)

Cut works like strings.Cut, but takes and returns ROs.

funcCutPrefix

func CutPrefix(m, prefixRO) (afterRO, foundbool)

CutPrefix works like strings.CutPrefix, but takes and returns ROs.

funcCutSuffix

func CutSuffix(m, suffixRO) (beforeRO, foundbool)

CutSuffix works like strings.CutSuffix, but takes and returns ROs.

funcS

func S(sstring)RO

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

func TrimCutset(m, cutsetRO)RO

TrimCutset returns a slice of the string s with all leading andtrailing Unicode code points contained in cutset removed.

funcTrimFunc

func TrimFunc(mRO, f func(rune)bool)RO

TrimFunc returns a slice of m with all leading and trailing Unicodecode points c satisfying f(c) removed.

funcTrimLeftCutset

func TrimLeftCutset(m, cutsetRO)RO

TrimLeftCutset returns a slice of m with all leading Unicode codepoints contained in cutset removed.

To remove a prefix, use TrimPrefix instead.

funcTrimLeftFunc

func TrimLeftFunc(mRO, f func(rune)bool)RO

TrimLeftFunc returns a slice of m with all leading Unicodecode points c satisfying f(c) removed.

funcTrimPrefix

func TrimPrefix(m, prefixRO)RO

TrimPrefix returns m without the provided leading prefix.If m doesn't start with prefix, m is returned unchanged.

funcTrimRightCutset

func TrimRightCutset(m, cutsetRO)RO

TrimRightCutset returns a slice of m with all trailing Unicode codepoints contained in cutset removed.

To remove a suffix, use TrimSuffix instead.

funcTrimRightFunc

func TrimRightFunc(mRO, f func(rune)bool)RO

TrimRightFunc returns a slice of m with all trailing Unicodecode points c satisfying f(c) removed.

funcTrimSpace

func TrimSpace(mRO)RO

TrimSpace returns a slice of the string s, with all leading andtrailing white space removed, as defined by Unicode.

funcTrimSuffix

func TrimSuffix(m, suffixRO)RO

TrimSuffix returns m without the provided trailing suffix.If m doesn't end with suffix, m is returned unchanged.

func (RO)At

func (rRO) At(iint)byte

At returns r[i].

func (RO)Copy

func (rRO) Copy(dest []byte)int

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)Equal

func (rRO) Equal(r2RO)bool

Equal reports whether r and r2 are the same length and contain thesame bytes.

func (RO)EqualBytes

func (rRO) EqualBytes(b []byte)bool

EqualBytes reports whether r and b are the same length and containthe same bytes.

func (RO)EqualString

func (rRO) EqualString(sstring)bool

EqualString reports whether r and s are the same length and containthe same bytes.

func (RO)Len

func (rRO) Len()int

Len returns len(r).

func (RO)Less

func (rRO) Less(r2RO)bool

Less reports whether r < r2.

func (RO)MapHash

func (rRO) MapHash()uint64

MapHash returns a hash of r's contents using runtime/maphash.The hash is stable for the lifetime of a process.

func (RO)Slice

func (rRO) Slice(from, toint)RO

Slice returns r[from:to].

func (RO)SliceFrom

func (rRO) SliceFrom(fromint)RO

SliceFrom returns r[from:].

func (RO)SliceTo

func (rRO) SliceTo(toint)RO

SliceTo returns r[:to].

func (RO)StringCopy

func (rRO) StringCopy()string

StringCopy returns m's contents in a newly allocated string.

typeReader

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

Reader is like a bytes.Reader or strings.Reader.

funcNewReader

func NewReader(mRO) *Reader

NewReader returns a new Reader that reads from m.

func (*Reader)Len

func (r *Reader) Len()int

func (*Reader)Read

func (r *Reader) Read(b []byte) (int,error)

func (*Reader)ReadAt

func (r *Reader) ReadAt(b []byte, offint64) (int,error)

func (*Reader)ReadByte

func (r *Reader) ReadByte() (byte,error)

func (*Reader)ReadRune

func (r *Reader) ReadRune() (chrune, sizeint, errerror)

func (*Reader)Seek

func (r *Reader) Seek(offsetint64, whenceint) (int64,error)

func (*Reader)Size

func (r *Reader) Size()int64

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp