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 #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 return String::number(m_numericValue, 6, KeepTrailingZeros) + unit; |
|
Yoav Weiss
2014/10/20 08:04:43
If I understand correctly the intention here is to
Timothy Loh
2014/10/20 08:16:38
Would it be clearer with "const int significantDig
Yoav Weiss
2014/10/20 08:38:24
Maybe replace this line with 'return String::numbe
Timothy Loh
2014/10/20 10:52:32
Done.
| |
| 104 sprintf(buffer, "%f%s", m_numericValue, unitBuffer); | |
| 105 | |
| 106 return String(buffer, strlen(buffer)); | |
| 107 } | 100 } |
| 108 return String(); | 101 return String(); |
| 109 } | 102 } |
| 110 | 103 |
| 111 UChar CSSParserToken::delimiter() const | 104 UChar CSSParserToken::delimiter() const |
| 112 { | 105 { |
| 113 ASSERT(m_type == DelimiterToken); | 106 ASSERT(m_type == DelimiterToken); |
| 114 return m_delimiter; | 107 return m_delimiter; |
| 115 } | 108 } |
| 116 | 109 |
| 117 NumericValueType CSSParserToken::numericValueType() const | 110 NumericValueType CSSParserToken::numericValueType() const |
| 118 { | 111 { |
| 119 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen sionToken); | 112 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen sionToken); |
| 120 return m_numericValueType; | 113 return m_numericValueType; |
| 121 } | 114 } |
| 122 | 115 |
| 123 double CSSParserToken::numericValue() const | 116 double CSSParserToken::numericValue() const |
| 124 { | 117 { |
| 125 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen sionToken); | 118 ASSERT(m_type == NumberToken || m_type == PercentageToken || m_type == Dimen sionToken); |
| 126 return m_numericValue; | 119 return m_numericValue; |
| 127 } | 120 } |
| 128 | 121 |
| 129 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |