Tweak unescape template function to unescape the escape char as well

Test that more thouroughly in the unit tests.
This commit is contained in:
Maxime Coste 2017-12-07 01:56:02 +08:00
parent 99636c6230
commit 2f48bbf6ff
2 changed files with 7 additions and 3 deletions

View File

@ -351,8 +351,8 @@ UnitTest test_string{[]()
kak_assert(wrapped2[1] == "unknown");
kak_assert(wrapped2[2] == "type");
kak_assert(escape("youpi:matin:tchou:", ':', '\\') == "youpi\\:matin\\:tchou\\:");
kak_assert(unescape("youpi\\:matin\\:tchou\\:", ':', '\\') == "youpi:matin:tchou:");
kak_assert(escape(R"(\youpi:matin:tchou\:)", ":\\", '\\') == R"(\\youpi\:matin\:tchou\\\:)");
kak_assert(unescape(R"(\\youpi\:matin\:tchou\\\:)", ":\\", '\\') == R"(\youpi:matin:tchou\:)");
kak_assert(prefix_match("tchou kanaky", "tchou"));
kak_assert(prefix_match("tchou kanaky", "tchou kanaky"));

View File

@ -14,7 +14,11 @@ String escape(StringView str, StringView characters, char escape);
String unescape(StringView str, StringView characters, char escape);
template<char character, char escape>
String unescape(StringView str) { return unescape(str, character, escape); }
String unescape(StringView str)
{
const char to_escape[2] = { character, escape };
return unescape(str, {to_escape, 2}, escape);
}
String indent(StringView str, StringView indent = " ");