Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/core/html/track/vtt/VTTParser.cpp

Issue 104443002: Simplify VTTParser::collectTimeStamp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // Step 12.5.11 461 // Step 12.5.11
462 m_regionList.append(region); 462 m_regionList.append(region);
463 } 463 }
464 464
465 double VTTParser::collectTimeStamp(const String& line, unsigned* position) 465 double VTTParser::collectTimeStamp(const String& line, unsigned* position)
466 { 466 {
467 // Collect a WebVTT timestamp (5.3 WebVTT cue timings and settings parsing.) 467 // Collect a WebVTT timestamp (5.3 WebVTT cue timings and settings parsing.)
468 // Steps 1 - 4 - Initial checks, let most significant units be minutes. 468 // Steps 1 - 4 - Initial checks, let most significant units be minutes.
469 enum Mode { Minutes, Hours }; 469 enum Mode { Minutes, Hours };
470 Mode mode = Minutes; 470 Mode mode = Minutes;
471 if (*position >= line.length() || !isASCIIDigit(line[*position]))
472 return malformedTime;
473 471
474 int value1;
475 // Steps 5 - 7 - Collect a sequence of characters that are 0-9. 472 // Steps 5 - 7 - Collect a sequence of characters that are 0-9.
476 // If not 2 characters or value is greater than 59, interpret as hours. 473 // If not 2 characters or value is greater than 59, interpret as hours.
477 if (collectDigitsToInt(line, position, value1) != 2 || value1 > 59) 474 int value1;
475 unsigned value1Digits = collectDigitsToInt(line, position, value1);
476 if (!value1Digits)
477 return malformedTime;
478 if (value1Digits != 2 || value1 > 59)
478 mode = Hours; 479 mode = Hours;
479 480
480 // Steps 8 - 11 - Collect the next sequence of 0-9 after ':' (must be 2 char s). 481 // Steps 8 - 11 - Collect the next sequence of 0-9 after ':' (must be 2 char s).
481 if (*position >= line.length() || line[(*position)++] != ':') 482 if (*position >= line.length() || line[(*position)++] != ':')
482 return malformedTime; 483 return malformedTime;
483 if (*position >= line.length() || !isASCIIDigit(line[(*position)]))
484 return malformedTime;
485 int value2; 484 int value2;
486 if (collectDigitsToInt(line, position, value2) != 2) 485 if (collectDigitsToInt(line, position, value2) != 2)
487 return malformedTime; 486 return malformedTime;
488 487
489 // Step 12 - Detect whether this timestamp includes hours. 488 // Step 12 - Detect whether this timestamp includes hours.
490 int value3; 489 int value3;
491 if (mode == Hours || (*position < line.length() && line[*position] == ':')) { 490 if (mode == Hours || (*position < line.length() && line[*position] == ':')) {
492 if (*position >= line.length() || line[(*position)++] != ':') 491 if (*position >= line.length() || line[(*position)++] != ':')
493 return malformedTime; 492 return malformedTime;
494 if (*position >= line.length() || !isASCIIDigit(line[*position]))
495 return malformedTime;
496 if (collectDigitsToInt(line, position, value3) != 2) 493 if (collectDigitsToInt(line, position, value3) != 2)
497 return malformedTime; 494 return malformedTime;
498 } else { 495 } else {
499 value3 = value2; 496 value3 = value2;
500 value2 = value1; 497 value2 = value1;
501 value1 = 0; 498 value1 = 0;
502 } 499 }
503 500
504 // Steps 13 - 17 - Collect next sequence of 0-9 after '.' (must be 3 chars). 501 // Steps 13 - 17 - Collect next sequence of 0-9 after '.' (must be 3 chars).
505 if (*position >= line.length() || line[(*position)++] != '.') 502 if (*position >= line.length() || line[(*position)++] != '.')
506 return malformedTime; 503 return malformedTime;
507 if (*position >= line.length() || !isASCIIDigit(line[*position]))
508 return malformedTime;
509 int value4; 504 int value4;
510 if (collectDigitsToInt(line, position, value4) != 3) 505 if (collectDigitsToInt(line, position, value4) != 3)
511 return malformedTime; 506 return malformedTime;
512 if (value2 > 59 || value3 > 59) 507 if (value2 > 59 || value3 > 59)
513 return malformedTime; 508 return malformedTime;
514 509
515 // Steps 18 - 19 - Calculate result. 510 // Steps 18 - 19 - Calculate result.
516 return (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + (v alue4 * secondsPerMillisecond); 511 return (value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3 + (v alue4 * secondsPerMillisecond);
517 } 512 }
518 513
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum ent, "timestamp", charactersString)); 611 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum ent, "timestamp", charactersString));
617 break; 612 break;
618 } 613 }
619 default: 614 default:
620 break; 615 break;
621 } 616 }
622 } 617 }
623 618
624 } 619 }
625 620
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698