func appendEscapeArg(b []byte, s string) []byte {
	if len(s) == 0 {
		return append(b, `""`...)
	}

	needsBackslash := false
	hasSpace := false
	for i := 0; i < len(s); i++ {
		switch s[i] {
		case '"', '\\':
			needsBackslash = true
		case ' ', '\t':
			hasSpace = true
		}
	}

	if !needsBackslash && !hasSpace {
		// No special handling required; normal case.
		return append(b, s...)
	}
	if !needsBackslash {
		// hasSpace is true, so we need to quote the string.
		b = append(b, '"')
		b = append(b, s...)
		return append(b, '"')
	}

	if hasSpace {
		b = append(b, '"')
	}
	slashes := 0
	for i := 0; i < len(s); i++ {
		c := s[i]
		switch c {
		default:
			slashes = 0
		case '\\':
			slashes++
		case '"':
			for ; slashes > 0; slashes-- {
				b = append(b, '\\')
			}
			b = append(b, '\\')
		}
		b = append(b, c)
	}
	if hasSpace {
		for ; slashes > 0; slashes-- {
			b = append(b, '\\')
		}
		b = append(b, '"')
	}

	return b
}
// appendEscapeArg escapes the string s, as per escapeArg,
// appends the result to b, and returns the updated slice.
appendEscapeArg escapes the string s, as per escapeArg,
appends the result to b, and returns the updated slice.
// appendEscapeArg escapes the string s as per escapeArg // appends the result to b and returns the updated slice .
func appendEscapeArg(b []byte, s string) []byte {
	if len(s) == 0 {
		return append(b, `""`...)
	}
	needsBackslash := false
	hasSpace := false
	for i := 0; i < len(s); i++ {
		switch s[i] {
		case '"', '\\':
			needsBackslash = true
		case ' ', '\t':
			hasSpace = true
		}
	}
	if !needsBackslash && !hasSpace {
		return append(b, s...)
	}
	if !needsBackslash {
		b = append(b, '"')
		b = append(b, s...)
		return append(b, '"')
	}
	if hasSpace {
		b = append(b, '"')
	}
	slashes := 0
	for i := 0; i < len(s); i++ {
		c := s[i]
		switch c {
		default:
			slashes = 0
		case '\\':
			slashes++
		case '"':
			for ; slashes > 0; slashes-- {
				b = append(b, '\\')
			}
			b = append(b, '\\')
		}
		b = append(b, c)
	}
	if hasSpace {
		for ; slashes > 0; slashes-- {
			b = append(b, '\\')
		}
		b = append(b, '"')
	}
	return b
}
func appendEscapeArg ( b [ ] byte , s string ) [ ] byte { if len ( s ) == 0 { return append ( b , `""` ... ) } needsBackslash := false hasSpace := false for i := 0 ; i < len ( s ) ; i ++ { switch s [ i ] { case '"' , '\\' : needsBackslash = true case ' ' , '\t' : hasSpace = true } } if ! needsBackslash && ! hasSpace { return append ( b , s ... ) } if ! needsBackslash { b = append ( b , '"' ) b = append ( b , s ... ) return append ( b , '"' ) } if hasSpace { b = append ( b , '"' ) } slashes := 0 for i := 0 ; i < len ( s ) ; i ++ { c := s [ i ] switch c { default : slashes = 0 case '\\' : slashes ++ case '"' : for ; slashes > 0 ; slashes -- { b = append ( b , '\\' ) } b = append ( b , '\\' ) } b = append ( b , c ) } if hasSpace { for ; slashes > 0 ; slashes -- { b = append ( b , '\\' ) } b = append ( b , '"' ) } return b }
appendEscapeArg escapes the string s, as per escapeArg,
appends the result to b, and returns the updated slice.
appendEscapeArg escapes the string s as per escapeArg appends the result to b and returns the updated slice .
// No special handling required; normal case. // hasSpace is true, so we need to quote the string.