Make whitespace-reduction a bit more efficient.
continuous-integration/drone/push Build is passing Details

We now use 2 passes instead of 3.
This commit is contained in:
tastytea 2021-06-08 17:30:29 +02:00
parent 3966b99c3f
commit f8270369b6
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 23 additions and 20 deletions

View File

@ -133,26 +133,29 @@ file_in_epub cleanup_text(const std::string_view text)
"(title|aria-label)"
"=\"([[:alnum:]]+)\""};
// TODO: Make this more efficient, 3 → 1;
{
size_t pos{0};
while ((pos = output.find_first_of("\n\t\r", pos)) != string::npos)
{
if (output[pos] == '\r')
{
output.erase(pos, 1);
}
else
{
output.replace(pos, 1, " ");
}
}
}
{
size_t pos{0};
while ((pos = output.find(" ", pos)) != string::npos)
{
output.replace(pos, 2, " ");
}
}
size_t pos{0};
while ((pos = output.find('\r', pos)) != string::npos)
{
output.erase(pos, 1);
}
pos = 0;
while ((pos = output.find_first_of("\n\t", pos)) != string::npos)
{
output.replace(pos, 1, " ");
}
pos = 0;
while ((pos = output.find(" ", pos)) != string::npos)
{
output.replace(pos, 2, " ");
}
pos = 0;
file_in_epub file;
size_t headline_start{string::npos};
while ((pos = output.find('<', pos)) != string::npos)

View File

@ -54,7 +54,7 @@ SCENARIO("Searching helpers work as intended")
}
THEN("No exception is thrown")
AND_THEN("The \\r are removed unchanged")
AND_THEN("The \\r are removed")
{
REQUIRE_FALSE(exception);
REQUIRE(text == "💖🦝");