diff --git a/libqpdf/ContentNormalizer.cc b/libqpdf/ContentNormalizer.cc index 47830f42..9da6fa1c 100644 --- a/libqpdf/ContentNormalizer.cc +++ b/libqpdf/ContentNormalizer.cc @@ -11,7 +11,6 @@ ContentNormalizer::ContentNormalizer() : void ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) { - std::string value = token.getRawValue(); QPDFTokenizer::token_type_e token_type = token.getType(); if (token_type == QPDFTokenizer::tt_bad) { @@ -24,6 +23,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) switch (token_type) { case QPDFTokenizer::tt_space: { + std::string const& value = token.getRawValue(); size_t len = value.length(); for (size_t i = 0; i < len; ++i) { char ch = value.at(i); @@ -38,7 +38,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) } } } - break; + return; case QPDFTokenizer::tt_string: // Replacing string and name tokens in this way normalizes their representation as this will @@ -52,12 +52,12 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token) default: writeToken(token); - break; + return; } - value = token.getRawValue(); - if (((token_type == QPDFTokenizer::tt_string) || (token_type == QPDFTokenizer::tt_name)) && - ((value.find('\r') != std::string::npos) || (value.find('\n') != std::string::npos))) { + // tt_string or tt_name + std::string const& value = token.getRawValue(); + if (value.find('\r') != std::string::npos || value.find('\n') != std::string::npos) { write("\n"); } } diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 4eaa2236..f2ab1d3e 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -148,7 +148,7 @@ QPDFObjectHandle::TokenFilter::write(std::string const& str) void QPDFObjectHandle::TokenFilter::writeToken(QPDFTokenizer::Token const& token) { - std::string value = token.getRawValue(); + std::string const& value = token.getRawValue(); write(value.c_str(), value.length()); }