intsetexpr

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package intsetexpr implements parsing of expressions like `a{01..03}b`.

It knows how to expand `a{01..03}b` into `[a01b, a02b, a03b]`.

Index

Constants

View Source
const (
	TokLB    = iota // non-escaped '{'
	TokRB           // non-escaped '}'
	TokNum          // a sequence of digits
	TokRunes        // an arbitrary sequence of non-special runes
	TokComma        // ','
	TokDots         // '..'
)

Variables

This section is empty.

Functions

func Expand

func Expand(s string) ([]string, error)

Expand expands a string with a int set into a list of strings.

For example, given `a{1..3}b` produces `['a1b', 'a2b', 'a3b']`.

The incoming string should have no more than one `{...}` section. If it's absent, the function returns the list that contains one item: the original string.

The set is given as comma-separated list of terms. Each term is either a single non-negative integer (e.g. `9`) or a range (e.g. `1..5`). Both ends of the range are inclusive. Ranges where the left hand side is larger than the right hand side are not allowed. All elements should be listed in the strictly increasing order (e.g. `1,2,5..10` is fine, but `5..10,1,2` is not). Spaces are not allowed.

The output integers are padded with zeros to match the width of corresponding terms. For ranges this works only if both sides have same width. For example, `01,002,03..04` will expand into `01, 002, 03, 04`.

Use `{{` and `}}` to escape `{` and `}` respectively.

Types

This section is empty.

Jump to

Keyboard shortcuts

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