str

package
v0.0.0-...-fe1446d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT, Unlicense Imports: 7 Imported by: 0

README

Fuzz test run for almost an hour

020/05/20 14:23:13 workers: 12, corpus: 1473 (52m38s ago), crashers: 0, restarts: 1/9996, execs: 171550918 (54048/sec), cover: 299, uptime: 52m54s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllSimpleFold

func AllSimpleFold(input rune) []rune

Given an input rune return a rune slice containing all of the possible simple fold

func Contains

func Contains(elements []string, needle string) bool

func Fuzz

func Fuzz(data []byte) int

For fuzz testing... https://github.com/dvyukov/go-fuzz install both go-fuzz-build and go-fuzz go-fuzz-build && go-fuzz

func HighlightString

func HighlightString(content string, locations [][]int, in string, out string) string

HighlightString takes in some content and locations and then inserts in/out strings which can be used for highlighting around matching terms. For example you could pass in "test" and have it return "<strong>te</strong>st" locations accepts output from regex.FindAllIndex IndexAllIgnoreCase or IndexAll

func IndexAll

func IndexAll(haystack string, needle string, limit int) [][]int

IndexAll extracts all of the locations of a str inside another str up-to the defined limit and does so without regular expressions which makes it faster than FindAllIndex in most situations while not being any slower. It performs worst when working against random data.

Some benchmark results to illustrate the point (find more in index_benchmark_test.go)

BenchmarkFindAllIndex-8 2458844 480.0 ns/op BenchmarkIndexAll-8 14819680 79.6 ns/op

For pure literal searches IE no regular expression logic this method is a drop in replacement for re.FindAllIndex but generally much faster.

Similar to how FindAllIndex the limit option can be passed -1 to get all matches.

Note that this method is explicitly case sensitive in its matching. A return value of nil indicates no match.

func IndexAllIgnoreCase

func IndexAllIgnoreCase(haystack string, needle string, limit int) [][]int

IndexAllIgnoreCase extracts all of the locations of a str inside another str up-to the defined limit. It is designed to be faster than uses of FindAllIndex with case insensitive matching enabled, by looking for str literals first and then checking for exact matches. It also does so in a unicode aware way such that a search for S will search for S s and ſ which a simple strings.ToLower over the haystack and the needle will not.

The result is the ability to search for literals without hitting the regex engine which can at times be horribly slow. This by contrast is much faster. See index_ignorecase_benchmark_test.go for some head to head results. Generally so long as we aren't dealing with random data this method should be considerably faster (in some cases thousands of times) or just as fast. Of course it cannot do regular expressions, but that's fine.

For pure literal searches IE no regular expression logic this method is a drop in replacement for re.FindAllIndex but generally much faster.

func IsSpace

func IsSpace(firstByte, nextByte byte) bool

Bytes MUST be UTF-8 encoded List of spaces detected (same as unicode.IsSpace): '\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP). N.B only two bytes are required for these cases. If we decided to support spaces like ',' then we'll need more bytes.

func PermuteCase

func PermuteCase(input string) []string

Given a str returns a slice containing all possible case permutations of that str such that input of foo will return foo Foo fOo FOo foO FoO fOO FOO Note that very long inputs can produce an enormous amount of results in the returned slice OR result in an overflow and return nothing

func PermuteCaseFolding

func PermuteCaseFolding(input string) []string

Given a str returns a slice containing all possible case permutations with characters being folded such that S will return S s ſ

func RemoveStringDuplicates

func RemoveStringDuplicates(elements []string) []string

Simple helper method that removes duplicates from any given str slice and then returns a nice duplicate free str slice

func StartOfRune

func StartOfRune(b byte) bool

Checks a byte and returns true if its the start of a multibyte character or a single byte character otherwise false

Types

This section is empty.

Jump to

Keyboard shortcuts

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