No description
  • Go 98.2%
  • Makefile 1.8%
Find a file
2023-09-16 21:55:13 +07:00
.gitignore Add more tests 2019-08-31 20:45:07 +10:00
generator.go Allow filtering non-graphic 2023-09-16 21:55:13 +07:00
generator_test.go Allow filtering non-graphic 2023-09-16 21:55:13 +07:00
go.mod Allow filtering non-graphic 2023-09-16 21:55:13 +07:00
go.sum Allow filtering non-graphic 2023-09-16 21:55:13 +07:00
lexer.go Update module deps 2019-10-29 22:30:10 +11:00
Makefile Clean up makefile 2020-07-31 13:38:41 +10:00
README.md Update readme 2019-10-24 15:10:38 +13:00

Generate character sequences from POSIX Bracket Expressions

a bracket expression matches any character among those listed between the opening and closing square brackets. Within a bracket expression, a range expression consists of two characters separated by a hyphen. It matches any single character that sorts between the two characters, based upon the systems native character set. For example, [0-9] is equivalent to [0123456789] ~ GNU Awk manual

Bracket expressions are often used to limit searches, regular expressions and filters. But sometimes you need to have the range of characters expanded and explicitly listed; this library helps do that.

gen, _ := bechars.New()
rng, _ := gen.Generate("[:print:]")
fmt.Println(rng) // => " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

// Unicode characters
rng, _ = gen.Generate("[\u0e010-2]")
fmt.Println(rng) // => "ก012"

rng, _ = gen.Generate("[:punct:]")
fmt.Println(rng) // => "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]"

The generator can also be configured:

gen, _ := bechars.New(MinRune('a'), MaxRune('z'))
rng, _ := gen.Generate("[^:cntrl::punct:]")
fmt.Println(rng) // => "abcdefghijklmnopqrstuvwxyz"

See the tests for more examples.