aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-09-23 19:56:07 +0200
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2022-09-24 23:09:56 +0200
commit4fb7d1335a4660bb8748773294f2dea979fcdbb7 (patch)
treefd96cdd418dbc899926d02e5a22fcd31e4cd0549
parent77111086eb38f6075fd2e8e4da74acc32719be02 (diff)
downloadqpdf-4fb7d1335a4660bb8748773294f2dea979fcdbb7.tar.zst
Tune QPDF_String::useHexString()
-rw-r--r--libqpdf/QPDF_String.cc25
1 files changed, 10 insertions, 15 deletions
diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc
index b7064f44..b37682c9 100644
--- a/libqpdf/QPDF_String.cc
+++ b/libqpdf/QPDF_String.cc
@@ -7,12 +7,6 @@
// be used.
#include <string.h>
-// See above about ctype.
-static bool
-is_ascii_printable(char ch)
-{
- return ((ch >= 32) && (ch <= 126));
-}
static bool
is_iso_latin1_printable(char ch)
{
@@ -92,19 +86,20 @@ QPDF_String::useHexString() const
// there are any non-printable (in PDF Doc encoding) characters or
// if too large of a proportion of the string consists of
// non-ASCII characters.
- bool nonprintable = false;
unsigned int non_ascii = 0;
- for (unsigned int i = 0; i < this->val.length(); ++i) {
- char ch = this->val.at(i);
- if ((ch == 0) ||
- (!(is_ascii_printable(ch) || strchr("\n\r\t\b\f", ch)))) {
- if ((ch >= 0) && (ch < 24)) {
- nonprintable = true;
- }
+ for (auto const ch: this->val) {
+ if (ch > 126) {
+ ++non_ascii;
+ } else if (ch >= 32) {
+ continue;
+ } else if (ch < 0 || ch >= 24) {
++non_ascii;
+ } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' ||
+ ch == '\f')) {
+ return true;
}
}
- return (nonprintable || (5 * non_ascii > val.length()));
+ return 5 * non_ascii > val.length();
}
std::string