rangespec

package module
v0.0.0-...-27d0d9e Latest Latest
Warning

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

Go to latest
Published: May 19, 2016 License: MIT Imports: 4 Imported by: 0

README

rangespec

Parsing a Range Specification, such as, "1,3,5-8,12-"

A number of checks are made to ensure that range is well formed.

  • an open ended range must be the last one
  • the start must be equal or greater than stop of an element
  • the start of an element must be greater than stop of prior element
  • no element may be zero (range begins at one)

Usage:

package main

import "github.com/mandolyte/rangespec"
import "log"
import "fmt"

func main() {
  input := "1,3,5-8,12-"
  fmt.Printf("Input is %v\n",input)
  result,err := rangespec.RangeSlice(input)
  if err != nil {
    // handle error
    log.Fatalf("Error:%v",err)
  }
  for n := range result {
    start := result[n].Start
    stop := result[n].Stop
    fmt.Printf("Start %v, Stop %v\n",start,stop)
  }
  // or
  for _, val := range result {
    start := val.Start
    stop := val.Stop
    fmt.Printf("Start %v, Stop %v\n",start,stop)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RangeSpec

type RangeSpec struct {
	Max uint64
	// contains filtered or unexported fields
}

RangeSpec parses a range specification, such as: 1,3,5-8,12- It will return a slice of RangeSpec, being two ints, a start and a stop Ranges start at 1, not zero.

func New

func New(r string) (*RangeSpec, error)

New takes a range specification string and returns a slice of RangeSpec structs

func (*RangeSpec) InRange

func (rs *RangeSpec) InRange(num uint64) bool

InRange will test whehter a number is in the range specification

Jump to

Keyboard shortcuts

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