Split a string with specified delimiter character and escape character. https://rosettacode.org/wiki/Tokenize_a_string_with_escaping#C.2B.2B
| 2038 | // Split a string with specified delimiter character and escape character. |
| 2039 | // https://rosettacode.org/wiki/Tokenize_a_string_with_escaping#C.2B.2B |
| 2040 | static void SplitString(const std::string &s, char delim, char escape, |
| 2041 | std::vector<std::string> &elems) { |
| 2042 | std::string token; |
| 2043 | |
| 2044 | bool escaping = false; |
| 2045 | for (size_t i = 0; i < s.size(); ++i) { |
| 2046 | char ch = s[i]; |
| 2047 | if (escaping) { |
| 2048 | escaping = false; |
| 2049 | } else if (ch == escape) { |
| 2050 | escaping = true; |
| 2051 | continue; |
| 2052 | } else if (ch == delim) { |
| 2053 | if (!token.empty()) { |
| 2054 | elems.push_back(token); |
| 2055 | } |
| 2056 | token.clear(); |
| 2057 | continue; |
| 2058 | } |
| 2059 | token += ch; |
| 2060 | } |
| 2061 | |
| 2062 | elems.push_back(token); |
| 2063 | } |
| 2064 | |
| 2065 | static std::string JoinPath(const std::string &dir, |
| 2066 | const std::string &filename) { |
no test coverage detected