Commit cf945eeabfea822d5aeb7b1d860dbc3a4eeedfa3
1 parent
45a6100c
Avoid shrinking QPDFTokenizer::val and QPDFTokenizer::raw_val
Showing
1 changed file
with
11 additions
and
8 deletions
libqpdf/QPDFTokenizer.cc
| ... | ... | @@ -78,8 +78,8 @@ QPDFTokenizer::reset() |
| 78 | 78 | { |
| 79 | 79 | state = st_top; |
| 80 | 80 | type = tt_bad; |
| 81 | - val = ""; | |
| 82 | - raw_val = ""; | |
| 81 | + val.clear(); | |
| 82 | + raw_val.clear(); | |
| 83 | 83 | error_message = ""; |
| 84 | 84 | unread_char = false; |
| 85 | 85 | char_to_unread = '\0'; |
| ... | ... | @@ -175,7 +175,8 @@ QPDFTokenizer::resolveLiteral() |
| 175 | 175 | nval.append(1, ch); |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | - this->val = nval; | |
| 178 | + this->val.clear(); | |
| 179 | + this->val += nval; | |
| 179 | 180 | } else if (QUtil::is_number(this->val.c_str())) { |
| 180 | 181 | if (this->val.find('.') != std::string::npos) { |
| 181 | 182 | this->type = tt_real; |
| ... | ... | @@ -282,7 +283,7 @@ QPDFTokenizer::presentCharacter(char ch) |
| 282 | 283 | } |
| 283 | 284 | } else if (this->state == st_lt) { |
| 284 | 285 | if (ch == '<') { |
| 285 | - this->val = "<<"; | |
| 286 | + this->val += "<<"; | |
| 286 | 287 | this->type = tt_dict_open; |
| 287 | 288 | this->state = st_token_ready; |
| 288 | 289 | } else { |
| ... | ... | @@ -291,11 +292,11 @@ QPDFTokenizer::presentCharacter(char ch) |
| 291 | 292 | } |
| 292 | 293 | } else if (this->state == st_gt) { |
| 293 | 294 | if (ch == '>') { |
| 294 | - this->val = ">>"; | |
| 295 | + this->val += ">>"; | |
| 295 | 296 | this->type = tt_dict_close; |
| 296 | 297 | this->state = st_token_ready; |
| 297 | 298 | } else { |
| 298 | - this->val = ">"; | |
| 299 | + this->val += ">"; | |
| 299 | 300 | this->type = tt_bad; |
| 300 | 301 | QTC::TC("qpdf", "QPDFTokenizer bad >"); |
| 301 | 302 | this->error_message = "unexpected >"; |
| ... | ... | @@ -437,7 +438,8 @@ QPDFTokenizer::presentCharacter(char ch) |
| 437 | 438 | char nch = static_cast<char>(strtol(num, nullptr, 16)); |
| 438 | 439 | nval += nch; |
| 439 | 440 | } |
| 440 | - this->val = nval; | |
| 441 | + this->val.clear(); | |
| 442 | + this->val += nval; | |
| 441 | 443 | } else if (QUtil::is_hex_digit(ch)) { |
| 442 | 444 | this->val += ch; |
| 443 | 445 | } else if (isSpace(ch)) { |
| ... | ... | @@ -600,7 +602,8 @@ QPDFTokenizer::getToken(Token& token, bool& unread_char, char& ch) |
| 600 | 602 | ch = this->char_to_unread; |
| 601 | 603 | if (ready) { |
| 602 | 604 | if (this->type == tt_bad) { |
| 603 | - this->val = this->raw_val; | |
| 605 | + this->val.clear(); | |
| 606 | + this->val += this->raw_val; | |
| 604 | 607 | } |
| 605 | 608 | token = |
| 606 | 609 | Token(this->type, this->val, this->raw_val, this->error_message); | ... | ... |