func NewRange(str []byte) (Range, error) {
	if len(str) == 0 || (len(str) == 1 && (str[0] == '*' || str[0] == 'x')) {
		// An empty Range contains everything.
		return Range{}, nil
	}
	isNaturalRange := true
	if bytes.HasSuffix(str, []byte(".x")) || bytes.HasSuffix(str, []byte(".*")) {
		str = bytes.TrimRight(str, ".x*")
		isNaturalRange = false
	}
	if str[0] == '^' || str[0] == '~' {
		return newRangeByShortcut(str)
	}

	var upperBound, lowerBound bool = true, true
	if len(str) >= 2 {
		lowerBound = !(str[0] == '<' || str[1] == '<')
		upperBound = !(str[0] == '>' || str[1] == '>')
	}
	var leftEnd, rightStart int
	if idx := bytes.IndexByte(str, byte(' ')); idx > 1 {
		leftEnd = idx
	} else if idx = bytes.IndexByte(str, byte(',')); idx > 1 {
		leftEnd = idx
	} else {
		leftEnd = len(str)
		rightStart = leftEnd
	}
	if rightStart == 0 {
		rightStart = bytes.LastIndexByte(str, byte(' ')) + 1
		if rightStart <= 0 {
			rightStart = bytes.LastIndexByte(str, byte(',')) + 1
		}
	}

	isNaturalRange = isNaturalRange && leftEnd != rightStart && (len(str)-rightStart) > 0
	if !isNaturalRange {
		leftDotCount := bytes.Count(str[:leftEnd], []byte{'.'})
		switch leftDotCount {
		case 1:
			return newRangeByShortcut(append([]byte{'~'}, str...))
		case 0:
			return newRangeByShortcut(append([]byte{'^'}, str...))
		}
	}
	vr := Range{}
	if leftEnd == rightStart {
		err := vr.setBound(str, lowerBound, upperBound)
		return vr, err
	}

	if err := vr.setBound(str[:leftEnd], true, false); err != nil {
		return vr, err
	}
	if err := vr.setBound(str[rightStart:], false, true); err != nil {
		return vr, err
	}

	return vr, nil
}
// NewRange translates into a Range.
NewRange translates into a Range.
// NewRange translates into a Range .
func NewRange(str []byte) (Range, error) {
	if len(str) == 0 || (len(str) == 1 && (str[0] == '*' || str[0] == 'x')) {
		return Range{}, nil
	}
	isNaturalRange := true
	if bytes.HasSuffix(str, []byte(".x")) || bytes.HasSuffix(str, []byte(".*")) {
		str = bytes.TrimRight(str, ".x*")
		isNaturalRange = false
	}
	if str[0] == '^' || str[0] == '~' {
		return newRangeByShortcut(str)
	}
	var upperBound, lowerBound bool = true, true
	if len(str) >= 2 {
		lowerBound = !(str[0] == '<' || str[1] == '<')
		upperBound = !(str[0] == '>' || str[1] == '>')
	}
	var leftEnd, rightStart int
	if idx := bytes.IndexByte(str, byte(' ')); idx > 1 {
		leftEnd = idx
	} else if idx = bytes.IndexByte(str, byte(',')); idx > 1 {
		leftEnd = idx
	} else {
		leftEnd = len(str)
		rightStart = leftEnd
	}
	if rightStart == 0 {
		rightStart = bytes.LastIndexByte(str, byte(' ')) + 1
		if rightStart <= 0 {
			rightStart = bytes.LastIndexByte(str, byte(',')) + 1
		}
	}
	isNaturalRange = isNaturalRange && leftEnd != rightStart && (len(str)-rightStart) > 0
	if !isNaturalRange {
		leftDotCount := bytes.Count(str[:leftEnd], []byte{'.'})
		switch leftDotCount {
		case 1:
			return newRangeByShortcut(append([]byte{'~'}, str...))
		case 0:
			return newRangeByShortcut(append([]byte{'^'}, str...))
		}
	}
	vr := Range{}
	if leftEnd == rightStart {
		err := vr.setBound(str, lowerBound, upperBound)
		return vr, err
	}
	if err := vr.setBound(str[:leftEnd], true, false); err != nil {
		return vr, err
	}
	if err := vr.setBound(str[rightStart:], false, true); err != nil {
		return vr, err
	}
	return vr, nil
}
func NewRange ( str [ ] byte ) ( Range , error ) { if len ( str ) == 0 || ( len ( str ) == 1 && ( str [ 0 ] == '*' || str [ 0 ] == 'x' ) ) { return Range { } , nil } isNaturalRange := true if bytes . HasSuffix ( str , [ ] byte ( " " ) ) || bytes . HasSuffix ( str , [ ] byte ( " " ) ) { str = bytes . TrimRight ( str , " " ) isNaturalRange = false } if str [ 0 ] == '^' || str [ 0 ] == '~' { return newRangeByShortcut ( str ) } var upperBound , lowerBound bool = true , true if len ( str ) >= 2 { lowerBound = ! ( str [ 0 ] == '<' || str [ 1 ] == '<' ) upperBound = ! ( str [ 0 ] == '>' || str [ 1 ] == '>' ) } var leftEnd , rightStart int if idx := bytes . IndexByte ( str , byte ( ' ' ) ) ; idx > 1 { leftEnd = idx } else if idx = bytes . IndexByte ( str , byte ( ',' ) ) ; idx > 1 { leftEnd = idx } else { leftEnd = len ( str ) rightStart = leftEnd } if rightStart == 0 { rightStart = bytes . LastIndexByte ( str , byte ( ' ' ) ) + 1 if rightStart <= 0 { rightStart = bytes . LastIndexByte ( str , byte ( ',' ) ) + 1 } } isNaturalRange = isNaturalRange && leftEnd != rightStart && ( len ( str ) - rightStart ) > 0 if ! isNaturalRange { leftDotCount := bytes . Count ( str [ : leftEnd ] , [ ] byte { '.' } ) switch leftDotCount { case 1 : return newRangeByShortcut ( append ( [ ] byte { '~' } , str ... ) ) case 0 : return newRangeByShortcut ( append ( [ ] byte { '^' } , str ... ) ) } } vr := Range { } if leftEnd == rightStart { err := vr . setBound ( str , lowerBound , upperBound ) return vr , err } if err := vr . setBound ( str [ : leftEnd ] , true , false ) ; err != nil { return vr , err } if err := vr . setBound ( str [ rightStart : ] , false , true ) ; err != nil { return vr , err } return vr , nil }
NewRange translates into a Range.
NewRange translates into a Range .
// An empty Range contains everything.