diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-11-04 13:31:15 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-11-04 13:32:18 +0000 |
| commit | 97df59ddb7d6d3a0716bc872fdd5a172ed53b269 (patch) | |
| tree | 8d46cdba894f48ccd33d11490bbb946cc58c0f8e /src/string.cc | |
| parent | b167c116712ca852801d93a157e7950e1350767a (diff) | |
Support single char StringView
remove single char escape function overload, add unescape function
Diffstat (limited to 'src/string.cc')
| -rw-r--r-- | src/string.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/string.cc b/src/string.cc index 79da055b..474b15b4 100644 --- a/src/string.cc +++ b/src/string.cc @@ -62,26 +62,27 @@ std::vector<StringView> split(StringView str, char separator) return res; } -String escape(StringView str, char character, char escape) +String escape(StringView str, StringView characters, char escape) { String res; for (auto& c : str) { - if (c == character) + if (contains(characters, c)) res += escape; res += c; } return res; } -String escape(StringView str, StringView characters, char escape) +String unescape(StringView str, StringView characters, char escape) { String res; for (auto& c : str) { - if (contains(characters, c)) - res += escape; - res += c; + if (contains(characters, c) and not res.empty() and res.back() == escape) + res.back() = c; + else + res += c; } return res; } |
