Commit f9530a581522a418b8298791969ac8a0e002dfff
1 parent
86ade3f9
Code tidy: replace if with case statement in QPDFTokenizer::handleCharacter
Showing
1 changed file
with
34 additions
and
12 deletions
libqpdf/QPDFTokenizer.cc
| ... | ... | @@ -233,46 +233,68 @@ QPDFTokenizer::handleCharacter(char ch) |
| 233 | 233 | this->state = st_in_space; |
| 234 | 234 | this->val += ch; |
| 235 | 235 | } |
| 236 | - } else if (ch == '%') { | |
| 236 | + return; | |
| 237 | + } | |
| 238 | + switch (ch) { | |
| 239 | + case '%': | |
| 237 | 240 | this->state = st_in_comment; |
| 238 | 241 | if (this->include_ignorable) { |
| 239 | 242 | this->val += ch; |
| 240 | 243 | } |
| 241 | - } else if (ch == '(') { | |
| 244 | + return; | |
| 245 | + | |
| 246 | + case '(': | |
| 242 | 247 | this->string_depth = 1; |
| 243 | 248 | this->string_ignoring_newline = false; |
| 244 | 249 | memset(this->bs_num_register, '\0', sizeof(this->bs_num_register)); |
| 245 | 250 | this->last_char_was_bs = false; |
| 246 | 251 | this->last_char_was_cr = false; |
| 247 | 252 | this->state = st_in_string; |
| 248 | - } else if (ch == '<') { | |
| 253 | + return; | |
| 254 | + | |
| 255 | + case '<': | |
| 249 | 256 | this->state = st_lt; |
| 250 | - } else if (ch == '>') { | |
| 257 | + return; | |
| 258 | + | |
| 259 | + case '>': | |
| 251 | 260 | this->state = st_gt; |
| 252 | - } else { | |
| 261 | + return; | |
| 262 | + | |
| 263 | + default: | |
| 253 | 264 | this->val += ch; |
| 254 | - if (ch == ')') { | |
| 265 | + switch (ch) { | |
| 266 | + case ')': | |
| 255 | 267 | this->type = tt_bad; |
| 256 | 268 | QTC::TC("qpdf", "QPDFTokenizer bad )"); |
| 257 | 269 | this->error_message = "unexpected )"; |
| 258 | 270 | this->state = st_token_ready; |
| 259 | - } else if (ch == '[') { | |
| 271 | + return; | |
| 272 | + | |
| 273 | + case '[': | |
| 260 | 274 | this->type = tt_array_open; |
| 261 | 275 | this->state = st_token_ready; |
| 262 | - } else if (ch == ']') { | |
| 276 | + return; | |
| 277 | + | |
| 278 | + case ']': | |
| 263 | 279 | this->type = tt_array_close; |
| 264 | 280 | this->state = st_token_ready; |
| 265 | - } else if (ch == '{') { | |
| 281 | + return; | |
| 282 | + | |
| 283 | + case '{': | |
| 266 | 284 | this->type = tt_brace_open; |
| 267 | 285 | this->state = st_token_ready; |
| 268 | - } else if (ch == '}') { | |
| 286 | + return; | |
| 287 | + | |
| 288 | + case '}': | |
| 269 | 289 | this->type = tt_brace_close; |
| 270 | 290 | this->state = st_token_ready; |
| 271 | - } else { | |
| 291 | + return; | |
| 292 | + | |
| 293 | + default: | |
| 272 | 294 | this->state = st_literal; |
| 295 | + return; | |
| 273 | 296 | } |
| 274 | 297 | } |
| 275 | - return; | |
| 276 | 298 | |
| 277 | 299 | case st_in_space: |
| 278 | 300 | // We only enter this state if include_ignorable is true. | ... | ... |