| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 collectMetadataHeader(line); | 172 collectMetadataHeader(line); |
| 173 | 173 |
| 174 if (line.isEmpty()) { | 174 if (line.isEmpty()) { |
| 175 if (m_client && m_regionList.size()) | 175 if (m_client && m_regionList.size()) |
| 176 m_client->newRegionsParsed(); | 176 m_client->newRegionsParsed(); |
| 177 | 177 |
| 178 m_state = Id; | 178 m_state = Id; |
| 179 break; | 179 break; |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Step 15 - Break out of header loop if the line could be a timesta
mp line. |
| 183 if (line.contains("-->")) |
| 184 m_state = recoverCue(line); |
| 185 |
| 182 // Step 16 - Line is not the empty string and does not contain "-->"
. | 186 // Step 16 - Line is not the empty string and does not contain "-->"
. |
| 183 break; | 187 break; |
| 184 | 188 |
| 185 case Id: | 189 case Id: |
| 186 // Steps 17 - 20 - Allow any number of line terminators, then initia
lize new cue values. | 190 // Steps 17 - 20 - Allow any number of line terminators, then initia
lize new cue values. |
| 187 if (line.isEmpty()) | 191 if (line.isEmpty()) |
| 188 break; | 192 break; |
| 189 | 193 |
| 190 // Step 21 - Cue creation (start a new cue). | 194 // Step 21 - Cue creation (start a new cue). |
| 191 resetCueValues(); | 195 resetCueValues(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return BadCue; | 304 return BadCue; |
| 301 skipWhiteSpace(line, &position); | 305 skipWhiteSpace(line, &position); |
| 302 | 306 |
| 303 // Step 12 - Parse the WebVTT settings for the cue (conducted in TextTrackCu
e). | 307 // Step 12 - Parse the WebVTT settings for the cue (conducted in TextTrackCu
e). |
| 304 m_currentSettings = line.substring(position, line.length()-1); | 308 m_currentSettings = line.substring(position, line.length()-1); |
| 305 return CueText; | 309 return CueText; |
| 306 } | 310 } |
| 307 | 311 |
| 308 WebVTTParser::ParseState WebVTTParser::collectCueText(const String& line) | 312 WebVTTParser::ParseState WebVTTParser::collectCueText(const String& line) |
| 309 { | 313 { |
| 314 // Step 34. |
| 310 if (line.isEmpty()) { | 315 if (line.isEmpty()) { |
| 311 createNewCue(); | 316 createNewCue(); |
| 312 return Id; | 317 return Id; |
| 313 } | 318 } |
| 319 // Step 35. |
| 320 if (line.contains("-->")) { |
| 321 // Step 39-40. |
| 322 createNewCue(); |
| 323 |
| 324 // Step 41 - New iteration of the cue loop. |
| 325 return recoverCue(line); |
| 326 } |
| 314 if (!m_currentContent.isEmpty()) | 327 if (!m_currentContent.isEmpty()) |
| 315 m_currentContent.append("\n"); | 328 m_currentContent.append("\n"); |
| 316 m_currentContent.append(line); | 329 m_currentContent.append(line); |
| 317 | 330 |
| 318 return CueText; | 331 return CueText; |
| 319 } | 332 } |
| 320 | 333 |
| 334 WebVTTParser::ParseState WebVTTParser::recoverCue(const String& line) |
| 335 { |
| 336 // Step 17 and 21. |
| 337 resetCueValues(); |
| 338 |
| 339 // Step 22. |
| 340 return collectTimingsAndSettings(line); |
| 341 } |
| 342 |
| 321 WebVTTParser::ParseState WebVTTParser::ignoreBadCue(const String& line) | 343 WebVTTParser::ParseState WebVTTParser::ignoreBadCue(const String& line) |
| 322 { | 344 { |
| 323 if (!line.isEmpty()) | 345 if (line.isEmpty()) |
| 324 return BadCue; | 346 return Id; |
| 325 return Id; | 347 if (line.contains("-->")) |
| 348 return recoverCue(line); |
| 349 return BadCue; |
| 326 } | 350 } |
| 327 | 351 |
| 328 // A helper class for the construction of a "cue fragment" from the cue text. | 352 // A helper class for the construction of a "cue fragment" from the cue text. |
| 329 class WebVTTTreeBuilder { | 353 class WebVTTTreeBuilder { |
| 330 public: | 354 public: |
| 331 WebVTTTreeBuilder(Document& document) | 355 WebVTTTreeBuilder(Document& document) |
| 332 : m_document(document) { } | 356 : m_document(document) { } |
| 333 | 357 |
| 334 PassRefPtr<DocumentFragment> buildFromString(const String& cueText); | 358 PassRefPtr<DocumentFragment> buildFromString(const String& cueText); |
| 335 | 359 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 589 } |
| 566 | 590 |
| 567 void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position) | 591 void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position) |
| 568 { | 592 { |
| 569 while (*position < line.length() && isASpace(line[*position])) | 593 while (*position < line.length() && isASpace(line[*position])) |
| 570 (*position)++; | 594 (*position)++; |
| 571 } | 595 } |
| 572 | 596 |
| 573 } | 597 } |
| 574 | 598 |
| OLD | NEW |