package regexp2

import (
	
	
)

// Split splits the given input string using the pattern and returns
// a slice of the parts. Count limits the number of matches to process.
// If Count is -1, then it will process the input fully.
// If Count is 0, returns nil. If Count is 1, returns the original input.
// The only expected error is a Timeout, if it's set.
//
// If capturing parentheses are used in the Regex expression, any captured
// text is included in the resulting string array
// For example, a pattern of "-" Split("a-b") will return ["a", "b"]
// but a pattern with "(-)" Split ("a-b") will return ["a", "-", "b"]
func ( *Regexp) ( string,  int) ([]string, error) {
	if  < -1 {
		return nil, errors.New("count too small")
	}
	if  == 0 {
		return nil, nil
	}
	if  == 1 {
		return []string{}, nil
	}
	if  == -1 {
		// no limit
		 = math.MaxInt
	}

	// iterate through the matches
	 := 0
	var  []string
	var  []rune

	,  := .FindStringMatch()

	for ;  != nil &&  > 0; ,  = .FindNextMatch() {
		 = .text.runes
		// if we have an m, we don't have an err
		// append our match
		 = append(, string([:.RuneIndex]))
		// append any capture groups, skipping group 0
		 := .Groups()
		for  := 1;  < len(); ++ {
			 = append(, [].String())
		}
		 = .RuneIndex + .RuneLength
		--
	}

	if  != nil {
		return nil, 
	}

	if  == nil {
		// we never matched, return the original string
		return []string{}, nil
	}

	// append our remainder
	 = append(, string([:]))

	return , nil
}