Chromium Code Reviews| 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 "core/html/parser/InputStreamPreprocessor.h" | |
| 8 #include "wtf/text/WTFString.h" | 9 #include "wtf/text/WTFString.h" |
| 9 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 12 struct CSSParserString; | 13 struct CSSParserString; |
| 13 | 14 |
| 14 class CSSTokenizerInputStream { | 15 class CSSTokenizerInputStream { |
| 15 WTF_MAKE_NONCOPYABLE(CSSTokenizerInputStream); | 16 WTF_MAKE_NONCOPYABLE(CSSTokenizerInputStream); |
| 16 USING_FAST_MALLOC(CSSTokenizerInputStream); | 17 DISALLOW_NEW(); |
|
esprehn
2016/04/22 23:30:58
always on the stack or a member :)
| |
| 17 public: | 18 public: |
| 18 CSSTokenizerInputStream(String input); | 19 explicit CSSTokenizerInputStream(const String& input) |
| 20 : m_offset(0) | |
| 21 , m_string(input.impl()) | |
| 22 { | |
| 23 } | |
| 19 | 24 |
| 20 UChar peek(unsigned); | 25 UChar peek(unsigned) const; |
| 21 inline UChar nextInputChar() | 26 UChar nextInputChar() const |
|
esprehn
2016/04/22 23:30:58
missing const on both, also don't need inline in t
| |
| 22 { | 27 { |
| 23 return peek(0); | 28 return peek(0); |
| 24 } | 29 } |
| 25 | 30 |
| 26 // For fast-path code, don't replace nulls with replacement characters | 31 // For fast-path code, don't replace nulls with replacement characters |
| 27 UChar peekWithoutReplacement(unsigned lookaheadOffset) | 32 UChar peekWithoutReplacement(unsigned lookaheadOffset) const |
| 28 { | 33 { |
| 29 ASSERT((m_offset + lookaheadOffset) <= m_stringLength); | 34 ASSERT((m_offset + lookaheadOffset) <= length()); |
| 30 if ((m_offset + lookaheadOffset) == m_stringLength) | 35 if ((m_offset + lookaheadOffset) == length()) |
| 31 return '\0'; | 36 return '\0'; |
| 32 return (*m_string)[m_offset + lookaheadOffset]; | 37 return (*m_string)[m_offset + lookaheadOffset]; |
| 33 } | 38 } |
| 34 | 39 |
| 35 void advance(unsigned offset = 1) { m_offset += offset; } | 40 void advance(unsigned offset = 1) { m_offset += offset; } |
| 36 void pushBack(UChar); | 41 void pushBack(UChar); |
| 37 | 42 |
| 38 double getDouble(unsigned start, unsigned end); | 43 double getDouble(unsigned start, unsigned end) const; |
|
esprehn
2016/04/22 23:30:58
missing const
| |
| 39 | 44 |
| 40 template<bool characterPredicate(UChar)> | 45 template<bool characterPredicate(UChar)> |
| 41 unsigned skipWhilePredicate(unsigned offset) | 46 unsigned skipWhilePredicate(unsigned offset) |
| 42 { | 47 { |
| 43 while ((m_offset + offset) < m_stringLength && characterPredicate((*m_st ring)[m_offset + offset])) | 48 while ((m_offset + offset) < length() && characterPredicate((*m_string)[ m_offset + offset])) |
| 44 ++offset; | 49 ++offset; |
| 45 return offset; | 50 return offset; |
| 46 } | 51 } |
| 47 | 52 |
| 48 unsigned offset() const { return std::min(m_offset, m_stringLength); } | 53 unsigned length() const { return m_string->length(); } |
| 54 unsigned offset() const { return std::min(m_offset, length()); } | |
| 49 CSSParserString rangeAsCSSParserString(unsigned start, unsigned length) cons t; | 55 CSSParserString rangeAsCSSParserString(unsigned start, unsigned length) cons t; |
| 50 | 56 |
| 51 private: | 57 private: |
| 52 size_t m_offset; | 58 unsigned m_offset; |
| 53 const size_t m_stringLength; | |
|
esprehn
2016/04/22 23:30:58
There's no reason to store the length, we have it
| |
| 54 const RefPtr<StringImpl> m_string; | 59 const RefPtr<StringImpl> m_string; |
| 55 }; | 60 }; |
| 56 | 61 |
| 62 inline UChar CSSTokenizerInputStream::peek(unsigned lookaheadOffset) const | |
| 63 { | |
| 64 if ((m_offset + lookaheadOffset) >= length()) | |
| 65 return kEndOfFileMarker; | |
| 66 UChar result = (*m_string)[m_offset + lookaheadOffset]; | |
| 67 return result ? result : 0xFFFD; | |
| 68 } | |
| 69 | |
| 70 inline void CSSTokenizerInputStream::pushBack(UChar cc) | |
| 71 { | |
| 72 --m_offset; | |
| 73 ASSERT(nextInputChar() == cc); | |
| 74 } | |
| 75 | |
| 57 } // namespace blink | 76 } // namespace blink |
| 58 | 77 |
| 59 #endif // CSSTokenizerInputStream_h | 78 #endif // CSSTokenizerInputStream_h |
| 60 | 79 |
| OLD | NEW |