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

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

Issue 77553004: Defer setting type in the WebVTT tokenizer until emitting the token (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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
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 30 matching lines...) Expand all
41 class VTTTokenizerState { 41 class VTTTokenizerState {
42 public: 42 public:
43 enum State { 43 enum State {
44 DataState, 44 DataState,
45 EscapeState, 45 EscapeState,
46 TagState, 46 TagState,
47 StartTagState, 47 StartTagState,
48 StartTagClassState, 48 StartTagClassState,
49 StartTagAnnotationState, 49 StartTagAnnotationState,
50 EndTagState, 50 EndTagState,
51 EndTagOpenState,
52 TimestampTagState, 51 TimestampTagState,
53 }; 52 };
54 }; 53 };
55 54
56 class VTTTokenizer { 55 class VTTTokenizer {
57 WTF_MAKE_NONCOPYABLE(VTTTokenizer); 56 WTF_MAKE_NONCOPYABLE(VTTTokenizer);
58 WTF_MAKE_FAST_ALLOCATED;
59 public: 57 public:
60 static PassOwnPtr<VTTTokenizer> create() { return adoptPtr(new VTTTokenizer) ; } 58 explicit VTTTokenizer(const String& input);
61 59
62 typedef VTTTokenizerState State; 60 typedef VTTTokenizerState State;
63 61
64 void reset(); 62 void reset();
65 63
66 bool nextToken(SegmentedString&, VTTToken&); 64 bool nextToken(VTTToken&);
67 65
68 inline bool haveBufferedCharacterToken() 66 inline bool haveBufferedCharacterToken() { return false; }
jochen (gone - plz use gerrit) 2013/11/20 14:09:37 why not just remove this method?
69 {
70 return m_token->type() == VTTToken::Type::Character;
71 }
72 67
73 inline void bufferCharacter(UChar character) 68 inline void bufferCharacter(UChar character)
74 { 69 {
75 ASSERT(character != kEndOfFileMarker); 70 ASSERT(character != kEndOfFileMarker);
76 m_token->ensureIsCharacterToken();
77 m_token->appendToCharacter(character); 71 m_token->appendToCharacter(character);
78 } 72 }
79 73
80 inline bool advanceAndEmitToken(SegmentedString& source, VTTTokenTypes::Type type) 74 inline bool advanceAndEmitToken(SegmentedString& source, VTTTokenTypes::Type type)
81 { 75 {
82 source.advanceAndUpdateLineNumber(); 76 source.advanceAndUpdateLineNumber();
83 return emitToken(type); 77 return emitToken(type);
84 } 78 }
85 79
86 inline bool emitToken(VTTTokenTypes::Type type) 80 inline bool emitToken(VTTTokenTypes::Type type)
87 { 81 {
88 ASSERT(m_token->type() == type); 82 m_token->setType(type);
89 return true; 83 return true;
90 } 84 }
91 85
92 bool shouldSkipNullCharacters() const { return true; } 86 bool shouldSkipNullCharacters() const { return true; }
93 87
94 private: 88 private:
95 VTTTokenizer();
96
97 // m_token is owned by the caller. If nextToken is not on the stack, 89 // m_token is owned by the caller. If nextToken is not on the stack,
98 // this member might be pointing to unallocated memory. 90 // this member might be pointing to unallocated memory.
99 VTTToken* m_token; 91 VTTToken* m_token;
100 92
101 // This member does not really need to be an instance member - it's only use d in nextToken. 93 // This member does not really need to be an instance member - it's only use d in nextToken.
102 // The reason it's stored here is because of the use of the ADVANCE_TO state helpers. 94 // The reason it's stored here is because of the use of the ADVANCE_TO state helpers.
103 VTTTokenizerState::State m_state; 95 VTTTokenizerState::State m_state;
104 96
105 StringBuilder m_buffer; 97 StringBuilder m_buffer;
98 SegmentedString m_input;
106 99
107 // ://www.whatwg.org/specs/web-apps/current-work/#preprocessing-the-input-st ream 100 // ://www.whatwg.org/specs/web-apps/current-work/#preprocessing-the-input-st ream
108 InputStreamPreprocessor<VTTTokenizer> m_inputStreamPreprocessor; 101 InputStreamPreprocessor<VTTTokenizer> m_inputStreamPreprocessor;
109 }; 102 };
110 103
111 } 104 }
112 105
113 #endif 106 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698