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

Side by Side Diff: sky/engine/core/html/parser/InputStreamPreprocessor.h

Issue 1215103007: Remove remaining HTML elements (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months 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
(Empty)
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/
4 * Copyright (C) 2013 Google, Inc. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef SKY_ENGINE_CORE_HTML_PARSER_INPUTSTREAMPREPROCESSOR_H_
29 #define SKY_ENGINE_CORE_HTML_PARSER_INPUTSTREAMPREPROCESSOR_H_
30
31 #include "sky/engine/platform/text/SegmentedString.h"
32 #include "sky/engine/wtf/Noncopyable.h"
33
34 namespace blink {
35
36 const LChar kEndOfFileMarker = 0;
37
38 // http://www.whatwg.org/specs/web-apps/current-work/#preprocessing-the-input-st ream
39 template <typename Tokenizer>
40 class InputStreamPreprocessor {
41 WTF_MAKE_NONCOPYABLE(InputStreamPreprocessor);
42 public:
43 InputStreamPreprocessor(Tokenizer* tokenizer)
44 : m_tokenizer(tokenizer)
45 {
46 reset();
47 }
48
49 ALWAYS_INLINE UChar nextInputCharacter() const { return m_nextInputCharacter ; }
50
51 // Returns whether we succeeded in peeking at the next character.
52 // The only way we can fail to peek is if there are no more
53 // characters in |source| (after collapsing \r\n, etc).
54 ALWAYS_INLINE bool peek(SegmentedString& source)
55 {
56 m_nextInputCharacter = source.currentChar();
57
58 // Every branch in this function is expensive, so we have a
59 // fast-reject branch for characters that don't require special
60 // handling. Please run the parser benchmark whenever you touch
61 // this function. It's very hot.
62 static const UChar specialCharacterMask = '\n' | '\r';
63 if (m_nextInputCharacter & ~specialCharacterMask) {
64 m_skipNextNewLine = false;
65 return true;
66 }
67 return processNextInputCharacter(source);
68 }
69
70 // Returns whether there are more characters in |source| after advancing.
71 ALWAYS_INLINE bool advance(SegmentedString& source)
72 {
73 source.advanceAndUpdateLineNumber();
74 if (source.isEmpty())
75 return false;
76 return peek(source);
77 }
78
79 bool skipNextNewLine() const { return m_skipNextNewLine; }
80
81 void reset(bool skipNextNewLine = false)
82 {
83 m_nextInputCharacter = '\0';
84 m_skipNextNewLine = skipNextNewLine;
85 }
86
87 private:
88 bool processNextInputCharacter(SegmentedString& source)
89 {
90 ASSERT(m_nextInputCharacter == source.currentChar());
91
92 if (m_nextInputCharacter == '\n' && m_skipNextNewLine) {
93 m_skipNextNewLine = false;
94 source.advancePastNewlineAndUpdateLineNumber();
95 if (source.isEmpty())
96 return false;
97 m_nextInputCharacter = source.currentChar();
98 }
99 if (m_nextInputCharacter == '\r') {
100 m_nextInputCharacter = '\n';
101 m_skipNextNewLine = true;
102 } else {
103 m_skipNextNewLine = false;
104 // FIXME: The spec indicates that the surrogate pair range as well a s
105 // a number of specific character values are parse errors and should be replaced
106 // by the replacement character. We suspect this is a problem with t he spec as doing
107 // that filtering breaks surrogate pair handling and causes us not t o match Minefield.
108 }
109 return true;
110 }
111
112 Tokenizer* m_tokenizer;
113
114 // http://www.whatwg.org/specs/web-apps/current-work/#next-input-character
115 UChar m_nextInputCharacter;
116 bool m_skipNextNewLine;
117 };
118
119 }
120
121 #endif // SKY_ENGINE_CORE_HTML_PARSER_INPUTSTREAMPREPROCESSOR_H_
122
OLDNEW
« no previous file with comments | « sky/engine/core/html/parser/HTMLTreeBuilder.cpp ('k') | sky/engine/core/html/parser/MarkupTokenizerInlines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698