helpers

package
v0.18.11 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsNonBMPCodePoint added in v0.17.11

func ContainsNonBMPCodePoint(text string) bool

func ContainsNonBMPCodePointUTF16 added in v0.17.11

func ContainsNonBMPCodePointUTF16(text []uint16) bool

This does "ContainsNonBMPCodePoint(UTF16ToString(text))" without any allocations

func DecodeWTF8Rune added in v0.17.11

func DecodeWTF8Rune(s string) (rune, int)

This is a clone of "utf8.DecodeRuneInString" that has been modified to decode using WTF-8 instead. See https://simonsapin.github.io/wtf-8/ for more info.

func EncodeStringAsPercentEscapedDataURL added in v0.17.11

func EncodeStringAsPercentEscapedDataURL(mimeType string, text string) (string, bool)

See "scripts/dataurl-escapes.html" for how this was derived

func EscapeClosingTag added in v0.17.11

func EscapeClosingTag(text string, slashTag string) string

func HashCombineString

func HashCombineString(seed uint32, text string) uint32

func IsInsideNodeModules

func IsInsideNodeModules(path string) bool

func MimeTypeByExtension

func MimeTypeByExtension(ext string) string

This is used instead of Go's built-in "mime.TypeByExtension" function because that function is broken on Windows: https://github.com/golang/go/issues/32350.

func PrettyPrintedStack added in v0.17.11

func PrettyPrintedStack() string

func QuoteForJSON added in v0.17.11

func QuoteForJSON(text string, asciiOnly bool) []byte

func QuoteSingle added in v0.17.11

func QuoteSingle(text string, asciiOnly bool) []byte

func StringArrayToQuotedCommaSeparatedString added in v0.17.11

func StringArrayToQuotedCommaSeparatedString(a []string) string

func StringArraysEqual added in v0.17.11

func StringArraysEqual(a []string, b []string) bool

func StringSlicesAreEqual added in v0.17.11

func StringSlicesAreEqual(a []string, b []string) bool

func StringToUTF16 added in v0.17.11

func StringToUTF16(text string) []uint16

func UTF16EqualsString added in v0.17.11

func UTF16EqualsString(text []uint16, str string) bool

Does "UTF16ToString(text) == str" without a temporary allocation

func UTF16EqualsUTF16 added in v0.17.11

func UTF16EqualsUTF16(a []uint16, b []uint16) bool

func UTF16ToString added in v0.17.11

func UTF16ToString(text []uint16) string

func UTF16ToStringWithValidation added in v0.17.11

func UTF16ToStringWithValidation(text []uint16) (string, uint16, bool)

Types

type BitSet

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

func NewBitSet

func NewBitSet(bitCount uint) BitSet

func (BitSet) Equals

func (bs BitSet) Equals(other BitSet) bool

func (BitSet) HasBit

func (bs BitSet) HasBit(bit uint) bool

func (BitSet) SetBit

func (bs BitSet) SetBit(bit uint)

func (BitSet) String

func (bs BitSet) String() string

type Joiner

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

This provides an efficient way to join lots of big string and byte slices together. It avoids the cost of repeatedly reallocating as the buffer grows by measuring exactly how big the buffer should be and then allocating once. This is a measurable speedup.

func (*Joiner) AddBytes

func (j *Joiner) AddBytes(data []byte)

func (*Joiner) AddString

func (j *Joiner) AddString(data string)

func (*Joiner) Contains

func (j *Joiner) Contains(s string, b []byte) bool

func (*Joiner) Done

func (j *Joiner) Done() []byte

func (*Joiner) EnsureNewlineAtEnd

func (j *Joiner) EnsureNewlineAtEnd()

func (*Joiner) LastByte

func (j *Joiner) LastByte() byte

func (*Joiner) Length

func (j *Joiner) Length() uint32

type Serializer added in v0.17.11

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

Each call to "Enter(i)" doesn't start until "Leave(i-1)" is called

func MakeSerializer added in v0.17.11

func MakeSerializer(count int) Serializer

func (*Serializer) Enter added in v0.17.11

func (s *Serializer) Enter(i int)

func (*Serializer) Leave added in v0.17.11

func (s *Serializer) Leave(i int)

type ThreadSafeWaitGroup added in v0.17.11

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

Go's "sync.WaitGroup" is not thread-safe. Specifically it's not safe to call "Add" concurrently with "Wait", which is problematic because we have a case where we would like to do that.

This is a simple alternative implementation of "sync.WaitGroup" that is thread-safe and that works for our purposes. We don't need to worry about multiple waiters so the implementation can be very simple.

func MakeThreadSafeWaitGroup added in v0.17.11

func MakeThreadSafeWaitGroup() *ThreadSafeWaitGroup

func (*ThreadSafeWaitGroup) Add added in v0.17.11

func (wg *ThreadSafeWaitGroup) Add(delta int32)

func (*ThreadSafeWaitGroup) Done added in v0.17.11

func (wg *ThreadSafeWaitGroup) Done()

func (*ThreadSafeWaitGroup) Wait added in v0.17.11

func (wg *ThreadSafeWaitGroup) Wait()

type Timer

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

func (*Timer) Begin

func (t *Timer) Begin(name string)

func (*Timer) End

func (t *Timer) End(name string)

func (*Timer) Fork

func (t *Timer) Fork() *Timer

func (*Timer) Join

func (t *Timer) Join(other *Timer)

func (*Timer) Log

func (t *Timer) Log(log logger.Log)

type TypoDetector added in v0.17.11

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

func MakeTypoDetector added in v0.17.11

func MakeTypoDetector(valid []string) TypoDetector

func (TypoDetector) MaybeCorrectTypo added in v0.17.11

func (detector TypoDetector) MaybeCorrectTypo(typo string) (string, bool)

Jump to

Keyboard shortcuts

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