17 std::vector<std::string>
18 split_quoted(
const std::string& str,
char sep,
char quote,
char escape) {
20 std::vector<std::string> out;
22 std::string::const_iterator it = str.begin();
25 for ( ; it != str.end(); )
31 else if (*it == quote) {
36 if (it == str.end()) {
37 throw std::runtime_error(
38 "unmatched end quote in split_quoted().");
40 else if (*it == quote) {
42 if (it == str.end()) {
44 out.emplace_back(std::move(entry));
47 else if (*it == sep) {
49 out.emplace_back(std::move(entry));
54 throw std::runtime_error(
55 std::string(
"extra quote enclosed in entry," 56 " followed by ") + *it);
59 else if (*it == escape) {
61 if (it == str.end()) {
62 throw std::runtime_error(
63 "escape as last character in string");
65 else if (*it == quote) {
69 else if (*it == escape) {
73 else if (*it ==
'n') {
77 else if (*it ==
'r') {
81 else if (*it ==
't') {
86 throw std::runtime_error(
87 std::string(
"escape followed by " 88 "unknown character") + *it);
100 if (it == str.end()) {
102 out.emplace_back(std::move(entry));
105 else if (*it == sep) {
107 out.emplace_back(std::move(entry));
std::vector< std::string > split_quoted(const std::string &str, char sep, char quote, char escape)
Split the given string at each separator character into distinct substrings.