mirror of
https://github.com/qpdf/qpdf.git
synced 2024-11-08 14:21:06 +00:00
In ContentNormalizer::handleToken refactor handling of space tokens
Avoid writing each space char individually.
This commit is contained in:
parent
ffe462e67e
commit
4783b22312
@ -25,18 +25,25 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
|
|||||||
case QPDFTokenizer::tt_space:
|
case QPDFTokenizer::tt_space:
|
||||||
{
|
{
|
||||||
std::string const& value = token.getRawValue();
|
std::string const& value = token.getRawValue();
|
||||||
size_t len = value.length();
|
auto size = value.size();
|
||||||
for (size_t i = 0; i < len; ++i) {
|
size_t pos = 0;
|
||||||
char ch = value.at(i);
|
auto r_pos = value.find('\r');
|
||||||
if (ch == '\r') {
|
while (r_pos != std::string::npos) {
|
||||||
if ((i + 1 < len) && (value.at(i + 1) == '\n')) {
|
if (pos != r_pos) {
|
||||||
// ignore
|
write(&value[pos], r_pos - pos);
|
||||||
} else {
|
|
||||||
write("\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
write(&ch, 1);
|
|
||||||
}
|
}
|
||||||
|
if (++r_pos >= size) {
|
||||||
|
write("\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (value[r_pos] != '\n') {
|
||||||
|
write("\n");
|
||||||
|
}
|
||||||
|
pos = r_pos;
|
||||||
|
r_pos = value.find('\r', pos);
|
||||||
|
}
|
||||||
|
if (pos < size) {
|
||||||
|
write(&value[pos], size - pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user