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

Side by Side Diff: Source/core/html/track/vtt/VTTToken.h

Issue 75243004: Replace character vectors with StringBuilders in the WebVTT tokenizer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase after symbolnames changed Created 7 years, 1 month 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/VTTParser.cpp ('k') | Source/core/html/track/vtt/VTTTokenizer.h » ('j') | 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef VTTToken_h 31 #ifndef VTTToken_h
32 #define VTTToken_h 32 #define VTTToken_h
33 33
34 #include "wtf/text/StringBuilder.h"
35
34 namespace WebCore { 36 namespace WebCore {
35 37
36 class VTTTokenTypes { 38 class VTTTokenTypes {
37 public: 39 public:
38 enum Type { 40 enum Type {
39 Uninitialized, 41 Uninitialized,
40 Character, 42 Character,
41 StartTag, 43 StartTag,
42 EndTag, 44 EndTag,
43 TimestampTag, 45 TimestampTag,
44 }; 46 };
45 }; 47 };
46 48
47 class VTTToken { 49 class VTTToken {
48 WTF_MAKE_NONCOPYABLE(VTTToken); 50 WTF_MAKE_NONCOPYABLE(VTTToken);
49 WTF_MAKE_FAST_ALLOCATED; 51 WTF_MAKE_FAST_ALLOCATED;
50 public: 52 public:
51 typedef VTTTokenTypes Type; 53 typedef VTTTokenTypes Type;
52 typedef WTF::Vector<UChar, 1024> DataVector; // FIXME: Is this too large for WebVTT?
53 54
54 VTTToken() { clear(); } 55 VTTToken() { clear(); }
55 56
56 void appendToName(UChar character) 57 void appendToName(UChar character)
57 { 58 {
58 ASSERT(m_type == VTTTokenTypes::StartTag || m_type == VTTTokenTypes::End Tag); 59 ASSERT(m_type == VTTTokenTypes::StartTag || m_type == VTTTokenTypes::End Tag);
59 ASSERT(character); 60 ASSERT(character);
60 m_data.append(character); 61 m_data.append(character);
61 } 62 }
62 63
63 Type::Type type() const { return m_type; } 64 Type::Type type() const { return m_type; }
64 65
65 const DataVector& name() const 66 StringBuilder& name()
66 { 67 {
67 return m_data; 68 return m_data;
68 } 69 }
69 70
70 const DataVector& characters() const 71 StringBuilder& characters()
71 { 72 {
72 ASSERT(m_type == Type::Character || m_type == Type::TimestampTag); 73 ASSERT(m_type == Type::Character || m_type == Type::TimestampTag);
73 return m_data; 74 return m_data;
74 } 75 }
75 76
76 // Starting a character token works slightly differently than starting 77 // Starting a character token works slightly differently than starting
77 // other types of tokens because we want to save a per-character branch. 78 // other types of tokens because we want to save a per-character branch.
78 void ensureIsCharacterToken() 79 void ensureIsCharacterToken()
79 { 80 {
80 ASSERT(m_type == Type::Uninitialized || m_type == Type::Character); 81 ASSERT(m_type == Type::Uninitialized || m_type == Type::Character);
81 m_type = Type::Character; 82 m_type = Type::Character;
82 } 83 }
83 84
84 void appendToCharacter(char character) 85 void appendToCharacter(char character)
85 { 86 {
86 ASSERT(m_type == Type::Character); 87 ASSERT(m_type == Type::Character);
87 m_data.append(character); 88 m_data.append(character);
88 } 89 }
89 90
90 void appendToCharacter(UChar character) 91 void appendToCharacter(UChar character)
91 { 92 {
92 ASSERT(m_type == Type::Character); 93 ASSERT(m_type == Type::Character);
93 m_data.append(character); 94 m_data.append(character);
94 } 95 }
95 96
96 void appendToCharacter(const Vector<LChar, 32>& characters) 97 void appendToCharacter(const StringBuilder& characters)
97 { 98 {
98 ASSERT(m_type == Type::Character); 99 ASSERT(m_type == Type::Character);
99 m_data.appendVector(characters); 100 m_data.append(characters);
100 } 101 }
101 102
102 void beginEmptyStartTag() 103 void beginEmptyStartTag()
103 { 104 {
104 ASSERT(m_type == Type::Uninitialized); 105 ASSERT(m_type == Type::Uninitialized);
105 m_type = Type::StartTag; 106 m_type = Type::StartTag;
106 m_data.clear(); 107 m_data.clear();
107 } 108 }
108 109
109 void beginStartTag(UChar character) 110 void beginStartTag(UChar character)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 144
144 void addNewClass() 145 void addNewClass()
145 { 146 {
146 ASSERT(m_type == Type::StartTag); 147 ASSERT(m_type == Type::StartTag);
147 if (!m_classes.isEmpty()) 148 if (!m_classes.isEmpty())
148 m_classes.append(' '); 149 m_classes.append(' ');
149 m_classes.append(m_currentBuffer); 150 m_classes.append(m_currentBuffer);
150 m_currentBuffer.clear(); 151 m_currentBuffer.clear();
151 } 152 }
152 153
153 const DataVector& classes() const 154 StringBuilder& classes()
154 { 155 {
155 return m_classes; 156 return m_classes;
156 } 157 }
157 158
158 void appendToAnnotation(UChar character) 159 void appendToAnnotation(UChar character)
159 { 160 {
160 appendToStartType(character); 161 appendToStartType(character);
161 } 162 }
162 163
163 void addNewAnnotation() 164 void addNewAnnotation()
164 { 165 {
165 ASSERT(m_type == Type::StartTag); 166 ASSERT(m_type == Type::StartTag);
166 m_annotation.clear(); 167 m_annotation.clear();
167 m_annotation.append(m_currentBuffer); 168 m_annotation.append(m_currentBuffer);
168 m_currentBuffer.clear(); 169 m_currentBuffer.clear();
169 } 170 }
170 171
171 const DataVector& annotation() const 172 StringBuilder& annotation()
172 { 173 {
173 return m_annotation; 174 return m_annotation;
174 } 175 }
175 176
176 void clear() 177 void clear()
177 { 178 {
178 m_type = Type::Uninitialized; 179 m_type = Type::Uninitialized;
179 m_data.clear(); 180 m_data.clear();
180 m_annotation.clear(); 181 m_annotation.clear();
181 m_classes.clear(); 182 m_classes.clear();
182 m_currentBuffer.clear(); 183 m_currentBuffer.clear();
183 } 184 }
184 185
185 private: 186 private:
186 void appendToStartType(UChar character) 187 void appendToStartType(UChar character)
187 { 188 {
188 ASSERT(character); 189 ASSERT(character);
189 ASSERT(m_type == Type::StartTag); 190 ASSERT(m_type == Type::StartTag);
190 m_currentBuffer.append(character); 191 m_currentBuffer.append(character);
191 } 192 }
192 193
193 Type::Type m_type; 194 Type::Type m_type;
194 DataVector m_data; 195 StringBuilder m_data;
195 DataVector m_annotation; 196 StringBuilder m_annotation;
196 DataVector m_classes; 197 StringBuilder m_classes;
197 DataVector m_currentBuffer; 198 StringBuilder m_currentBuffer;
198 }; 199 };
199 200
200 } 201 }
201 202
202 #endif 203 #endif
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTParser.cpp ('k') | Source/core/html/track/vtt/VTTTokenizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698