Commit 3d83638d8e7c6a9b74a60d8eddf980ea6f70e0b6

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