151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/* 251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Copyright (C) 2011 Google Inc. All rights reserved. 351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * modification, are permitted provided that the following conditions are 651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * met: 751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 1151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 1251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * in the documentation and/or other materials provided with the 1351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * distribution. 1451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 1551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 1651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * this software without specific prior written permission. 1751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 1851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) */ 3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "config.h" 3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/html/track/vtt/VTTTokenizer.h" 3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/xml/parser/MarkupTokenizerInlines.h" 3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "wtf/text/StringBuilder.h" 3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "wtf/unicode/CharacterNames.h" 3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 39c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 41a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WEBVTT_BEGIN_STATE(stateName) case stateName: stateName: 42a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WEBVTT_ADVANCE_TO(stateName) \ 43a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) do { \ 44a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) state = stateName; \ 45a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ASSERT(!m_input.isEmpty()); \ 46a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) m_inputStreamPreprocessor.advance(m_input); \ 47a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) cc = m_inputStreamPreprocessor.nextInputCharacter(); \ 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) goto stateName; \ 49a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } while (false) 5051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)template<unsigned charactersCount> 5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)ALWAYS_INLINE bool equalLiteral(const StringBuilder& s, const char (&characters)[charactersCount]) 5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 5451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return WTF::equal(s, reinterpret_cast<const LChar*>(characters), charactersCount - 1); 5551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)static void addNewClass(StringBuilder& classes, const StringBuilder& newClass) 5851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (!classes.isEmpty()) 6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) classes.append(' '); 6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) classes.append(newClass); 6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 6351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 64a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)inline bool emitToken(VTTToken& resultToken, const VTTToken& token) 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) resultToken = token; 67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return true; 68a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 69a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)inline bool advanceAndEmitToken(SegmentedString& source, VTTToken& resultToken, const VTTToken& token) 71a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles){ 72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) source.advanceAndUpdateLineNumber(); 73a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return emitToken(resultToken, token); 74a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} 75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)VTTTokenizer::VTTTokenizer(const String& input) 7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) : m_input(input) 7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) , m_inputStreamPreprocessor(this) 7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Append a EOF marker and close the input "stream". 8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT(!m_input.isClosed()); 8251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); 8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) m_input.close(); 8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 8651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)bool VTTTokenizer::nextToken(VTTToken& token) 8751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 8851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (m_input.isEmpty() || !m_inputStreamPreprocessor.peek(m_input)) 89a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return false; 9051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 9151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) UChar cc = m_inputStreamPreprocessor.nextInputCharacter(); 9251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == kEndOfFileMarker) { 9351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) m_inputStreamPreprocessor.advance(m_input); 9451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return false; 9551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 9651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 9751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) StringBuilder buffer; 9851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) StringBuilder result; 9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) StringBuilder classes; 100a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) enum { 101a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) DataState, 102a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) EscapeState, 103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) TagState, 104a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) StartTagState, 105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) StartTagClassState, 106a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) StartTagAnnotationState, 107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) EndTagState, 108a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) TimestampTagState, 109a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } state = DataState; 11051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 11151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // 4.8.10.13.4 WebVTT cue text tokenizer 112a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) switch (state) { 11351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(DataState) { 11451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == '&') { 11551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.append(static_cast<LChar>(cc)); 11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(EscapeState); 11751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '<') { 11851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (result.isEmpty()) { 11951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(TagState); 12051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 12151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // We don't want to advance input or perform a state transition - just return a (new) token. 12251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // (On the next call to nextToken we will see '<' again, but take the other branch in this if instead.) 123a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return emitToken(token, VTTToken::StringToken(result.toString())); 12451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 12551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == kEndOfFileMarker) { 126a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StringToken(result.toString())); 12751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 12851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 12951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(DataState); 13051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 13151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 13251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 13451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(EscapeState) { 13551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == ';') { 13651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (equalLiteral(buffer, "&")) { 13751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append('&'); 13851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (equalLiteral(buffer, "<")) { 13951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append('<'); 14051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (equalLiteral(buffer, ">")) { 14151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append('>'); 14251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (equalLiteral(buffer, "&lrm")) { 14351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(leftToRightMark); 14451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (equalLiteral(buffer, "&rlm")) { 14551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(rightToLeftMark); 14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (equalLiteral(buffer, " ")) { 14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(noBreakSpace); 14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.append(static_cast<LChar>(cc)); 15051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(buffer); 15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.clear(); 15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(DataState); 15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (isASCIIAlphanumeric(cc)) { 15551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.append(static_cast<LChar>(cc)); 15651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(EscapeState); 157a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } else if (cc == '<') { 158a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) result.append(buffer); 159a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return emitToken(token, VTTToken::StringToken(result.toString())); 16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == kEndOfFileMarker) { 16151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(buffer); 162a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StringToken(result.toString())); 16351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 164a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) result.append(buffer); 16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.clear(); 166a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 167a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (cc == '&') { 168a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) buffer.append(static_cast<LChar>(cc)); 169a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WEBVTT_ADVANCE_TO(EscapeState); 170a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) } 171a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) result.append(cc); 17251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(DataState); 17351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 17451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 17551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 17651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 17751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(TagState) { 17851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (isTokenizerWhitespace(cc)) { 17951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT(result.isEmpty()); 18051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagAnnotationState); 18151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '.') { 18251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT(result.isEmpty()); 18351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagClassState); 18451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '/') { 18551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(EndTagState); 18651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (WTF::isASCIIDigit(cc)) { 18751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 18851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(TimestampTagState); 18951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '>' || cc == kEndOfFileMarker) { 19051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT(result.isEmpty()); 191a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StartTag(result.toString())); 19251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 19351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 19451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagState); 19551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 19651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 19751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 19851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 19951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(StartTagState) { 20051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (isTokenizerWhitespace(cc)) { 20151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagAnnotationState); 20251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '.') { 20351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagClassState); 20451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '>' || cc == kEndOfFileMarker) { 205a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StartTag(result.toString())); 20651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 20751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 20851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagState); 20951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 21051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 21151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 21251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 21351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(StartTagClassState) { 21451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (isTokenizerWhitespace(cc)) { 21551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) addNewClass(classes, buffer); 21651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.clear(); 21751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagAnnotationState); 21851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '.') { 21951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) addNewClass(classes, buffer); 22051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.clear(); 22151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagClassState); 22251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else if (cc == '>' || cc == kEndOfFileMarker) { 22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) addNewClass(classes, buffer); 22451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.clear(); 225a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StartTag(result.toString(), classes.toAtomicString())); 22651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } else { 22751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.append(cc); 22851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagClassState); 22951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 23051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 23151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 23251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 23351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(StartTagAnnotationState) { 23451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == '>' || cc == kEndOfFileMarker) { 235a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::StartTag(result.toString(), classes.toAtomicString(), buffer.toAtomicString())); 23651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 23751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) buffer.append(cc); 23851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(StartTagAnnotationState); 23951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 24051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 24151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(EndTagState) { 24351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == '>' || cc == kEndOfFileMarker) 244a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::EndTag(result.toString())); 24551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 24651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(EndTagState); 24751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 24851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 24951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 25051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_BEGIN_STATE(TimestampTagState) { 25151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (cc == '>' || cc == kEndOfFileMarker) 252a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) return advanceAndEmitToken(m_input, token, VTTToken::TimestampTag(result.toString())); 25351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) result.append(cc); 25451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) WEBVTT_ADVANCE_TO(TimestampTagState); 25551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 25651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) END_STATE() 25751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 25851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 25951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 26051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT_NOT_REACHED(); 26151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return false; 26251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 26351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 26451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 26551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 266