Commit e7889ec5dc3ae5caf942bb242f802b7a19a6b2c5

Authored by m-holger
1 parent e4fe0d5c

Refactor st_top case in QPDFTokenizer::handleCharacter

Showing 1 changed file with 36 additions and 33 deletions
libqpdf/QPDFTokenizer.cc
... ... @@ -222,7 +222,7 @@ QPDFTokenizer::handleCharacter(char ch)
222 222 "INTERNAL ERROR: QPDF tokenizer presented character "
223 223 "while token is waiting");
224 224  
225   - case (st_top):
  225 + case st_top:
226 226 // Note: we specifically do not use ctype here. It is
227 227 // locale-dependent.
228 228 if (isSpace(ch)) {
... ... @@ -254,40 +254,42 @@ QPDFTokenizer::handleCharacter(char ch)
254 254 this->state = st_gt;
255 255 return;
256 256  
257   - default:
  257 + case (')'):
  258 + this->type = tt_bad;
  259 + QTC::TC("qpdf", "QPDFTokenizer bad )");
  260 + this->error_message = "unexpected )";
258 261 this->val += ch;
259   - switch (ch) {
260   - case ')':
261   - this->type = tt_bad;
262   - QTC::TC("qpdf", "QPDFTokenizer bad )");
263   - this->error_message = "unexpected )";
264   - this->state = st_token_ready;
265   - return;
  262 + this->state = st_token_ready;
  263 + return;
266 264  
267   - case '[':
268   - this->type = tt_array_open;
269   - this->state = st_token_ready;
270   - return;
  265 + case '[':
  266 + this->type = tt_array_open;
  267 + this->state = st_token_ready;
  268 + this->val += ch;
  269 + return;
271 270  
272   - case ']':
273   - this->type = tt_array_close;
274   - this->state = st_token_ready;
275   - return;
  271 + case ']':
  272 + this->type = tt_array_close;
  273 + this->val += ch;
  274 + this->state = st_token_ready;
  275 + return;
276 276  
277   - case '{':
278   - this->type = tt_brace_open;
279   - this->state = st_token_ready;
280   - return;
  277 + case '{':
  278 + this->type = tt_brace_open;
  279 + this->state = st_token_ready;
  280 + this->val += ch;
  281 + return;
281 282  
282   - case '}':
283   - this->type = tt_brace_close;
284   - this->state = st_token_ready;
285   - return;
  283 + case '}':
  284 + this->type = tt_brace_close;
  285 + this->state = st_token_ready;
  286 + this->val += ch;
  287 + return;
286 288  
287   - default:
288   - this->state = st_literal;
289   - return;
290   - }
  289 + default:
  290 + this->state = st_literal;
  291 + this->val += ch;
  292 + return;
291 293 }
292 294  
293 295 case st_in_space:
... ... @@ -297,10 +299,11 @@ QPDFTokenizer::handleCharacter(char ch)
297 299 this->unread_char = true;
298 300 this->char_to_unread = ch;
299 301 this->state = st_token_ready;
  302 + return;
300 303 } else {
301 304 this->val += ch;
  305 + return;
302 306 }
303   - return;
304 307  
305 308 case st_in_comment:
306 309 if ((ch == '\r') || (ch == '\n')) {
... ... @@ -345,7 +348,7 @@ QPDFTokenizer::handleCharacter(char ch)
345 348 }
346 349 return;
347 350  
348   - case st_in_string:
  351 + case (st_in_string):
349 352 inString(ch);
350 353 return;
351 354  
... ... @@ -438,11 +441,11 @@ QPDFTokenizer::handleCharacter(char ch)
438 441 }
439 442 return;
440 443  
441   - case (st_in_hexstring):
  444 + case st_in_hexstring:
442 445 inHexstring(ch);
443 446 return;
444 447  
445   - case (st_in_hexstring_2nd):
  448 + case st_in_hexstring_2nd:
446 449 inHexstring2nd(ch);
447 450 return;
448 451  
... ...