Documentation ¶
Overview ¶
Package shlex is used for simple command line splitting.
Both POSIX and Windows dialects are provided.
Index ¶
Constants ¶
Variables ¶
View Source
var Posix = Dialect{ IsSpace: func(r rune) bool { return ' ' == r || '\t' == r || '\n' == r }, IsQuote: func(r rune) bool { return '"' == r || '\'' == r }, Escape: func(s rune, r, r0 rune) rune { if '\\' != r { return NoEscape } switch s { case Space, Word: if '\n' == r0 || EmptyRune == r0 { return EmptyRune } return r0 case DoubleQuote: if '\n' == r0 || EmptyRune == r0 { return EmptyRune } if '$' == r0 || '`' == r0 || '"' == r0 || '\\' == r0 { return r0 } return NoEscape default: return NoEscape } }, }
Posix is the POSIX dialect of command line splitting. See https://tinyurl.com/26man79 for guidelines.
View Source
var Windows = Dialect{ IsSpace: func(r rune) bool { return ' ' == r || '\t' == r || '\r' == r || '\n' == r }, IsQuote: func(r rune) bool { return '"' == r }, Escape: func(s rune, r, r0 rune) rune { switch s { case Space, Word: if '\\' == r && '"' == r0 { return r0 } return NoEscape case DoubleQuote: if ('\\' == r || '"' == r) && '"' == r0 { return r0 } return NoEscape default: return NoEscape } }, LongEscape: func(s rune, r rune, line string) ([]rune, string, rune, int) { if '\\' != r { return nil, "", 0, 0 } var w int n := 0 for { r, w = utf8.DecodeRuneInString(line[n:]) n++ if 0 == w || '\\' != r { break } } if 2 > n { return nil, "", 0, 0 } if '"' != r { return []rune(strings.Repeat("\\", n-1)), line[n-1:], r, w } else if 0 == n&1 { return []rune(strings.Repeat("\\", n/2-1)), line[n-1:], '"', 1 } else { return []rune(strings.Repeat("\\", n/2-1)), line[n-2:], '\\', 1 } }, }
Windows is the Windows dialect of command line splitting. See https://tinyurl.com/ycdj5ghh for guidelines.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.