cmdstr

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncompleteCommand = errors.New("incomplete command")
)

Functions

func Parse

func Parse(cmd []byte, endset string) (out []string, n int, rerr error)

Parse implements shell-esque string-splitting rules, similar to Python's shlex.

Parsing ends when all arguments are successfully consumed, when invalid syntax is encountered, or when one of the characters in 'endset' is encountered while scanning for the start of the next argument.

The input string is stripped of leading and trailing whitespace. Whitespace is defined as '\r', '\n', '\t' and ' '.

Strings within cmd can be single-quoted, double-quoted or unquoted. Empty strings are allowed.

An unquoted string ends at the first occurence of whitespace or the end of cmd.

Quote characters are not recognized within words; `Do"Not"Separate` is parsed as the single word `Do"Not"Separate`.

Enclosing characters in single-quotes ( ” ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes.

Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the exception of <backslash>, explained below.

The <backslash> shall retain its special meaning as an escape character when present in the following two-byte sequences, producing the output on the right side:

0x5c 0x6e (\n)  --> 0x0a
0x5c 0x0a (\\n) --> <nothing>
0x5c 0x22 (\")  --> 0x22
0x5c 0x5c (\\)  --> 0x5c

All other backslashes are copied literally into the output:

0x5c 0x61 (\a)  --> 0x5c 0x61

func ParseString

func ParseString(cmd string, endset string) ([]string, error)

ParseString implements the string-version of Parse. See Parse for more details.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL