2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-24 15:48:29 +00:00

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

This commit is contained in:
m-holger 2022-08-18 18:25:51 +01:00
parent 86ade3f9cd
commit f9530a5815

View File

@ -233,47 +233,69 @@ QPDFTokenizer::handleCharacter(char ch)
this->state = st_in_space; this->state = st_in_space;
this->val += ch; this->val += ch;
} }
} else if (ch == '%') { return;
}
switch (ch) {
case '%':
this->state = st_in_comment; this->state = st_in_comment;
if (this->include_ignorable) { if (this->include_ignorable) {
this->val += ch; this->val += ch;
} }
} else if (ch == '(') { return;
case '(':
this->string_depth = 1; this->string_depth = 1;
this->string_ignoring_newline = false; this->string_ignoring_newline = false;
memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); memset(this->bs_num_register, '\0', sizeof(this->bs_num_register));
this->last_char_was_bs = false; this->last_char_was_bs = false;
this->last_char_was_cr = false; this->last_char_was_cr = false;
this->state = st_in_string; this->state = st_in_string;
} else if (ch == '<') { return;
case '<':
this->state = st_lt; this->state = st_lt;
} else if (ch == '>') { return;
case '>':
this->state = st_gt; this->state = st_gt;
} else { return;
default:
this->val += ch; this->val += ch;
if (ch == ')') { switch (ch) {
case ')':
this->type = tt_bad; this->type = tt_bad;
QTC::TC("qpdf", "QPDFTokenizer bad )"); QTC::TC("qpdf", "QPDFTokenizer bad )");
this->error_message = "unexpected )"; this->error_message = "unexpected )";
this->state = st_token_ready; this->state = st_token_ready;
} else if (ch == '[') { return;
case '[':
this->type = tt_array_open; this->type = tt_array_open;
this->state = st_token_ready; this->state = st_token_ready;
} else if (ch == ']') { return;
case ']':
this->type = tt_array_close; this->type = tt_array_close;
this->state = st_token_ready; this->state = st_token_ready;
} else if (ch == '{') { return;
case '{':
this->type = tt_brace_open; this->type = tt_brace_open;
this->state = st_token_ready; this->state = st_token_ready;
} else if (ch == '}') { return;
case '}':
this->type = tt_brace_close; this->type = tt_brace_close;
this->state = st_token_ready; this->state = st_token_ready;
} else {
this->state = st_literal;
}
}
return; return;
default:
this->state = st_literal;
return;
}
}
case st_in_space: case st_in_space:
// We only enter this state if include_ignorable is true. // We only enter this state if include_ignorable is true.
if (!isSpace(ch)) { if (!isSpace(ch)) {