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

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

Issue 119143002: Introduce VTTScanner - a parser helper for various VTT parsing needs (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: struct Run -> class Run; explicit constructor; make non-copyable. Created 6 years, 11 months 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 | « Source/core/html/track/vtt/VTTScanner.h ('k') | Source/core/html/track/vtt/VTTScannerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Opera Software ASA nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "config.h"
31 #include "core/html/track/vtt/VTTScanner.h"
32
33 namespace WebCore {
34
35 VTTScanner::VTTScanner(const String& line) : m_is8Bit(line.is8Bit())
36 {
37 if (m_is8Bit) {
38 m_data.characters8 = line.characters8();
39 m_end.characters8 = m_data.characters8 + line.length();
40 } else {
41 m_data.characters16 = line.characters16();
42 m_end.characters16 = m_data.characters16 + line.length();
43 }
44 }
45
46 bool VTTScanner::scan(char c)
47 {
48 if (!match(c))
49 return false;
50 advance();
51 return true;
52 }
53
54 bool VTTScanner::scan(const LChar* characters, size_t charactersCount)
55 {
56 unsigned matchLength = m_is8Bit ? m_end.characters8 - m_data.characters8 : m _end.characters16 - m_data.characters16;
57 if (matchLength < charactersCount)
58 return false;
59 bool matched;
60 if (m_is8Bit)
61 matched = WTF::equal(m_data.characters8, characters, charactersCount);
62 else
63 matched = WTF::equal(m_data.characters16, characters, charactersCount);
64 if (matched)
65 advance(charactersCount);
66 return matched;
67 }
68
69 String VTTScanner::restOfInputAsString()
70 {
71 ASSERT(position() <= end());
72 String s;
73 if (m_is8Bit)
74 s = String(m_data.characters8, m_end.characters8 - m_data.characters8);
75 else
76 s = String(m_data.characters16, m_end.characters16 - m_data.characters16 );
77 seekTo(end());
78 return s;
79 }
80
81 unsigned VTTScanner::scanDigits(int& number)
82 {
83 Run runOfDigits = collectWhile<isASCIIDigit>();
84 if (runOfDigits.isEmpty()) {
85 number = 0;
86 return 0;
87 }
88 bool validNumber;
89 size_t numDigits = runOfDigits.length();
90 if (m_is8Bit)
91 number = charactersToInt(m_data.characters8, numDigits, &validNumber);
92 else
93 number = charactersToInt(m_data.characters16, numDigits, &validNumber);
94
95 // Since we know that scanDigits only scanned valid (ASCII) digits (and
96 // hence that's what got passed to charactersToInt()), the remaining
97 // failure mode for charactersToInt() is overflow, so if |validNumber| is
98 // not true, then set |number| to the maximum int value.
99 if (!validNumber)
100 number = std::numeric_limits<int>::max();
101 // Consume the digits.
102 seekTo(runOfDigits.end());
103 return numDigits;
104 }
105
106 }
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTScanner.h ('k') | Source/core/html/track/vtt/VTTScannerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698