Fix tagged text escaping & tests
This commit is contained in:
parent
183f5283e2
commit
2b228fbd32
2 changed files with 23 additions and 17 deletions
|
|
@ -56,19 +56,10 @@ namespace psemek::ui
|
|||
}
|
||||
else
|
||||
{
|
||||
auto start = current;
|
||||
|
||||
if (*current == '\\')
|
||||
{
|
||||
++current;
|
||||
if (current == text.end())
|
||||
error("unexpected end");
|
||||
}
|
||||
|
||||
auto append = [&](std::string_view & target)
|
||||
{
|
||||
if (target.empty())
|
||||
target = {start, current + 1};
|
||||
target = {current, current + 1};
|
||||
else
|
||||
target = {target.data(), current + 1};
|
||||
};
|
||||
|
|
@ -87,9 +78,23 @@ namespace psemek::ui
|
|||
}
|
||||
else
|
||||
{
|
||||
if (result.tokens.empty() || !std::get_if<std::string_view>(&result.tokens.back()))
|
||||
result.tokens.push_back(std::string_view{});
|
||||
append(std::get<std::string_view>(result.tokens.back()));
|
||||
if (*current == '\\')
|
||||
{
|
||||
++current;
|
||||
if (current < text.end())
|
||||
{
|
||||
result.tokens.push_back(std::string_view{});
|
||||
append(std::get<std::string_view>(result.tokens.back()));
|
||||
}
|
||||
else
|
||||
--current;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (result.tokens.empty() || !std::get_if<std::string_view>(&result.tokens.back()))
|
||||
result.tokens.push_back(std::string_view{});
|
||||
append(std::get<std::string_view>(result.tokens.back()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,10 +93,11 @@ test_case(ui_tagged__text_tag__attribute)
|
|||
|
||||
test_case(ui_tagged__text_escape)
|
||||
{
|
||||
test("\\[", {{"\\["}});
|
||||
test("\\]", {{"\\]"}});
|
||||
test("\\\\", {{"\\\\"}});
|
||||
test("\\[\\]", {{"\\[\\]"}});
|
||||
test("\\[", {{"["}});
|
||||
test("\\]", {{"]"}});
|
||||
test("\\\\", {{"\\"}});
|
||||
test("\\[\\]", {{"[", "]"}});
|
||||
test(R"(text \[not \\ tag\] end)", {{"text ", "[not ", "\\ tag", "] end"}});
|
||||
}
|
||||
|
||||
test_case(ui_tagged__text_error)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue