Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Unified Diff: Source/core/css/parser/CSSParserToken.cpp

Issue 667663002: Simplify CSSParserToken::textForUnitTests by using more WTF helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use numberToStringFixedWidth Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/parser/CSSParserToken.cpp
diff --git a/Source/core/css/parser/CSSParserToken.cpp b/Source/core/css/parser/CSSParserToken.cpp
index a57271e903bb090ae0768b908b793643fbfbb031..e936c08b66315c490096e117ea8c97638617083c 100644
--- a/Source/core/css/parser/CSSParserToken.cpp
+++ b/Source/core/css/parser/CSSParserToken.cpp
@@ -71,39 +71,33 @@ void CSSParserToken::convertToPercentage()
// FIXME - This doesn't cover all possible Token types, but it's enough for current testing.
String CSSParserToken::textForUnitTests() const
{
- char buffer[std::numeric_limits<float>::digits];
if (!m_value.isNull())
return m_value;
if (m_type == LeftParenthesisToken)
- return String("(");
+ return "(";
if (m_type == RightParenthesisToken)
- return String(")");
+ return ")";
if (m_type == ColonToken)
- return String(":");
+ return ":";
if (m_type == WhitespaceToken)
- return String(" ");
+ return " ";
+ if (m_delimiter)
+ return String("'") + m_delimiter + '\'';
- if (m_delimiter) {
- sprintf(buffer, "'%c'", m_delimiter);
- return String(buffer, strlen(buffer));
- }
if (m_numericValue) {
- static const unsigned maxUnitBufferLength = 6;
- char unitBuffer[maxUnitBufferLength] = {0};
+ String unit;
if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE)
- sprintf(unitBuffer, "%s", "%");
+ unit = "%";
else if (m_unit == CSSPrimitiveValue::CSS_PX)
- sprintf(unitBuffer, "%s", "px");
+ unit = "px";
else if (m_unit == CSSPrimitiveValue::CSS_EMS)
- sprintf(unitBuffer, "%s", "em");
+ unit = "em";
else if (m_unit != CSSPrimitiveValue::CSS_NUMBER)
- sprintf(unitBuffer, "%s", "other");
+ unit = "other";
if (m_numericValueType == IntegerValueType)
- sprintf(buffer, "%d%s", static_cast<int>(m_numericValue), unitBuffer);
- else
- sprintf(buffer, "%f%s", m_numericValue, unitBuffer);
-
- return String(buffer, strlen(buffer));
+ return String::number(static_cast<int>(m_numericValue)) + unit;
+ const unsigned fractionalDigits = 6;
+ return String::numberToStringFixedWidth(m_numericValue, fractionalDigits) + unit;
}
return String();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698