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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 StringBuilder classes; | 99 StringBuilder classes; |
100 enum { | 100 enum { |
101 DataState, | 101 DataState, |
102 EscapeState, | 102 EscapeState, |
103 TagState, | 103 TagState, |
104 StartTagState, | 104 StartTagState, |
105 StartTagClassState, | 105 StartTagClassState, |
106 StartTagAnnotationState, | 106 StartTagAnnotationState, |
107 EndTagState, | 107 EndTagState, |
108 TimestampTagState, | 108 TimestampTagState, |
| 109 EscapeCharacterState, |
109 } state = DataState; | 110 } state = DataState; |
110 | 111 |
111 // 4.8.10.13.4 WebVTT cue text tokenizer | 112 // 4.8.10.13.4 WebVTT cue text tokenizer |
112 switch (state) { | 113 switch (state) { |
113 WEBVTT_BEGIN_STATE(DataState) { | 114 WEBVTT_BEGIN_STATE(DataState) { |
114 if (cc == '&') { | 115 if (cc == '&') { |
115 buffer.append(static_cast<LChar>(cc)); | 116 buffer.append(static_cast<LChar>(cc)); |
116 WEBVTT_ADVANCE_TO(EscapeState); | 117 WEBVTT_ADVANCE_TO(EscapeState); |
117 } else if (cc == '<') { | 118 } else if (cc == '<') { |
118 if (result.isEmpty()) { | 119 if (result.isEmpty()) { |
(...skipping 25 matching lines...) Expand all Loading... |
144 } else if (equalLiteral(buffer, "&rlm")) { | 145 } else if (equalLiteral(buffer, "&rlm")) { |
145 result.append(rightToLeftMark); | 146 result.append(rightToLeftMark); |
146 } else if (equalLiteral(buffer, " ")) { | 147 } else if (equalLiteral(buffer, " ")) { |
147 result.append(noBreakSpace); | 148 result.append(noBreakSpace); |
148 } else { | 149 } else { |
149 buffer.append(static_cast<LChar>(cc)); | 150 buffer.append(static_cast<LChar>(cc)); |
150 result.append(buffer); | 151 result.append(buffer); |
151 } | 152 } |
152 buffer.clear(); | 153 buffer.clear(); |
153 WEBVTT_ADVANCE_TO(DataState); | 154 WEBVTT_ADVANCE_TO(DataState); |
| 155 } else if (cc == '#') { |
| 156 buffer.clear(); |
| 157 WEBVTT_ADVANCE_TO(EscapeCharacterState); |
154 } else if (isASCIIAlphanumeric(cc)) { | 158 } else if (isASCIIAlphanumeric(cc)) { |
155 buffer.append(static_cast<LChar>(cc)); | 159 buffer.append(static_cast<LChar>(cc)); |
156 WEBVTT_ADVANCE_TO(EscapeState); | 160 WEBVTT_ADVANCE_TO(EscapeState); |
157 } else if (cc == '<') { | 161 } else if (cc == '<') { |
158 result.append(buffer); | 162 result.append(buffer); |
159 return emitToken(token, VTTToken::StringToken(result.toString())
); | 163 return emitToken(token, VTTToken::StringToken(result.toString())
); |
160 } else if (cc == kEndOfFileMarker) { | 164 } else if (cc == kEndOfFileMarker) { |
161 result.append(buffer); | 165 result.append(buffer); |
162 return advanceAndEmitToken(m_input, token, VTTToken::StringToken
(result.toString())); | 166 return advanceAndEmitToken(m_input, token, VTTToken::StringToken
(result.toString())); |
163 } else { | 167 } else { |
164 result.append(buffer); | 168 result.append(buffer); |
165 buffer.clear(); | 169 buffer.clear(); |
166 | 170 |
167 if (cc == '&') { | 171 if (cc == '&') { |
168 buffer.append(static_cast<LChar>(cc)); | 172 buffer.append(static_cast<LChar>(cc)); |
169 WEBVTT_ADVANCE_TO(EscapeState); | 173 WEBVTT_ADVANCE_TO(EscapeState); |
170 } | 174 } |
171 result.append(cc); | 175 result.append(cc); |
172 WEBVTT_ADVANCE_TO(DataState); | 176 WEBVTT_ADVANCE_TO(DataState); |
173 } | 177 } |
174 } | 178 } |
175 END_STATE() | 179 END_STATE() |
176 | 180 |
| 181 WEBVTT_BEGIN_STATE(EscapeCharacterState) { |
| 182 if (cc == ';') { |
| 183 unsigned charCode = buffer.toString().toUIntStrict(); |
| 184 result.append(static_cast<UChar>(charCode)); |
| 185 buffer.clear(); |
| 186 WEBVTT_ADVANCE_TO(DataState); |
| 187 } else if (WTF::isASCIIDigit(cc)) { |
| 188 buffer.append(static_cast<LChar>(cc)); |
| 189 WEBVTT_ADVANCE_TO(EscapeCharacterState); |
| 190 } else { |
| 191 buffer.clear(); |
| 192 WEBVTT_ADVANCE_TO(DataState); |
| 193 } |
| 194 } |
| 195 END_STATE() |
| 196 |
177 WEBVTT_BEGIN_STATE(TagState) { | 197 WEBVTT_BEGIN_STATE(TagState) { |
178 if (isTokenizerWhitespace(cc)) { | 198 if (isTokenizerWhitespace(cc)) { |
179 ASSERT(result.isEmpty()); | 199 ASSERT(result.isEmpty()); |
180 WEBVTT_ADVANCE_TO(StartTagAnnotationState); | 200 WEBVTT_ADVANCE_TO(StartTagAnnotationState); |
181 } else if (cc == '.') { | 201 } else if (cc == '.') { |
182 ASSERT(result.isEmpty()); | 202 ASSERT(result.isEmpty()); |
183 WEBVTT_ADVANCE_TO(StartTagClassState); | 203 WEBVTT_ADVANCE_TO(StartTagClassState); |
184 } else if (cc == '/') { | 204 } else if (cc == '/') { |
185 WEBVTT_ADVANCE_TO(EndTagState); | 205 WEBVTT_ADVANCE_TO(EndTagState); |
186 } else if (WTF::isASCIIDigit(cc)) { | 206 } else if (WTF::isASCIIDigit(cc)) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 END_STATE() | 276 END_STATE() |
257 | 277 |
258 } | 278 } |
259 | 279 |
260 ASSERT_NOT_REACHED(); | 280 ASSERT_NOT_REACHED(); |
261 return false; | 281 return false; |
262 } | 282 } |
263 | 283 |
264 } | 284 } |
265 | 285 |
OLD | NEW |