Make whitespace-reduction a bit more efficient.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
We now use 2 passes instead of 3.
This commit is contained in:
parent
3966b99c3f
commit
f8270369b6
|
@ -133,26 +133,29 @@ file_in_epub cleanup_text(const std::string_view text)
|
||||||
"(title|aria-label)"
|
"(title|aria-label)"
|
||||||
"=\"([[:alnum:]]+)\""};
|
"=\"([[: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};
|
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;
|
file_in_epub file;
|
||||||
size_t headline_start{string::npos};
|
size_t headline_start{string::npos};
|
||||||
while ((pos = output.find('<', pos)) != string::npos)
|
while ((pos = output.find('<', pos)) != string::npos)
|
||||||
|
|
|
@ -54,7 +54,7 @@ SCENARIO("Searching helpers work as intended")
|
||||||
}
|
}
|
||||||
|
|
||||||
THEN("No exception is thrown")
|
THEN("No exception is thrown")
|
||||||
AND_THEN("The \\r are removed unchanged")
|
AND_THEN("The \\r are removed")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
REQUIRE_FALSE(exception);
|
||||||
REQUIRE(text == "💖🦝");
|
REQUIRE(text == "💖🦝");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user