bytes

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 4 Imported by: 9

README

drop-in replacement for standard "bytes" library

contains alternative Buffer implementation that provides direct access to the underlying byte-slice, with some interesting alternative struct methods. provides no safety guards, if you pass bad values it will blow up in your face...

and alternative ToUpper() and ToLower() implementations that use lookup tables for improved performance

provides direct call-throughs to most of the "bytes" library functions to facilitate this being a direct drop-in. in some time, i may offer alternative implementations for other functions too

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString returns byte slice cast to string via the "unsafe" package

func Compare

func Compare(b, s []byte) int

Compare is a direct call-through to standard library bytes.Compare()

func Contains

func Contains(b, s []byte) bool

Contains is a direct call-through to standard library bytes.Contains()

func Copy

func Copy(b []byte) []byte

Copy returns a new copy of slice b, does NOT maintain nil values

func Equal

func Equal(b, s []byte) bool

Equal is a direct call-through to standard library bytes.Equal()

func EqualFold

func EqualFold(b, s []byte) bool

EqualFold is a direct call-through to standard library bytes.EqualFold()

func Fields

func Fields(b []byte) [][]byte

Fields is a direct call-through to standard library bytes.Fields()

func FieldsFunc

func FieldsFunc(b []byte, fn func(rune) bool) [][]byte

FieldsFunc is a direct call-through to standard library bytes.FieldsFunc()

func HasBytePrefix

func HasBytePrefix(b []byte, c byte) bool

HasBytePrefix returns whether b has the provided byte prefix

func HasByteSuffix

func HasByteSuffix(b []byte, c byte) bool

HasByteSuffix returns whether b has the provided byte suffix

func HasPrefix

func HasPrefix(b, s []byte) bool

HasPrefix is a direct call-through to standard library bytes.HasPrefix()

func HasSuffix

func HasSuffix(b, s []byte) bool

HasSuffix is a direct call-through to standard library bytes.HasSuffix()

func Index

func Index(b, s []byte) int

Index is a direct call-through to standard library bytes.Index()

func IndexAny

func IndexAny(b []byte, s string) int

IndexAny is a direct call-through to standard library bytes.IndexAny()

func IndexByte

func IndexByte(b []byte, c byte) int

IndexByte is a direct call-through to standard library bytes.IndexByte()

func IndexFunc

func IndexFunc(b []byte, fn func(rune) bool) int

IndexFunc is a direct call-through to standard library bytes.IndexFunc()

func IndexRune

func IndexRune(b []byte, r rune) int

IndexRune is a direct call-through to standard library bytes.IndexRune()

func LastIndex

func LastIndex(b, s []byte) int

LastIndex is a direct call-through to standard library bytes.LastIndex()

func LastIndexAny

func LastIndexAny(b []byte, s string) int

LastIndexAny is a direct call-through to standard library bytes.LastIndexAny()

func LastIndexByte

func LastIndexByte(b []byte, c byte) int

LastIndexByte is a direct call-through to standard library bytes.LastIndexByte()

func LastIndexFunc

func LastIndexFunc(b []byte, fn func(rune) bool) int

LastIndexFunc is a direct call-through to standard library bytes.LastIndexFunc()

func NewReader

func NewReader(b []byte) *bytes.Reader

NewReader is a direct call-through to standard library bytes.NewReader()

func Replace

func Replace(b, s, r []byte, c int) []byte

Replace is a direct call-through to standard library bytes.Replace()

func ReplaceAll

func ReplaceAll(b, s, r []byte) []byte

ReplaceAll is a direct call-through to standard library bytes.ReplaceAll()

func Split

func Split(b, s []byte) [][]byte

Split is a direct call-through to standard library bytes.Split()

func SplitAfter

func SplitAfter(b, s []byte) [][]byte

SplitAfter is a direct call-through to standard library bytes.SplitAfter()

func SplitAfterN

func SplitAfterN(b, s []byte, c int) [][]byte

SplitAfterN is a direct call-through to standard library bytes.SplitAfterN()

func SplitN

func SplitN(b, s []byte, c int) [][]byte

SplitN is a direct call-through to standard library bytes.SplitN()

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes returns the string cast to string via the "unsafe" and "reflect" packages

func ToLower

func ToLower(b []byte)

ToLower offers a faster ToLower implementation using a lookup table

func ToUpper

func ToUpper(b []byte)

ToUpper offers a faster ToUpper implementation using a lookup table

func TrimBytePrefix

func TrimBytePrefix(b []byte, c byte) []byte

HasBytePrefix returns b without the provided leading byte

func TrimByteSuffix

func TrimByteSuffix(b []byte, c byte) []byte

TrimByteSuffix returns b without the provided trailing byte

func TrimPrefix

func TrimPrefix(b, s []byte) []byte

TrimPrefix is a direct call-through to standard library bytes.TrimPrefix()

func TrimSuffix

func TrimSuffix(b, s []byte) []byte

TrimSuffix is a direct call-through to standard library bytes.TrimSuffix()

Types

type Buffer

type Buffer struct {
	B []byte
}

Buffer is a very simple buffer implementation that allows access to and reslicing of the underlying byte slice.

func NewBuffer

func NewBuffer(b []byte) Buffer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Delete

func (b *Buffer) Delete(start int64, size int)

func (*Buffer) DeleteByte

func (b *Buffer) DeleteByte(index int)

func (*Buffer) Grow

func (b *Buffer) Grow(size int)

func (*Buffer) Guarantee

func (b *Buffer) Guarantee(size int)

func (*Buffer) Insert

func (b *Buffer) Insert(index int64, p []byte)

func (*Buffer) InsertByte

func (b *Buffer) InsertByte(index int64, c byte)

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) Shift

func (b *Buffer) Shift(start int64, size int)

func (*Buffer) ShiftByte

func (b *Buffer) ShiftByte(index int)

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) StringPtr

func (b *Buffer) StringPtr() string

func (*Buffer) Truncate

func (b *Buffer) Truncate(size int)

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

func (*Buffer) WriteAt

func (b *Buffer) WriteAt(p []byte, start int64) (int, error)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) (int, error)

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (int, error)

func (*Buffer) WriteStringAt

func (b *Buffer) WriteStringAt(s string, start int64) (int, error)

type Bytes

type Bytes interface {
	// Bytes returns the byte slice content
	Bytes() []byte

	// String returns byte slice cast directly to string, this
	// will cause an allocation but comes with the safety of
	// being an immutable Go string
	String() string

	// StringPtr returns byte slice cast to string via the unsafe
	// package. This comes with the same caveats of accessing via
	// .Bytes() in that the content is liable change and is NOT
	// immutable, despite being a string type
	StringPtr() string
}

Bytes defines a standard way of retrieving the content of a byte buffer of some-kind.

func ToBytes

func ToBytes(b []byte) Bytes

ToBytes casts the provided byte slice as the simplest possible Bytes interface implementation

Jump to

Keyboard shortcuts

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