| OLD | NEW |
| 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 CSSTokenizerInputStream(String input); | 17 explicit CSSTokenizerInputStream(String input); |
| 18 | 18 |
| 19 UChar peek(unsigned); | 19 UChar peek(unsigned) const; |
| 20 inline UChar nextInputChar() | 20 UChar nextInputChar() const { return peek(0); } |
| 21 { | |
| 22 return peek(0); | |
| 23 } | |
| 24 | 21 |
| 25 // For fast-path code, don't replace nulls with replacement characters | 22 // For fast-path code, don't replace nulls with replacement characters |
| 26 UChar peekWithoutReplacement(unsigned lookaheadOffset) | 23 UChar peekWithoutReplacement(unsigned lookaheadOffset) const |
| 27 { | 24 { |
| 28 ASSERT((m_offset + lookaheadOffset) <= m_stringLength); | 25 DCHECK((m_offset + lookaheadOffset) <= m_stringLength); |
| 29 if ((m_offset + lookaheadOffset) == m_stringLength) | 26 if ((m_offset + lookaheadOffset) == m_stringLength) |
| 30 return '\0'; | 27 return '\0'; |
| 31 return (*m_string)[m_offset + lookaheadOffset]; | 28 return (*m_string)[m_offset + lookaheadOffset]; |
| 32 } | 29 } |
| 33 | 30 |
| 34 void advance(unsigned offset = 1) { m_offset += offset; } | 31 void advance(unsigned offset = 1) { m_offset += offset; } |
| 35 void pushBack(UChar); | 32 void pushBack(UChar cc) |
| 33 { |
| 34 --m_offset; |
| 35 DCHECK(nextInputChar() == cc); |
| 36 } |
| 36 | 37 |
| 37 double getDouble(unsigned start, unsigned end); | 38 double getDouble(unsigned start, unsigned end) const; |
| 38 | 39 |
| 39 template<bool characterPredicate(UChar)> | 40 template<bool characterPredicate(UChar)> |
| 40 unsigned skipWhilePredicate(unsigned offset) | 41 unsigned skipWhilePredicate(unsigned offset) |
| 41 { | 42 { |
| 42 while ((m_offset + offset) < m_stringLength && characterPredicate((*m_st
ring)[m_offset + offset])) | 43 while ((m_offset + offset) < m_stringLength && characterPredicate((*m_st
ring)[m_offset + offset])) |
| 43 ++offset; | 44 ++offset; |
| 44 return offset; | 45 return offset; |
| 45 } | 46 } |
| 46 | 47 |
| 47 void advanceUntilNonWhitespace(); | 48 void advanceUntilNonWhitespace(); |
| 48 | 49 |
| 49 unsigned length() const { return m_stringLength; } | 50 unsigned length() const { return m_stringLength; } |
| 50 unsigned offset() const { return std::min(m_offset, m_stringLength); } | 51 unsigned offset() const { return std::min(m_offset, m_stringLength); } |
| 51 StringView rangeAt(unsigned start, unsigned length) const; | 52 StringView rangeAt(unsigned start, unsigned length) const; |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 size_t m_offset; | 55 size_t m_offset; |
| 55 const size_t m_stringLength; | 56 const size_t m_stringLength; |
| 56 const RefPtr<StringImpl> m_string; | 57 const RefPtr<StringImpl> m_string; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 } // namespace blink | 60 } // namespace blink |
| 60 | 61 |
| 61 #endif // CSSTokenizerInputStream_h | 62 #endif // CSSTokenizerInputStream_h |
| 62 | 63 |
| OLD | NEW |