Commit a5d2e8877580fb74d21ca453dd143ce5d32904fd

Authored by m-holger
1 parent 7c32f6cc

Code tidy: replace if with case statement in QPDFTokenizer::inString

Showing 1 changed file with 20 additions and 9 deletions
libqpdf/QPDFTokenizer.cc
@@ -486,26 +486,37 @@ QPDFTokenizer::inHexstring(char ch) @@ -486,26 +486,37 @@ QPDFTokenizer::inHexstring(char ch)
486 void 486 void
487 QPDFTokenizer::inString(char ch) 487 QPDFTokenizer::inString(char ch)
488 { 488 {
489 - if (ch == '\\') { 489 + switch (ch) {
  490 + case '\\':
490 this->state = st_string_escape; 491 this->state = st_string_escape;
491 return; 492 return;
492 - } else if (ch == '(') { 493 +
  494 + case '(':
493 this->val += ch; 495 this->val += ch;
494 ++this->string_depth; 496 ++this->string_depth;
495 return; 497 return;
496 - } else if ((ch == ')') && (--this->string_depth == 0)) {  
497 - this->type = tt_string;  
498 - this->state = st_token_ready; 498 +
  499 + case ')':
  500 + if (--this->string_depth == 0) {
  501 + this->type = tt_string;
  502 + this->state = st_token_ready;
  503 + return;
  504 + }
  505 +
  506 + this->val += ch;
499 return; 507 return;
500 - } else if (ch == '\r') { 508 +
  509 + case '\r':
501 // CR by itself is converted to LF 510 // CR by itself is converted to LF
502 this->val += '\n'; 511 this->val += '\n';
503 this->state = st_string_after_cr; 512 this->state = st_string_after_cr;
504 return; 513 return;
505 - } else if (ch == '\n') { 514 +
  515 + case '\n':
506 this->val += ch; 516 this->val += ch;
507 return; 517 return;
508 - } else { 518 +
  519 + default:
509 this->val += ch; 520 this->val += ch;
510 return; 521 return;
511 } 522 }
@@ -524,7 +535,7 @@ QPDFTokenizer::inCharCode(char ch) @@ -524,7 +535,7 @@ QPDFTokenizer::inCharCode(char ch)
524 memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); 535 memset(this->bs_num_register, '\0', sizeof(this->bs_num_register));
525 bs_num_count = 0; 536 bs_num_count = 0;
526 this->state = st_in_string; 537 this->state = st_in_string;
527 - handleCharacter(ch); 538 + inString(ch);
528 return; 539 return;
529 } else if (ch_is_octal) { 540 } else if (ch_is_octal) {
530 this->bs_num_register[bs_num_count++] = ch; 541 this->bs_num_register[bs_num_count++] = ch;