Commit b8905c62 authored by timloh@chromium.org's avatar timloh@chromium.org

Simplify CSSParserToken::textForUnitTests by using more WTF helpers

Instead of manually handling char arrays and using sprintf in converting
CSSParserTokens to strings, we should just concatenate Strings and use
String::number. I didn't bother using StringBuilder here since the
function is only used in unit tests and it's a bit more readable this way.

Review URL: https://codereview.chromium.org/667663002

git-svn-id: svn://svn.chromium.org/blink/trunk@183975 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a0023941
...@@ -71,39 +71,33 @@ void CSSParserToken::convertToPercentage() ...@@ -71,39 +71,33 @@ void CSSParserToken::convertToPercentage()
// FIXME - This doesn't cover all possible Token types, but it's enough for current testing. // FIXME - This doesn't cover all possible Token types, but it's enough for current testing.
String CSSParserToken::textForUnitTests() const String CSSParserToken::textForUnitTests() const
{ {
char buffer[std::numeric_limits<float>::digits];
if (!m_value.isNull()) if (!m_value.isNull())
return m_value; return m_value;
if (m_type == LeftParenthesisToken) if (m_type == LeftParenthesisToken)
return String("("); return "(";
if (m_type == RightParenthesisToken) if (m_type == RightParenthesisToken)
return String(")"); return ")";
if (m_type == ColonToken) if (m_type == ColonToken)
return String(":"); return ":";
if (m_type == WhitespaceToken) 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) { if (m_numericValue) {
static const unsigned maxUnitBufferLength = 6; String unit;
char unitBuffer[maxUnitBufferLength] = {0};
if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE) if (m_unit == CSSPrimitiveValue::CSS_PERCENTAGE)
sprintf(unitBuffer, "%s", "%"); unit = "%";
else if (m_unit == CSSPrimitiveValue::CSS_PX) else if (m_unit == CSSPrimitiveValue::CSS_PX)
sprintf(unitBuffer, "%s", "px"); unit = "px";
else if (m_unit == CSSPrimitiveValue::CSS_EMS) else if (m_unit == CSSPrimitiveValue::CSS_EMS)
sprintf(unitBuffer, "%s", "em"); unit = "em";
else if (m_unit != CSSPrimitiveValue::CSS_NUMBER) else if (m_unit != CSSPrimitiveValue::CSS_NUMBER)
sprintf(unitBuffer, "%s", "other"); unit = "other";
if (m_numericValueType == IntegerValueType) if (m_numericValueType == IntegerValueType)
sprintf(buffer, "%d%s", static_cast<int>(m_numericValue), unitBuffer); return String::number(static_cast<int>(m_numericValue)) + unit;
else const unsigned fractionalDigits = 6;
sprintf(buffer, "%f%s", m_numericValue, unitBuffer); return String::numberToStringFixedWidth(m_numericValue, fractionalDigits) + unit;
return String(buffer, strlen(buffer));
} }
return String(); return String();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment