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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSTokenizerInputStream.h

Issue 2160943002: Use CSSTokenizerInputStream::peekWithoutReplacement instead of peek(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: checks. Created 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CSSTokenizerInputStream_h 5 #ifndef CSSTokenizerInputStream_h
6 #define CSSTokenizerInputStream_h 6 #define CSSTokenizerInputStream_h
7 7
8 #include "wtf/text/StringView.h" 8 #include "wtf/text/StringView.h"
9 #include "wtf/text/WTFString.h" 9 #include "wtf/text/WTFString.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 class CSSTokenizerInputStream { 13 class CSSTokenizerInputStream {
14 WTF_MAKE_NONCOPYABLE(CSSTokenizerInputStream); 14 WTF_MAKE_NONCOPYABLE(CSSTokenizerInputStream);
15 USING_FAST_MALLOC(CSSTokenizerInputStream); 15 USING_FAST_MALLOC(CSSTokenizerInputStream);
16 public: 16 public:
17 explicit CSSTokenizerInputStream(String input); 17 explicit CSSTokenizerInputStream(String input);
18 18
19 UChar peek(unsigned) const; 19 // Gets the char in the stream replacing NUL characters with a unicode
20 UChar nextInputChar() const { return peek(0); } 20 // replacement character. Will return (NUL) kEndOfFileMarker when at the
21 // end of the stream.
22 UChar nextInputChar() const
23 {
24 if (m_offset >= m_stringLength)
25 return '\0';
26 UChar result = (*m_string)[m_offset];
27 return result ? result : 0xFFFD;
28 }
21 29
22 // For fast-path code, don't replace nulls with replacement characters 30 // Gets the char at lookaheadOffset from the current stream position. Will
31 // return NUL (kEndOfFileMarker) if the stream position is at the end.
32 // NOTE: This may *also* return NUL if there's one in the input! Never
33 // compare the return value to '\0'.
23 UChar peekWithoutReplacement(unsigned lookaheadOffset) const 34 UChar peekWithoutReplacement(unsigned lookaheadOffset) const
24 { 35 {
25 DCHECK((m_offset + lookaheadOffset) <= m_stringLength); 36 if ((m_offset + lookaheadOffset) >= m_stringLength)
26 if ((m_offset + lookaheadOffset) == m_stringLength)
27 return '\0'; 37 return '\0';
28 return (*m_string)[m_offset + lookaheadOffset]; 38 return (*m_string)[m_offset + lookaheadOffset];
29 } 39 }
30 40
31 void advance(unsigned offset = 1) { m_offset += offset; } 41 void advance(unsigned offset = 1) { m_offset += offset; }
32 void pushBack(UChar cc) 42 void pushBack(UChar cc)
33 { 43 {
34 --m_offset; 44 --m_offset;
35 DCHECK(nextInputChar() == cc); 45 DCHECK(nextInputChar() == cc);
36 } 46 }
(...skipping 17 matching lines...) Expand all
54 private: 64 private:
55 size_t m_offset; 65 size_t m_offset;
56 const size_t m_stringLength; 66 const size_t m_stringLength;
57 const RefPtr<StringImpl> m_string; 67 const RefPtr<StringImpl> m_string;
58 }; 68 };
59 69
60 } // namespace blink 70 } // namespace blink
61 71
62 #endif // CSSTokenizerInputStream_h 72 #endif // CSSTokenizerInputStream_h
63 73
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698