OLD | NEW |
---|---|
(Empty) | |
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(currentInputChar() == 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 if (start < end) { | |
43 unsigned long long result; | |
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 if (isResultOK) | |
eseidel
2014/03/13 17:22:07
nit: I might have written this as a ternary at the
| |
49 return result; | |
50 } | |
51 return 0; | |
52 } | |
53 | |
54 double MediaQueryInputStream::getDouble(unsigned start, unsigned end) | |
55 { | |
56 ASSERT(start <= end && ((m_offset + end) <= m_string.length())); | |
57 bool isResultOK = false; | |
58 if (start < end) { | |
59 double result; | |
60 if (m_string.is8Bit()) | |
61 result = charactersToDouble(m_string.characters8() + m_offset + star t, end - start, &isResultOK); | |
eseidel
2014/03/13 17:22:07
Sigh. If we had a StringView class then the calle
| |
62 else | |
63 result = charactersToDouble(m_string.characters16() + m_offset + sta rt, end - start, &isResultOK); | |
64 if (isResultOK) | |
65 return result; | |
66 } | |
67 return 0.0; | |
68 } | |
69 | |
70 } // namespace WebCore | |
OLD | NEW |