| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 using namespace HTMLNames; | 44 using namespace HTMLNames; |
| 45 | 45 |
| 46 const double secondsPerHour = 3600; | 46 const double secondsPerHour = 3600; |
| 47 const double secondsPerMinute = 60; | 47 const double secondsPerMinute = 60; |
| 48 const double secondsPerMillisecond = 0.001; | 48 const double secondsPerMillisecond = 0.001; |
| 49 const unsigned fileIdentifierLength = 6; | 49 const unsigned fileIdentifierLength = 6; |
| 50 | 50 |
| 51 static unsigned scanDigits(const String& input, unsigned* position) | |
| 52 { | |
| 53 unsigned startPosition = *position; | |
| 54 while (*position < input.length() && isASCIIDigit(input[*position])) | |
| 55 (*position)++; | |
| 56 return *position - startPosition; | |
| 57 } | |
| 58 | |
| 59 unsigned VTTParser::collectDigitsToInt(const String& input, unsigned* position,
int& number) | 51 unsigned VTTParser::collectDigitsToInt(const String& input, unsigned* position,
int& number) |
| 60 { | 52 { |
| 61 VTTLegacyScanner inputScanner(input, position); | 53 VTTLegacyScanner inputScanner(input, position); |
| 62 return inputScanner.scanDigits(number); | 54 return inputScanner.scanDigits(number); |
| 63 } | 55 } |
| 64 | 56 |
| 65 bool VTTParser::parseFloatPercentageValue(const String& value, float& percentage
) | 57 bool VTTParser::parseFloatPercentageValue(VTTScanner& valueScanner, float& perce
ntage) |
| 66 { | 58 { |
| 59 float number; |
| 60 if (!valueScanner.scanFloat(number)) |
| 61 return false; |
| 67 // '%' must be present and at the end of the setting value. | 62 // '%' must be present and at the end of the setting value. |
| 68 if (value.isEmpty() || value[value.length() - 1] != '%') | 63 if (!valueScanner.scan('%')) |
| 69 return false; | 64 return false; |
| 70 | |
| 71 unsigned position = 0; | |
| 72 unsigned digitsBeforeDot = scanDigits(value, &position); | |
| 73 unsigned digitsAfterDot = 0; | |
| 74 if (value[position] == '.') { | |
| 75 position++; | |
| 76 | |
| 77 digitsAfterDot = scanDigits(value, &position); | |
| 78 } | |
| 79 | |
| 80 // At least one digit required. | |
| 81 if (!digitsBeforeDot && !digitsAfterDot) | |
| 82 return false; | |
| 83 | |
| 84 float number = value.toFloat(); | |
| 85 if (number < 0 || number > 100) | 65 if (number < 0 || number > 100) |
| 86 return false; | 66 return false; |
| 87 | |
| 88 percentage = number; | 67 percentage = number; |
| 89 return true; | 68 return true; |
| 90 } | 69 } |
| 91 | 70 |
| 92 bool VTTParser::parseFloatPercentageValuePair(const String& value, char delimite
r, FloatPoint& valuePair) | 71 bool VTTParser::parseFloatPercentageValuePair(const String& value, char delimite
r, FloatPoint& valuePair) |
| 93 { | 72 { |
| 94 // The delimiter can't be the first or second value because a pair of | 73 VTTScanner valueScanner(value); |
| 95 // percentages (x%,y%) implies that at least the first two characters | 74 |
| 96 // are the first percentage value. | 75 float firstCoord; |
| 97 size_t delimiterOffset = value.find(delimiter, 2); | 76 if (!parseFloatPercentageValue(valueScanner, firstCoord)) |
| 98 if (delimiterOffset == kNotFound || delimiterOffset == value.length() - 1) | |
| 99 return false; | 77 return false; |
| 100 | 78 |
| 101 float firstCoord; | 79 if (!valueScanner.scan(delimiter)) |
| 102 if (!parseFloatPercentageValue(value.substring(0, delimiterOffset), firstCoo
rd)) | |
| 103 return false; | 80 return false; |
| 104 | 81 |
| 105 float secondCoord; | 82 float secondCoord; |
| 106 if (!parseFloatPercentageValue(value.substring(delimiterOffset + 1, value.le
ngth() - 1), secondCoord)) | 83 if (!parseFloatPercentageValue(valueScanner, secondCoord)) |
| 84 return false; |
| 85 |
| 86 if (!valueScanner.isAtEnd()) |
| 107 return false; | 87 return false; |
| 108 | 88 |
| 109 valuePair = FloatPoint(firstCoord, secondCoord); | 89 valuePair = FloatPoint(firstCoord, secondCoord); |
| 110 return true; | 90 return true; |
| 111 } | 91 } |
| 112 | 92 |
| 113 VTTParser::VTTParser(VTTParserClient* client, Document& document) | 93 VTTParser::VTTParser(VTTParserClient* client, Document& document) |
| 114 : m_document(&document) | 94 : m_document(&document) |
| 115 , m_state(Initial) | 95 , m_state(Initial) |
| 116 , m_decoder(TextResourceDecoder::create("text/plain", UTF8Encoding())) | 96 , m_decoder(TextResourceDecoder::create("text/plain", UTF8Encoding())) |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); | 563 m_currentNode->parserAppendChild(ProcessingInstruction::create(docum
ent, "timestamp", charactersString)); |
| 584 break; | 564 break; |
| 585 } | 565 } |
| 586 default: | 566 default: |
| 587 break; | 567 break; |
| 588 } | 568 } |
| 589 } | 569 } |
| 590 | 570 |
| 591 } | 571 } |
| 592 | 572 |
| OLD | NEW |