package csscolorparser

import 

// Cursor-based scanner over an input string.
//
// All delimiters it cares about are ASCII, so it works on bytes and slicing
// is always safe for UTF-8 input (a delimiter byte can never be part of a
// multi-byte sequence).
type paramParser struct {
	s   string
	pos int
}

func newParamParser( string) *paramParser {
	return &paramParser{s: }
}

// value consumes and returns the substring from the current position up to
// (not including) the next space, comma, or slash. Those characters are
// ignored while inside parentheses, which may be nested.
//
// Returns ("", false) if there is no value at the current position; the
// position is left unchanged in that case.
func ( *paramParser) () (string, bool) {
	 := .pos
	 := 
	 := 0

	for  < len(.s) {
		 := .s[]
		if  == '(' {
			++
		} else if  == ')' {
			if  > 0 {
				--
			}
		} else if  == 0 && (isSpace() ||  == ',' ||  == '/') {
			break
		}
		++
	}

	if  ==  {
		return "", false
	}
	.pos = 
	return .s[:], true
}

// space consumes one or more ASCII whitespace characters.
// Returns true if at least one was found, false otherwise.
func ( *paramParser) () bool {
	 := .pos
	for .pos < len(.s) && isSpace(.s[.pos]) {
		.pos++
	}
	return .pos > 
}

// separator consumes a single character from chars, with optional
// whitespace around it. If no such character is found, nothing is consumed.
func ( *paramParser) ( string) bool {
	 := .pos
	.space()
	if .pos < len(.s) && strings.IndexByte(, .s[.pos]) >= 0 {
		.pos++
		.space()
		return true
	}
	.pos = 
	return false
}

// commaOrSpace consumes one or more spaces, or a single comma. Spaces are
// allowed around the comma. Returns true if either was found.
func ( *paramParser) () bool {
	 := .space()
	if .pos < len(.s) && .s[.pos] == ',' {
		.pos++
		.space()
		return true
	}
	return 
}

// commaOrSlash consumes a single comma or a single slash. Spaces are allowed
// around it. Returns true if one was found; otherwise nothing is consumed.
func ( *paramParser) () bool {
	return .separator(",/")
}

// slash consumes a single slash. Spaces are allowed around it. Returns true
// if a slash was found; otherwise nothing is consumed.
func ( *paramParser) () bool {
	return .separator("/")
}

// isEnd reports whether the whole string has been read.
func ( *paramParser) () bool {
	return .pos >= len(.s)
}