lib

package
v0.0.0-...-c9c6779 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RegexpCache

type RegexpCache struct {
	// Size is the maximum size of the cache
	Size int
	// contains filtered or unexported fields
}

RegexpCache caches compilation of regular expressions. Except for modification of Size, it can be used concurrently.

Example
// create a cache of size 2
cache := &RegexpCache{
	Size: 2,
}

// compile 'hello' regexp
first, err := cache.Compile("hello")
fmt.Println(first, err)

// compile 'world' regexp
second, err := cache.Compile("world")
fmt.Println(second, err)

// compile 'hello' regexp again
third, err := cache.Compile("hello")
fmt.Println(third, err)

// this is re-using the same regular expression
fmt.Println(unsafe.Pointer(first) == unsafe.Pointer(third))
Output:

hello <nil>
world <nil>
hello <nil>
true

func (*RegexpCache) Compile

func (rr *RegexpCache) Compile(src string) (exp *regexp.Regexp, err error)

Compile returns a (possibly cached) compiled version of src. When src is invalid it is never cached.

See regexp.Compile for description of regular expressions.

func (*RegexpCache) Reset

func (rr *RegexpCache) Reset()

Reset removes all cached regular expressions

Jump to

Keyboard shortcuts

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