Commit 3d83638d8e7c6a9b74a60d8eddf980ea6f70e0b6
Committed by
m-holger
1 parent
0f0502b1
Change QPDFParser private method names to snake_case
Co-authored-by: m-holger <34626170+m-holger@users.noreply.github.com>
Showing
2 changed files
with
44 additions
and
44 deletions
libqpdf/QPDFParser.cc
| ... | ... | @@ -224,28 +224,28 @@ QPDFParser::parse_first(bool content_stream) |
| 224 | 224 | input_, |
| 225 | 225 | (tokenizer_.getType() == QPDFTokenizer::tt_array_open) ? st_array : st_dictionary_key); |
| 226 | 226 | frame_ = &stack_.back(); |
| 227 | - return parseRemainder(content_stream); | |
| 227 | + return parse_remainder(content_stream); | |
| 228 | 228 | |
| 229 | 229 | case QPDFTokenizer::tt_bool: |
| 230 | - return withDescription<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 230 | + return with_description<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 231 | 231 | |
| 232 | 232 | case QPDFTokenizer::tt_null: |
| 233 | 233 | return {QPDFObject::create<QPDF_Null>()}; |
| 234 | 234 | |
| 235 | 235 | case QPDFTokenizer::tt_integer: |
| 236 | - return withDescription<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 236 | + return with_description<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 237 | 237 | |
| 238 | 238 | case QPDFTokenizer::tt_real: |
| 239 | - return withDescription<QPDF_Real>(tokenizer_.getValue()); | |
| 239 | + return with_description<QPDF_Real>(tokenizer_.getValue()); | |
| 240 | 240 | |
| 241 | 241 | case QPDFTokenizer::tt_name: |
| 242 | - return withDescription<QPDF_Name>(tokenizer_.getValue()); | |
| 242 | + return with_description<QPDF_Name>(tokenizer_.getValue()); | |
| 243 | 243 | |
| 244 | 244 | case QPDFTokenizer::tt_word: |
| 245 | 245 | { |
| 246 | 246 | auto const& value = tokenizer_.getValue(); |
| 247 | 247 | if (content_stream) { |
| 248 | - return withDescription<QPDF_Operator>(value); | |
| 248 | + return with_description<QPDF_Operator>(value); | |
| 249 | 249 | } else if (value == "endobj") { |
| 250 | 250 | // We just saw endobj without having read anything. Nothing in the PDF spec appears |
| 251 | 251 | // to allow empty objects, but they have been encountered in actual PDF files and |
| ... | ... | @@ -259,7 +259,7 @@ QPDFParser::parse_first(bool content_stream) |
| 259 | 259 | return {}; |
| 260 | 260 | } else { |
| 261 | 261 | warn("unknown token while reading object; treating as string"); |
| 262 | - return withDescription<QPDF_String>(value); | |
| 262 | + return with_description<QPDF_String>(value); | |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| ... | ... | @@ -267,9 +267,9 @@ QPDFParser::parse_first(bool content_stream) |
| 267 | 267 | if (decrypter_) { |
| 268 | 268 | std::string s{tokenizer_.getValue()}; |
| 269 | 269 | decrypter_->decryptString(s); |
| 270 | - return withDescription<QPDF_String>(s); | |
| 270 | + return with_description<QPDF_String>(s); | |
| 271 | 271 | } else { |
| 272 | - return withDescription<QPDF_String>(tokenizer_.getValue()); | |
| 272 | + return with_description<QPDF_String>(tokenizer_.getValue()); | |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | default: |
| ... | ... | @@ -279,7 +279,7 @@ QPDFParser::parse_first(bool content_stream) |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | QPDFObjectHandle |
| 282 | -QPDFParser::parseRemainder(bool content_stream) | |
| 282 | +QPDFParser::parse_remainder(bool content_stream) | |
| 283 | 283 | { |
| 284 | 284 | // This method must take care not to resolve any objects. Don't check the type of any object |
| 285 | 285 | // without first ensuring that it is a direct object. Otherwise, doing so may have the side |
| ... | ... | @@ -301,7 +301,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 301 | 301 | if (tokenizer_.getType() == QPDFTokenizer::tt_integer) { |
| 302 | 302 | if (++int_count_ > 2) { |
| 303 | 303 | // Process the oldest buffered integer. |
| 304 | - addInt(int_count_); | |
| 304 | + add_int(int_count_); | |
| 305 | 305 | } |
| 306 | 306 | last_offset_buffer_[int_count_ % 2] = input_.getLastOffset(); |
| 307 | 307 | int_buffer_[int_count_ % 2] = QUtil::string_to_ll(tokenizer_.getValue().c_str()); |
| ... | ... | @@ -330,9 +330,9 @@ QPDFParser::parseRemainder(bool content_stream) |
| 330 | 330 | } else if (int_count_ > 0) { |
| 331 | 331 | // Process the buffered integers before processing the current token. |
| 332 | 332 | if (int_count_ > 1) { |
| 333 | - addInt(int_count_ - 1); | |
| 333 | + add_int(int_count_ - 1); | |
| 334 | 334 | } |
| 335 | - addInt(int_count_); | |
| 335 | + add_int(int_count_); | |
| 336 | 336 | int_count_ = 0; |
| 337 | 337 | } |
| 338 | 338 | } |
| ... | ... | @@ -349,7 +349,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 349 | 349 | |
| 350 | 350 | case QPDFTokenizer::tt_bad: |
| 351 | 351 | check_too_many_bad_tokens(); |
| 352 | - addNull(); | |
| 352 | + add_null(); | |
| 353 | 353 | continue; |
| 354 | 354 | |
| 355 | 355 | case QPDFTokenizer::tt_brace_open: |
| ... | ... | @@ -362,7 +362,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 362 | 362 | auto object = frame_->null_count > 100 |
| 363 | 363 | ? QPDFObject::create<QPDF_Array>(std::move(frame_->olist), true) |
| 364 | 364 | : QPDFObject::create<QPDF_Array>(std::move(frame_->olist)); |
| 365 | - setDescription(object, frame_->offset - 1); | |
| 365 | + set_description(object, frame_->offset - 1); | |
| 366 | 366 | // The `offset` points to the next of "[". Set the rewind offset to point to the |
| 367 | 367 | // beginning of "[". This has been explicitly tested with whitespace surrounding the |
| 368 | 368 | // array start delimiter. getLastOffset points to the array end token and therefore |
| ... | ... | @@ -401,7 +401,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 401 | 401 | frame_->offset, |
| 402 | 402 | "expected dictionary keys but found non-name objects; ignoring"); |
| 403 | 403 | } else { |
| 404 | - fixMissingKeys(); | |
| 404 | + fix_missing_keys(); | |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| ... | ... | @@ -412,7 +412,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 412 | 412 | dict["/Contents"].setParsedOffset(frame_->contents_offset); |
| 413 | 413 | } |
| 414 | 414 | auto object = QPDFObject::create<QPDF_Dictionary>(std::move(dict)); |
| 415 | - setDescription(object, frame_->offset - 2); | |
| 415 | + set_description(object, frame_->offset - 2); | |
| 416 | 416 | // The `offset` points to the next of "<<". Set the rewind offset to point to the |
| 417 | 417 | // beginning of "<<". This has been explicitly tested with whitespace surrounding |
| 418 | 418 | // the dictionary start delimiter. getLastOffset points to the dictionary end token |
| ... | ... | @@ -449,11 +449,11 @@ QPDFParser::parseRemainder(bool content_stream) |
| 449 | 449 | continue; |
| 450 | 450 | |
| 451 | 451 | case QPDFTokenizer::tt_bool: |
| 452 | - addScalar<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 452 | + add_scalar<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 453 | 453 | continue; |
| 454 | 454 | |
| 455 | 455 | case QPDFTokenizer::tt_null: |
| 456 | - addNull(); | |
| 456 | + add_null(); | |
| 457 | 457 | continue; |
| 458 | 458 | |
| 459 | 459 | case QPDFTokenizer::tt_integer: |
| ... | ... | @@ -463,12 +463,12 @@ QPDFParser::parseRemainder(bool content_stream) |
| 463 | 463 | int_buffer_[1] = QUtil::string_to_ll(tokenizer_.getValue().c_str()); |
| 464 | 464 | int_count_ = 1; |
| 465 | 465 | } else { |
| 466 | - addScalar<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 466 | + add_scalar<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 467 | 467 | } |
| 468 | 468 | continue; |
| 469 | 469 | |
| 470 | 470 | case QPDFTokenizer::tt_real: |
| 471 | - addScalar<QPDF_Real>(tokenizer_.getValue()); | |
| 471 | + add_scalar<QPDF_Real>(tokenizer_.getValue()); | |
| 472 | 472 | continue; |
| 473 | 473 | |
| 474 | 474 | case QPDFTokenizer::tt_name: |
| ... | ... | @@ -478,13 +478,13 @@ QPDFParser::parseRemainder(bool content_stream) |
| 478 | 478 | b_contents = decrypter_ && frame_->key == "/Contents"; |
| 479 | 479 | continue; |
| 480 | 480 | } else { |
| 481 | - addScalar<QPDF_Name>(tokenizer_.getValue()); | |
| 481 | + add_scalar<QPDF_Name>(tokenizer_.getValue()); | |
| 482 | 482 | } |
| 483 | 483 | continue; |
| 484 | 484 | |
| 485 | 485 | case QPDFTokenizer::tt_word: |
| 486 | 486 | if (content_stream) { |
| 487 | - addScalar<QPDF_Operator>(tokenizer_.getValue()); | |
| 487 | + add_scalar<QPDF_Operator>(tokenizer_.getValue()); | |
| 488 | 488 | continue; |
| 489 | 489 | } |
| 490 | 490 | |
| ... | ... | @@ -504,7 +504,7 @@ QPDFParser::parseRemainder(bool content_stream) |
| 504 | 504 | |
| 505 | 505 | warn("unknown token while reading object; treating as string"); |
| 506 | 506 | check_too_many_bad_tokens(); |
| 507 | - addScalar<QPDF_String>(tokenizer_.getValue()); | |
| 507 | + add_scalar<QPDF_String>(tokenizer_.getValue()); | |
| 508 | 508 | |
| 509 | 509 | continue; |
| 510 | 510 | |
| ... | ... | @@ -519,9 +519,9 @@ QPDFParser::parseRemainder(bool content_stream) |
| 519 | 519 | } |
| 520 | 520 | std::string s{val}; |
| 521 | 521 | decrypter_->decryptString(s); |
| 522 | - addScalar<QPDF_String>(s); | |
| 522 | + add_scalar<QPDF_String>(s); | |
| 523 | 523 | } else { |
| 524 | - addScalar<QPDF_String>(val); | |
| 524 | + add_scalar<QPDF_String>(val); | |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | 527 | continue; |
| ... | ... | @@ -541,14 +541,14 @@ QPDFParser::add(std::shared_ptr<QPDFObject>&& obj) |
| 541 | 541 | frame_->olist.emplace_back(std::move(obj)); |
| 542 | 542 | } else { |
| 543 | 543 | if (auto res = frame_->dict.insert_or_assign(frame_->key, std::move(obj)); !res.second) { |
| 544 | - warnDuplicateKey(); | |
| 544 | + warn_duplicate_key(); | |
| 545 | 545 | } |
| 546 | 546 | frame_->state = st_dictionary_key; |
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | void |
| 551 | -QPDFParser::addNull() | |
| 551 | +QPDFParser::add_null() | |
| 552 | 552 | { |
| 553 | 553 | const static ObjectPtr null_obj = QPDFObject::create<QPDF_Null>(); |
| 554 | 554 | |
| ... | ... | @@ -558,7 +558,7 @@ QPDFParser::addNull() |
| 558 | 558 | frame_->olist.emplace_back(null_obj); |
| 559 | 559 | } else { |
| 560 | 560 | if (auto res = frame_->dict.insert_or_assign(frame_->key, null_obj); !res.second) { |
| 561 | - warnDuplicateKey(); | |
| 561 | + warn_duplicate_key(); | |
| 562 | 562 | } |
| 563 | 563 | frame_->state = st_dictionary_key; |
| 564 | 564 | } |
| ... | ... | @@ -570,11 +570,11 @@ QPDFParser::add_bad_null(std::string const& msg) |
| 570 | 570 | { |
| 571 | 571 | warn(msg); |
| 572 | 572 | check_too_many_bad_tokens(); |
| 573 | - addNull(); | |
| 573 | + add_null(); | |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | void |
| 577 | -QPDFParser::addInt(int count) | |
| 577 | +QPDFParser::add_int(int count) | |
| 578 | 578 | { |
| 579 | 579 | auto obj = QPDFObject::create<QPDF_Integer>(int_buffer_[count % 2]); |
| 580 | 580 | obj->setDescription(context_, description_, last_offset_buffer_[count % 2]); |
| ... | ... | @@ -583,7 +583,7 @@ QPDFParser::addInt(int count) |
| 583 | 583 | |
| 584 | 584 | template <typename T, typename... Args> |
| 585 | 585 | void |
| 586 | -QPDFParser::addScalar(Args&&... args) | |
| 586 | +QPDFParser::add_scalar(Args&&... args) | |
| 587 | 587 | { |
| 588 | 588 | auto limit = Limits::parser_max_container_size(bad_count_ || sanity_checks_); |
| 589 | 589 | if (frame_->olist.size() >= limit || frame_->dict.size() >= limit) { |
| ... | ... | @@ -599,7 +599,7 @@ QPDFParser::addScalar(Args&&... args) |
| 599 | 599 | |
| 600 | 600 | template <typename T, typename... Args> |
| 601 | 601 | QPDFObjectHandle |
| 602 | -QPDFParser::withDescription(Args&&... args) | |
| 602 | +QPDFParser::with_description(Args&&... args) | |
| 603 | 603 | { |
| 604 | 604 | auto obj = QPDFObject::create<T>(std::forward<Args>(args)...); |
| 605 | 605 | obj->setDescription(context_, description_, start_); |
| ... | ... | @@ -607,7 +607,7 @@ QPDFParser::withDescription(Args&&... args) |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | void |
| 610 | -QPDFParser::setDescription(ObjectPtr& obj, qpdf_offset_t parsed_offset) | |
| 610 | +QPDFParser::set_description(ObjectPtr& obj, qpdf_offset_t parsed_offset) | |
| 611 | 611 | { |
| 612 | 612 | if (obj) { |
| 613 | 613 | obj->setDescription(context_, description_, parsed_offset); |
| ... | ... | @@ -615,7 +615,7 @@ QPDFParser::setDescription(ObjectPtr& obj, qpdf_offset_t parsed_offset) |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | void |
| 618 | -QPDFParser::fixMissingKeys() | |
| 618 | +QPDFParser::fix_missing_keys() | |
| 619 | 619 | { |
| 620 | 620 | std::set<std::string> names; |
| 621 | 621 | for (auto& obj: frame_->olist) { |
| ... | ... | @@ -697,7 +697,7 @@ QPDFParser::warn(QPDFExc const& e) const |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | void |
| 700 | -QPDFParser::warnDuplicateKey() | |
| 700 | +QPDFParser::warn_duplicate_key() | |
| 701 | 701 | { |
| 702 | 702 | warn( |
| 703 | 703 | frame_->offset, | ... | ... |
libqpdf/qpdf/QPDFParser.hh
| ... | ... | @@ -114,16 +114,16 @@ class QPDFParser |
| 114 | 114 | |
| 115 | 115 | QPDFObjectHandle parse(bool content_stream = false); |
| 116 | 116 | QPDFObjectHandle parse_first(bool content_stream); |
| 117 | - QPDFObjectHandle parseRemainder(bool content_stream); | |
| 117 | + QPDFObjectHandle parse_remainder(bool content_stream); | |
| 118 | 118 | void add(std::shared_ptr<QPDFObject>&& obj); |
| 119 | - void addNull(); | |
| 119 | + void add_null(); | |
| 120 | 120 | void add_bad_null(std::string const& msg); |
| 121 | - void addInt(int count); | |
| 121 | + void add_int(int count); | |
| 122 | 122 | template <typename T, typename... Args> |
| 123 | - void addScalar(Args&&... args); | |
| 123 | + void add_scalar(Args&&... args); | |
| 124 | 124 | void check_too_many_bad_tokens(); |
| 125 | - void warnDuplicateKey(); | |
| 126 | - void fixMissingKeys(); | |
| 125 | + void warn_duplicate_key(); | |
| 126 | + void fix_missing_keys(); | |
| 127 | 127 | [[noreturn]] void limits_error(std::string const& limit, std::string const& msg); |
| 128 | 128 | void warn(qpdf_offset_t offset, std::string const& msg) const; |
| 129 | 129 | void warn(std::string const& msg) const; |
| ... | ... | @@ -131,8 +131,8 @@ class QPDFParser |
| 131 | 131 | template <typename T, typename... Args> |
| 132 | 132 | // Create a new scalar object complete with parsed offset and description. |
| 133 | 133 | // NB the offset includes any leading whitespace. |
| 134 | - QPDFObjectHandle withDescription(Args&&... args); | |
| 135 | - void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); | |
| 134 | + QPDFObjectHandle with_description(Args&&... args); | |
| 135 | + void set_description(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); | |
| 136 | 136 | InputSource& input_; |
| 137 | 137 | std::string const& object_description_; |
| 138 | 138 | qpdf::Tokenizer& tokenizer_; | ... | ... |