2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

In ContentNormalizer::handleToken refactor handling of space tokens

Avoid writing each space char individually.
This commit is contained in:
m-holger 2024-07-27 18:06:12 +01:00
parent ffe462e67e
commit 4783b22312

View File

@ -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 { }
if (++r_pos >= size) {
write("\n");
return;
}
if (value[r_pos] != '\n') {
write("\n"); write("\n");
} }
} else { pos = r_pos;
write(&ch, 1); r_pos = value.find('\r', pos);
} }
if (pos < size) {
write(&value[pos], size - pos);
} }
} }
return; return;