regexps

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 2 Imported by: 2

README

godoc codecov Go Report Card

regexps - caching regexp compiler and common regexp patterns

regexps is a simple package for common regexp patterns and a caching regexp compilation system.

Installation

> go get github.com/go-corelibs/regexps@latest

Examples

Compile, ClearCache

func main() {
    var err error
    var rx *regexp.Regexp

    // this first call tries to compile the broken pattern
    rx, err = regexps.Compile(`[not a thing`)
    // this second call just returns the prior results for
    // the same broken pattern
    rx, err = regexps.Compile(`[not a thing`)
    // this next call actually compiles a regexp instance
    rx, err = regexps.Compile(`[not] a thing`)
    // trying the same pattern again just returns the prior
    // instance
    rx, err = regexps.Compile(`[not] a thing`)

    // in case clearing the cached results is necessary...
    regexps.ClearCache()
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache will purge all cached patterns

func Compile

func Compile(pattern string) (rx *regexp.Regexp, err error)

Compile will call regexp.Compile and cache the results and any subsequent calls to Compile with the same patterns return the cached results

Types

type Cache added in v1.1.0

type Cache interface {
	// Compile tries to compile the regular expression pattern and caches the
	// results, even error cases, so that subsequent calls to Compile with the
	// same pattern will return the cached results
	Compile(pattern string) (rx *regexp.Regexp, err error)

	// Reset clears the existing cache
	Reset()
}

func NewCache added in v1.1.0

func NewCache() (c Cache)

Jump to

Keyboard shortcuts

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