Home | History | Annotate | Download | only in parser
      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
      3 // found in the LICENSE file.
      4 
      5 #include "config.h"
      6 #include "core/css/parser/MediaQueryInputStream.h"
      7 
      8 #include "core/html/parser/InputStreamPreprocessor.h"
      9 
     10 namespace WebCore {
     11 
     12 MediaQueryInputStream::MediaQueryInputStream(String input)
     13     : m_offset(0)
     14     , m_string(input)
     15 {
     16 }
     17 
     18 UChar MediaQueryInputStream::peek(unsigned lookaheadOffset)
     19 {
     20     ASSERT((m_offset + lookaheadOffset) <= maxLength());
     21     if ((m_offset + lookaheadOffset) >= m_string.length())
     22         return kEndOfFileMarker;
     23     return m_string[m_offset + lookaheadOffset];
     24 }
     25 
     26 void MediaQueryInputStream::advance(unsigned offset)
     27 {
     28     ASSERT(m_offset + offset <= maxLength());
     29     m_offset += offset;
     30 }
     31 
     32 void MediaQueryInputStream::pushBack(UChar cc)
     33 {
     34     --m_offset;
     35     ASSERT(nextInputChar() == cc);
     36 }
     37 
     38 unsigned long long MediaQueryInputStream::getUInt(unsigned start, unsigned end)
     39 {
     40     ASSERT(start <= end && ((m_offset + end) <= m_string.length()));
     41     bool isResultOK = false;
     42     unsigned long long result = 0;
     43     if (start < end) {
     44         if (m_string.is8Bit())
     45             result = charactersToUInt64Strict(m_string.characters8() + m_offset + start, end - start, &isResultOK);
     46         else
     47             result = charactersToUInt64Strict(m_string.characters16() + m_offset + start, end - start, &isResultOK);
     48     }
     49     return isResultOK ? result : 0;
     50 }
     51 
     52 double MediaQueryInputStream::getDouble(unsigned start, unsigned end)
     53 {
     54     ASSERT(start <= end && ((m_offset + end) <= m_string.length()));
     55     bool isResultOK = false;
     56     double result = 0.0;
     57     if (start < end) {
     58         if (m_string.is8Bit())
     59             result = charactersToDouble(m_string.characters8() + m_offset + start, end - start, &isResultOK);
     60         else
     61             result = charactersToDouble(m_string.characters16() + m_offset + start, end - start, &isResultOK);
     62     }
     63     return isResultOK ? result : 0.0;
     64 }
     65 
     66 } // namespace WebCore
     67