n0madic / expand-range

Parsing of numeric ranges from string

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expand-range

Go Reference

Parsing of numeric ranges from string.

Convert "1,3-5" into [1,3,4,5].

Installation

go get -u github.com/n0madic/expand-range

Usage

Import:

import expandrange "github.com/n0madic/expand-range"

Parse string:

rng, err := expandrange.Parse("1,3-5")
if err != nil {
    panic(err)
}

Range checking:

if rng.InRange(4) {
    ...
}

Sorting result:

rng, _ := expandrange.Parse("3,2,1")
rng.Sort()
// [1,2,3]

About

Parsing of numeric ranges from string

License:The Unlicense


Languages

Language:Go 100.0%