Split a string with specified delimiter character and escape character. https://rosettacode.org/wiki/Tokenize_a_string_with_escaping#C.2B.2B
| 1781 | // Split a string with specified delimiter character and escape character. |
| 1782 | // https://rosettacode.org/wiki/Tokenize_a_string_with_escaping#C.2B.2B |
| 1783 | static void SplitString(const std::string &s, char delim, char escape, |
| 1784 | std::vector<std::string> &elems) { |
| 1785 | std::string token; |
| 1786 | |
| 1787 | bool escaping = false; |
| 1788 | for (size_t i = 0; i < s.size(); ++i) { |
| 1789 | char ch = s[i]; |
| 1790 | if (escaping) { |
| 1791 | escaping = false; |
| 1792 | } else if (ch == escape) { |
| 1793 | escaping = true; |
| 1794 | continue; |
| 1795 | } else if (ch == delim) { |
| 1796 | if (!token.empty()) { |
| 1797 | elems.push_back(token); |
| 1798 | } |
| 1799 | token.clear(); |
| 1800 | continue; |
| 1801 | } |
| 1802 | token += ch; |
| 1803 | } |
| 1804 | |
| 1805 | elems.push_back(token); |
| 1806 | } |
| 1807 | |
| 1808 | static std::string JoinPath(const std::string &dir, |
| 1809 | const std::string &filename) { |