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 "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSParserToken.h" | 6 #include "core/css/parser/CSSParserToken.h" |
7 | 7 |
8 #include "wtf/HashMap.h" | 8 #include "wtf/HashMap.h" |
9 #include "wtf/text/StringHash.h" | 9 #include "wtf/text/StringHash.h" |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 { | 64 { |
65 ASSERT(m_type == NumberToken); | 65 ASSERT(m_type == NumberToken); |
66 m_type = PercentageToken; | 66 m_type = PercentageToken; |
67 m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; | 67 m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; |
68 } | 68 } |
69 | 69 |
70 // This function is used only for testing | 70 // This function is used only for testing |
71 // FIXME - This doesn't cover all possible Token types, but it's enough for curr
ent testing. | 71 // FIXME - This doesn't cover all possible Token types, but it's enough for curr
ent testing. |
72 String CSSParserToken::textForUnitTests() const | 72 String CSSParserToken::textForUnitTests() const |
73 { | 73 { |
74 char buffer[std::numeric_limits<float>::digits]; | |
75 if (!m_value.isNull()) | 74 if (!m_value.isNull()) |
76 return m_value; | 75 return m_value; |
77 if (m_type == LeftParenthesisToken) | 76 if (m_type == LeftParenthesisToken) |
78 return String("("); | 77 return "("; |
79 if (m_type == RightParenthesisToken) | 78 if (m_type == RightParenthesisToken) |
80 return String(")"); | 79 return ")"; |
81 if (m_type == ColonToken) | 80 if (m_type == ColonToken) |
82 return String(":"); | 81 return ":"; |
83 if (m_type == WhitespaceToken) | 82 if (m_type == WhitespaceToken) |
84 return String(" "); | 83 return " "; |
| 84 if (m_delimiter) |
| 85 return String("'") + m_delimiter + '\''; |
85 | 86 |
86 if (m_delimiter) { | |
87 sprintf(buffer, "'%c'", m_delimiter); | |
88 return String(buffer, strlen(buffer)); | |
89 } | |
90 if (m_numericValue) { | 87 if (m_numericValue) { |
91 static const unsigned maxUnitBufferLength = 6; | 88 String unit; |
92 char unitBuffer[maxUnitBufferLength] = {0}; | |
93 if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE) | 89 if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE) |
94 sprintf(unitBuffer, "%s", "%"); | 90 unit = "%"; |
95 else if (m_unit == CSSPrimitiveValue::CSS_PX) | 91 else if (m_unit == CSSPrimitiveValue::CSS_PX) |
96 sprintf(unitBuffer, "%s", "px"); | 92 unit = "px"; |
97 else if (m_unit == CSSPrimitiveValue::CSS_EMS) | 93 else if (m_unit == CSSPrimitiveValue::CSS_EMS) |
98 sprintf(unitBuffer, "%s", "em"); | 94 unit = "em"; |
99 else if (m_unit != CSSPrimitiveValue::CSS_NUMBER) | 95 else if (m_unit != CSSPrimitiveValue::CSS_NUMBER) |
100 sprintf(unitBuffer, "%s", "other"); | 96 unit = "other"; |
101 if (m_numericValueType == IntegerValueType) | 97 if (m_numericValueType == IntegerValueType) |
102 sprintf(buffer, "%d%s", static_cast<int>(m_numericValue), unitBuffer
); | 98 return String::number(static_cast<int>(m_numericValue)) + unit; |
103 else | 99 const unsigned fractionalDigits = 6; |
104 sprintf(buffer, "%f%s", m_numericValue, unitBuffer); | 100 return String::numberToStringFixedWidth(m_numericValue, fractionalDigits
) + unit; |
105 | |
106 return String(buffer, strlen(buffer)); | |
107 } | 101 } |
108 return String(); | 102 return String(); |
109 } | 103 } |
110 | 104 |
111 UChar CSSParserToken::delimiter() const | 105 UChar CSSParserToken::delimiter() const |
112 { | 106 { |
113 ASSERT(m_type == DelimiterToken); | 107 ASSERT(m_type == DelimiterToken); |
114 return m_delimiter; | 108 return m_delimiter; |
115 } | 109 } |
116 | 110 |
117 NumericValueType CSSParserToken::numericValueType() const | 111 NumericValueType CSSParserToken::numericValueType() const |
118 { | 112 { |
119 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
sionToken); | 113 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
sionToken); |
120 return m_numericValueType; | 114 return m_numericValueType; |
121 } | 115 } |
122 | 116 |
123 double CSSParserToken::numericValue() const | 117 double CSSParserToken::numericValue() const |
124 { | 118 { |
125 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
sionToken); | 119 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen
sionToken); |
126 return m_numericValue; | 120 return m_numericValue; |
127 } | 121 } |
128 | 122 |
129 } // namespace blink | 123 } // namespace blink |
OLD | NEW |