pub fn split(input: &str) -> Result<Vec<String>, MismatchedQuotes>
Expand description
Splits a string into a vector of words in the same way the UNIX Bourne shell does.
This function does not behave like a full command line parser. Only single quotes, double quotes, and backslashes are treated as metacharacters. Within double quoted strings, backslashes are only treated as metacharacters when followed by one of the following characters:
- $
- `
- “
- \
- newline
§Errors
If the input contains mismatched quotes (a quoted string missing a matching ending quote),
a MismatchedQuotes
error is returned.
§Examples
Quoted strings are intepreted as one word:
assert_eq!(split("here are \"two words\"").unwrap(), ["here", "are", "two words"]);
The pipe character has no special meaning:
assert_eq!(split("cat file.txt | less").unwrap(), ["cat", "file.txt", "|", "less"]);