Function split_string¶
-
void
o2scl
::
split_string
(std::string str, std::vector<std::string> &sv)¶ Split a string into words using whitespace for delimiters and (partially) respecting quotes.
This function separates a string into words, and handles words that begin with a
. Strings like“</tt> by adding more words until finding
one which ends with another <tt>”
get parsed as “this”, “is”, “a”, “test” and strings likethis is a test
get parsed as “this is”, “a”, “test”."this is" a test
This is used to reformat command descriptions and help text for the screen width in cli::comm_option_help(), to process lines read from a file in cli::comm_option_run(), and to process input in cli::run_interactive().
- Todo:
The rules surrounding spaces and quotes are strange and not well documented.
- Idea for Future:
Replace with a better algorithm. Should quotes be escaped?
- Note
The string vector is not emptied before processing, and entries from
str
are added to the end ofsv
.- Note
The parsing algorithm here is simple-minded and can produce unexpected results in several ways. For example, it may not properly handle nested quotes, like
.“””test” test2”
test3”