Commit f9530a581522a418b8298791969ac8a0e002dfff

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