package http

import (
	
	
	
	
)

func ( []string,  func(string) ([]string, error)) ([]string, error) {
	 := make([]string, 0, len())

	for  := 0;  < len(); ++ {
		,  := ([])
		if  != nil {
			return nil, 
		}
		 = append(, ...)
	}

	return , nil
}

// SplitHeaderListValues attempts to split the elements of the slice by commas,
// and return a list of all values separated. Returns error if unable to
// separate the values.
func ( []string) ([]string, error) {
	return splitHeaderListValues(, quotedCommaSplit)
}

func ( string) ( []string,  error) {
	 = strings.TrimSpace()

	 := true
	for  := 0;  < len(); ++ {
		if unicode.IsSpace(rune([])) {
			continue
		}
		 = false

		// leading  space in part is ignored.
		// Start of value must be non-space, or quote.
		//
		// - If quote, enter quoted mode, find next non-escaped quote to
		//   terminate the value.
		// - Otherwise, find next comma to terminate value.

		 := [:]

		var  string
		var  int
		if [0] == '"' {
			//------------------------------
			// Quoted value
			//------------------------------
			var  int
			var  bool
			for  += 1;  < len(); ++ {
				if [] == '\\' || ([] != '\\' && ) {
					 = !
					continue
				}
				if [] == '"' {
					break
				}
			}
			if  == len() ||  == 1 {
				return nil, fmt.Errorf("value %v missing closing double quote",
					)
			}
			 =  + 1

			 := [:]
			var  int
			for ;  < len(); ++ {
				if !unicode.IsSpace(rune([])) && [] != ',' {
					return nil, fmt.Errorf("value %v has non-space trailing characters",
						)
				}
				if [] == ',' {
					 = true
					break
				}
			}
			 = [:]
			,  = strconv.Unquote()
			if  != nil {
				return nil, fmt.Errorf("failed to unquote value %v, %w", , )
			}

			// Pad valueLen to include trailing space(s) so `i` is updated correctly.
			 += 

		} else {
			//------------------------------
			// Unquoted value
			//------------------------------

			// Index of the next comma is the length of the value, or end of string.
			 = strings.Index(, ",")
			if  != -1 {
				 = true
			} else {
				 = len()
			}
			 = strings.TrimSpace([:])
		}

		 += 
		 = append(, )

	}

	if  {
		 = append(, "")
	}

	return , nil
}

// SplitHTTPDateTimestampHeaderListValues attempts to split the HTTP-Date
// timestamp values in the slice by commas, and return a list of all values
// separated. The split is aware of the HTTP-Date timestamp format, and will skip
// comma within the timestamp value. Returns an error if unable to split the
// timestamp values.
func ( []string) ([]string, error) {
	return splitHeaderListValues(, splitHTTPDateHeaderValue)
}

func ( string) ([]string, error) {
	if  := strings.Count(, ",");  <= 1 {
		// Nothing to do if only contains a no, or single HTTPDate value
		return []string{}, nil
	} else if %2 == 0 {
		return nil, fmt.Errorf("invalid timestamp HTTPDate header comma separations, %q", )
	}

	var  []string
	var ,  int

	var  bool
	for ;  < len(); ++ {
		if [] == ',' {
			if  {
				 = false
				 = append(, strings.TrimSpace([:]))
				 =  + 1
			} else {
				// Skip the first comma in the timestamp value since that
				// separates the day from the rest of the timestamp.
				//
				// Tue, 17 Dec 2019 23:48:18 GMT
				 = true
			}
		}
	}
	// Add final part
	if  < len() {
		 = append(, strings.TrimSpace([:]))
	}

	return , nil
}