Index: Source/core/html/track/vtt/VTTCue.cpp |
diff --git a/Source/core/html/track/vtt/VTTCue.cpp b/Source/core/html/track/vtt/VTTCue.cpp |
index 15412ea2158dd1488c59fc33abfd47ec8a6bd8ec..ce50c7d243b89a647d8d8894d66e51760b8980b7 100644 |
--- a/Source/core/html/track/vtt/VTTCue.cpp |
+++ b/Source/core/html/track/vtt/VTTCue.cpp |
@@ -44,6 +44,7 @@ |
#include "core/html/track/vtt/VTTElement.h" |
#include "core/html/track/vtt/VTTParser.h" |
#include "core/html/track/vtt/VTTRegionList.h" |
+#include "core/html/track/vtt/VTTScanner.h" |
#include "core/rendering/RenderVTTCue.h" |
#include "platform/text/BidiResolver.h" |
#include "platform/text/TextRunIterator.h" |
@@ -833,44 +834,37 @@ std::pair<double, double> VTTCue::getPositionCoordinates() const |
return coordinates; |
} |
-VTTCue::CueSetting VTTCue::settingName(const String& name) |
+VTTCue::CueSetting VTTCue::settingName(VTTScanner& input) |
{ |
- DEFINE_STATIC_LOCAL(const String, verticalKeyword, ("vertical")); |
- DEFINE_STATIC_LOCAL(const String, lineKeyword, ("line")); |
- DEFINE_STATIC_LOCAL(const String, positionKeyword, ("position")); |
- DEFINE_STATIC_LOCAL(const String, sizeKeyword, ("size")); |
- DEFINE_STATIC_LOCAL(const String, alignKeyword, ("align")); |
- DEFINE_STATIC_LOCAL(const String, regionIdKeyword, ("region")); |
- |
- if (name == verticalKeyword) |
- return Vertical; |
- if (name == lineKeyword) |
- return Line; |
- if (name == positionKeyword) |
- return Position; |
- if (name == sizeKeyword) |
- return Size; |
- if (name == alignKeyword) |
- return Align; |
- if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && name == regionIdKeyword) |
- return RegionId; |
- |
+ CueSetting parsedSetting = None; |
+ if (input.scan("vertical")) |
+ parsedSetting = Vertical; |
+ else if (input.scan("line")) |
+ parsedSetting = Line; |
+ else if (input.scan("position")) |
+ parsedSetting = Position; |
+ else if (input.scan("size")) |
+ parsedSetting = Size; |
+ else if (input.scan("align")) |
+ parsedSetting = Align; |
+ else if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && input.scan("region")) |
+ parsedSetting = RegionId; |
+ // Verify that a ':' follows. |
+ if (parsedSetting != None && input.scan(':')) |
+ return parsedSetting; |
return None; |
} |
// Used for 'position' and 'size'. |
-static bool scanPercentage(const String& input, unsigned* position, int& number) |
+static bool scanPercentage(VTTScanner& input, const VTTScanner::Run& valueRun, int& number) |
{ |
- ASSERT(position); |
// 1. If value contains any characters other than U+0025 PERCENT SIGN |
// characters (%) and characters in the range U+0030 DIGIT ZERO (0) to |
// U+0039 DIGIT NINE (9), then jump to the step labeled next setting. |
// 2. If value does not contain at least one character in the range U+0030 |
// DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jump to the step |
// labeled next setting. |
- if (!VTTParser::collectDigitsToInt(input, position, number)) |
- return false; |
- if (*position >= input.length()) |
+ if (!input.scanDigits(number)) |
return false; |
// 3. If any character in value other than the last character is a U+0025 |
@@ -878,9 +872,7 @@ static bool scanPercentage(const String& input, unsigned* position, int& number) |
// setting. |
// 4. If the last character in value is not a U+0025 PERCENT SIGN character |
// (%), then jump to the step labeled next setting. |
- if (input[(*position)++] != '%') |
- return false; |
- if (*position < input.length() && !VTTParser::isValidSettingDelimiter(input[*position])) |
+ if (!input.scan('%') || !input.isAt(valueRun.end())) |
return false; |
// 5. Ignoring the trailing percent sign, interpret value as an integer, |
@@ -890,17 +882,17 @@ static bool scanPercentage(const String& input, unsigned* position, int& number) |
return number >= 0 && number <= 100; |
} |
-void VTTCue::parseSettings(const String& input) |
+void VTTCue::parseSettings(const String& inputString) |
{ |
- unsigned position = 0; |
+ VTTScanner input(inputString); |
- while (position < input.length()) { |
+ while (!input.isAtEnd()) { |
// The WebVTT cue settings part of a WebVTT cue consists of zero or more of the following components, in any order, |
// separated from each other by one or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters. |
- while (position < input.length() && VTTParser::isValidSettingDelimiter(input[position])) |
- position++; |
- if (position >= input.length()) |
+ input.skipWhile<VTTParser::isValidSettingDelimiter>(); |
+ |
+ if (input.isAtEnd()) |
break; |
// When the user agent is to parse the WebVTT settings given by a string input for a text track cue cue, |
@@ -909,20 +901,11 @@ void VTTCue::parseSettings(const String& input) |
// 2. For each token setting in the list settings, run the following substeps: |
// 1. If setting does not contain a U+003A COLON character (:), or if the first U+003A COLON character (:) |
// in setting is either the first or last character of setting, then jump to the step labeled next setting. |
- unsigned endOfSetting = position; |
- String setting = VTTParser::collectWord(input, &endOfSetting); |
- CueSetting name; |
- size_t colonOffset = setting.find(':', 1); |
- if (colonOffset == kNotFound || !colonOffset || colonOffset == setting.length() - 1) |
- goto NextSetting; |
- |
- // 2. Let name be the leading substring of setting up to and excluding the first U+003A COLON character (:) in that string. |
- name = settingName(setting.substring(0, colonOffset)); |
+ // 2. Let name be the leading substring of setting up to and excluding the first U+003A COLON character (:) in that string. |
+ CueSetting name = settingName(input); |
// 3. Let value be the trailing substring of setting starting from the character immediately after the first U+003A COLON character (:) in that string. |
- position += colonOffset + 1; |
- if (position >= input.length()) |
- break; |
+ VTTScanner::Run valueRun = input.collectUntil<VTTParser::isValidSettingDelimiter>(); |
// 4. Run the appropriate substeps that apply for the value of name, as follows: |
switch (name) { |
@@ -930,13 +913,12 @@ void VTTCue::parseSettings(const String& input) |
// If name is a case-sensitive match for "vertical" |
// 1. If value is a case-sensitive match for the string "rl", then let cue's text track cue writing direction |
// be vertical growing left. |
- String writingDirection = VTTParser::collectWord(input, &position); |
- if (writingDirection == verticalGrowingLeftKeyword()) |
+ if (input.scanRun(valueRun, verticalGrowingLeftKeyword())) |
m_writingDirection = VerticalGrowingLeft; |
// 2. Otherwise, if value is a case-sensitive match for the string "lr", then let cue's text track cue writing |
// direction be vertical growing right. |
- else if (writingDirection == verticalGrowingRightKeyword()) |
+ else if (input.scanRun(valueRun, verticalGrowingRightKeyword())) |
m_writingDirection = VerticalGrowingRight; |
break; |
} |
@@ -945,10 +927,12 @@ void VTTCue::parseSettings(const String& input) |
// 1. If value contains any characters other than U+002D HYPHEN-MINUS characters (-), U+0025 PERCENT SIGN |
// characters (%), and characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jump |
// to the step labeled next setting. |
- StringBuilder linePositionBuilder; |
- while (position < input.length() && (input[position] == '-' || input[position] == '%' || isASCIIDigit(input[position]))) |
- linePositionBuilder.append(input[position++]); |
- if (position < input.length() && !VTTParser::isValidSettingDelimiter(input[position])) |
+ bool isNegative = input.scan('-'); |
+ int linePosition; |
+ unsigned numDigits = input.scanDigits(linePosition); |
+ bool isPercentage = input.scan('%'); |
+ |
+ if (!input.isAt(valueRun.end())) |
break; |
// 2. If value does not contain at least one character in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT |
@@ -957,43 +941,36 @@ void VTTCue::parseSettings(const String& input) |
// jump to the step labeled next setting. |
// 4. If any character in value other than the last character is a U+0025 PERCENT SIGN character (%), then |
// jump to the step labeled next setting. |
- String linePosition = linePositionBuilder.toString(); |
- if (linePosition.find('-', 1) != kNotFound || linePosition.reverseFind("%", linePosition.length() - 2) != kNotFound) |
- break; |
// 5. If the first character in value is a U+002D HYPHEN-MINUS character (-) and the last character in value is a |
// U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting. |
- if (linePosition[0] == '-' && linePosition[linePosition.length() - 1] == '%') |
+ if (!numDigits || (isPercentage && isNegative)) |
break; |
// 6. Ignoring the trailing percent sign, if any, interpret value as a (potentially signed) integer, and |
// let number be that number. |
- // NOTE: toInt ignores trailing non-digit characters, such as '%'. |
- bool validNumber; |
- int number = linePosition.toInt(&validNumber); |
- if (!validNumber) |
- break; |
- |
// 7. If the last character in value is a U+0025 PERCENT SIGN character (%), but number is not in the range |
// 0 ≤ number ≤ 100, then jump to the step labeled next setting. |
// 8. Let cue's text track cue line position be number. |
// 9. If the last character in value is a U+0025 PERCENT SIGN character (%), then let cue's text track cue |
// snap-to-lines flag be false. Otherwise, let it be true. |
- if (linePosition[linePosition.length() - 1] == '%') { |
- if (number < 0 || number > 100) |
+ if (isPercentage) { |
+ if (linePosition < 0 || linePosition > 100) |
break; |
- |
// 10 - If '%' then set snap-to-lines flag to false. |
m_snapToLines = false; |
+ } else { |
+ if (isNegative) |
+ linePosition = -linePosition; |
Mike West
2014/01/13 07:24:20
Where does this come into play? I don't see it in
fs
2014/01/13 08:12:01
In the old code this was handled by toInt (line 97
|
+ m_snapToLines = true; |
} |
- |
- m_linePosition = number; |
+ m_linePosition = linePosition; |
break; |
} |
case Position: { |
int number; |
// Steps 1 - 6. |
- if (!scanPercentage(input, &position, number)) |
+ if (!scanPercentage(input, valueRun, number)) |
break; |
// 7. Let cue's text track cue text position be number. |
@@ -1003,7 +980,7 @@ void VTTCue::parseSettings(const String& input) |
case Size: { |
int number; |
// Steps 1 - 6. |
- if (!scanPercentage(input, &position, number)) |
+ if (!scanPercentage(input, valueRun, number)) |
break; |
// 7. Let cue's text track cue size be number. |
@@ -1011,38 +988,36 @@ void VTTCue::parseSettings(const String& input) |
break; |
} |
case Align: { |
- String cueAlignment = VTTParser::collectWord(input, &position); |
- |
// 1. If value is a case-sensitive match for the string "start", then let cue's text track cue alignment be start alignment. |
- if (cueAlignment == startKeyword()) |
+ if (input.scanRun(valueRun, startKeyword())) |
m_cueAlignment = Start; |
// 2. If value is a case-sensitive match for the string "middle", then let cue's text track cue alignment be middle alignment. |
- else if (cueAlignment == middleKeyword()) |
+ else if (input.scanRun(valueRun, middleKeyword())) |
m_cueAlignment = Middle; |
// 3. If value is a case-sensitive match for the string "end", then let cue's text track cue alignment be end alignment. |
- else if (cueAlignment == endKeyword()) |
+ else if (input.scanRun(valueRun, endKeyword())) |
m_cueAlignment = End; |
// 4. If value is a case-sensitive match for the string "left", then let cue's text track cue alignment be left alignment. |
- else if (cueAlignment == leftKeyword()) |
+ else if (input.scanRun(valueRun, leftKeyword())) |
m_cueAlignment = Left; |
// 5. If value is a case-sensitive match for the string "right", then let cue's text track cue alignment be right alignment. |
- else if (cueAlignment == rightKeyword()) |
+ else if (input.scanRun(valueRun, rightKeyword())) |
m_cueAlignment = Right; |
break; |
} |
case RegionId: |
- m_regionId = VTTParser::collectWord(input, &position); |
+ m_regionId = input.extractString(valueRun); |
break; |
case None: |
break; |
} |
-NextSetting: |
- position = endOfSetting; |
+ // Make sure the entire run is consumed. |
+ input.skipRun(valueRun); |
} |
// If cue's line position is not auto or cue's size is not 100 or cue's |