| 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 #include "core/css/parser/CSSTokenizerInputStream.h" | 5 #include "core/css/parser/CSSTokenizerInputStream.h" |
| 6 | 6 |
| 7 #include "core/css/parser/CSSParserString.h" | 7 #include "core/css/parser/CSSParserString.h" |
| 8 #include "core/html/parser/InputStreamPreprocessor.h" | 8 #include "core/html/parser/InputStreamPreprocessor.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 CSSTokenizerInputStream::CSSTokenizerInputStream(String input) | 12 double CSSTokenizerInputStream::getDouble(unsigned start, unsigned end) const |
| 13 : m_offset(0) | |
| 14 , m_stringLength(input.length()) | |
| 15 , m_string(input.impl()) | |
| 16 { | 13 { |
| 17 } | 14 ASSERT(start <= end && ((m_offset + end) <= length())); |
| 18 | |
| 19 UChar CSSTokenizerInputStream::peek(unsigned lookaheadOffset) | |
| 20 { | |
| 21 if ((m_offset + lookaheadOffset) >= m_stringLength) | |
| 22 return kEndOfFileMarker; | |
| 23 UChar result = (*m_string)[m_offset + lookaheadOffset]; | |
| 24 return result ? result : 0xFFFD; | |
| 25 } | |
| 26 | |
| 27 void CSSTokenizerInputStream::pushBack(UChar cc) | |
| 28 { | |
| 29 --m_offset; | |
| 30 ASSERT(nextInputChar() == cc); | |
| 31 } | |
| 32 | |
| 33 double CSSTokenizerInputStream::getDouble(unsigned start, unsigned end) | |
| 34 { | |
| 35 ASSERT(start <= end && ((m_offset + end) <= m_stringLength)); | |
| 36 bool isResultOK = false; | 15 bool isResultOK = false; |
| 37 double result = 0.0; | 16 double result = 0.0; |
| 38 if (start < end) { | 17 if (start < end) { |
| 39 if (m_string->is8Bit()) | 18 if (m_string->is8Bit()) |
| 40 result = charactersToDouble(m_string->characters8() + m_offset + sta
rt, end - start, &isResultOK); | 19 result = charactersToDouble(m_string->characters8() + m_offset + sta
rt, end - start, &isResultOK); |
| 41 else | 20 else |
| 42 result = charactersToDouble(m_string->characters16() + m_offset + st
art, end - start, &isResultOK); | 21 result = charactersToDouble(m_string->characters16() + m_offset + st
art, end - start, &isResultOK); |
| 43 } | 22 } |
| 44 // FIXME: It looks like callers ensure we have a valid number | 23 // FIXME: It looks like callers ensure we have a valid number |
| 45 return isResultOK ? result : 0.0; | 24 return isResultOK ? result : 0.0; |
| 46 } | 25 } |
| 47 | 26 |
| 48 CSSParserString CSSTokenizerInputStream::rangeAsCSSParserString(unsigned start,
unsigned length) const | 27 CSSParserString CSSTokenizerInputStream::rangeAsCSSParserString(unsigned start,
unsigned length) const |
| 49 { | 28 { |
| 50 ASSERT(start + length <= m_stringLength); | 29 ASSERT(start + length <= length()); |
| 51 CSSParserString result; | 30 CSSParserString result; |
| 52 if (m_string->is8Bit()) | 31 if (m_string->is8Bit()) |
| 53 result.init(m_string->characters8() + start, length); | 32 result.init(m_string->characters8() + start, length); |
| 54 else | 33 else |
| 55 result.init(m_string->characters16() + start, length); | 34 result.init(m_string->characters16() + start, length); |
| 56 return result; | 35 return result; |
| 57 } | 36 } |
| 58 | 37 |
| 59 } // namespace blink | 38 } // namespace blink |
| OLD | NEW |