Commit 4fb7d1335a4660bb8748773294f2dea979fcdbb7

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 77111086

Tune QPDF_String::useHexString()

Showing 1 changed file with 10 additions and 15 deletions
libqpdf/QPDF_String.cc
@@ -7,12 +7,6 @@ @@ -7,12 +7,6 @@
7 // be used. 7 // be used.
8 #include <string.h> 8 #include <string.h>
9 9
10 -// See above about ctype.  
11 -static bool  
12 -is_ascii_printable(char ch)  
13 -{  
14 - return ((ch >= 32) && (ch <= 126));  
15 -}  
16 static bool 10 static bool
17 is_iso_latin1_printable(char ch) 11 is_iso_latin1_printable(char ch)
18 { 12 {
@@ -92,19 +86,20 @@ QPDF_String::useHexString() const @@ -92,19 +86,20 @@ QPDF_String::useHexString() const
92 // there are any non-printable (in PDF Doc encoding) characters or 86 // there are any non-printable (in PDF Doc encoding) characters or
93 // if too large of a proportion of the string consists of 87 // if too large of a proportion of the string consists of
94 // non-ASCII characters. 88 // non-ASCII characters.
95 - bool nonprintable = false;  
96 unsigned int non_ascii = 0; 89 unsigned int non_ascii = 0;
97 - for (unsigned int i = 0; i < this->val.length(); ++i) {  
98 - char ch = this->val.at(i);  
99 - if ((ch == 0) ||  
100 - (!(is_ascii_printable(ch) || strchr("\n\r\t\b\f", ch)))) {  
101 - if ((ch >= 0) && (ch < 24)) {  
102 - nonprintable = true;  
103 - } 90 + for (auto const ch: this->val) {
  91 + if (ch > 126) {
  92 + ++non_ascii;
  93 + } else if (ch >= 32) {
  94 + continue;
  95 + } else if (ch < 0 || ch >= 24) {
104 ++non_ascii; 96 ++non_ascii;
  97 + } else if (!(ch == '\n' || ch == '\r' || ch == '\t' || ch == '\b' ||
  98 + ch == '\f')) {
  99 + return true;
105 } 100 }
106 } 101 }
107 - return (nonprintable || (5 * non_ascii > val.length())); 102 + return 5 * non_ascii > val.length();
108 } 103 }
109 104
110 std::string 105 std::string