Commit 26326314 authored by andersca's avatar andersca
Browse files

2006-09-26 Anders Carlsson <acarlsson@apple.com>

        Reviewed by Maciej.

        http://bugzilla.opendarwin.org/show_bug.cgi?id=10820
        Add StringImpl::toDouble() and remove uses of .deprecatedString().toDouble()
        
        (Originally written by Eric Seidel).
        
        * bindings/js/kjs_window.cpp:
        (KJS::floatFeature):
        * ksvg2/svg/SVGAngle.cpp:
        (SVGAngle::setValueAsString):
        * ksvg2/svg/SVGAnimationElement.cpp:
        (SVGAnimationElement::parseMappedAttribute):
        * ksvg2/svg/SVGComponentTransferFunctionElement.cpp:
        (SVGComponentTransferFunctionElement::parseMappedAttribute):
        * ksvg2/svg/SVGFECompositeElement.cpp:
        (WebCore::SVGFECompositeElement::parseMappedAttribute):
        * ksvg2/svg/SVGFEDiffuseLightingElement.cpp:
        (WebCore::SVGFEDiffuseLightingElement::parseMappedAttribute):
        * ksvg2/svg/SVGFEDisplacementMapElement.cpp:
        (SVGFEDisplacementMapElement::parseMappedAttribute):
        * ksvg2/...
parent 165ca0b9
2006-09-26 Anders Carlsson <acarlsson@apple.com>
Reviewed by Maciej.
http://bugzilla.opendarwin.org/show_bug.cgi?id=10820
Add StringImpl::toDouble() and remove uses of .deprecatedString().toDouble()
(Originally written by Eric Seidel).
* bindings/js/kjs_window.cpp:
(KJS::floatFeature):
* ksvg2/svg/SVGAngle.cpp:
(SVGAngle::setValueAsString):
* ksvg2/svg/SVGAnimationElement.cpp:
(SVGAnimationElement::parseMappedAttribute):
* ksvg2/svg/SVGComponentTransferFunctionElement.cpp:
(SVGComponentTransferFunctionElement::parseMappedAttribute):
* ksvg2/svg/SVGFECompositeElement.cpp:
(WebCore::SVGFECompositeElement::parseMappedAttribute):
* ksvg2/svg/SVGFEDiffuseLightingElement.cpp:
(WebCore::SVGFEDiffuseLightingElement::parseMappedAttribute):
* ksvg2/svg/SVGFEDisplacementMapElement.cpp:
(SVGFEDisplacementMapElement::parseMappedAttribute):
* ksvg2/svg/SVGFELightElement.cpp:
(SVGFELightElement::parseMappedAttribute):
* ksvg2/svg/SVGFEOffsetElement.cpp:
(WebCore::SVGFEOffsetElement::parseMappedAttribute):
* ksvg2/svg/SVGFESpecularLightingElement.cpp:
(SVGFESpecularLightingElement::parseMappedAttribute):
* ksvg2/svg/SVGFETurbulenceElement.cpp:
(WebCore::SVGFETurbulenceElement::parseMappedAttribute):
* ksvg2/svg/SVGStopElement.cpp:
(SVGStopElement::parseMappedAttribute):
* platform/AtomicString.h:
(WebCore::AtomicString::toDouble):
* platform/PlatformString.h:
* platform/String.cpp:
(WebCore::String::toDouble):
* platform/StringImpl.cpp:
(WebCore::StringImpl::toDouble):
* platform/StringImpl.h:
* rendering/DeprecatedSlider.cpp:
(WebCore::DeprecatedSlider::updateFromElement):
* xml/XPathGrammar.y:
2006-09-25 David Harrison <harrison@apple.com>
 
Reviewed by Tim Omernick and Tim Hatcher.
......@@ -523,12 +523,11 @@ static float floatFeature(const HashMap<String, String> &features, const char *k
HashMap<String, String>::const_iterator it = features.find(key);
if (it == features.end())
return defaultValue;
DeprecatedString value = it->second.deprecatedString();
// FIXME: Can't distinguish "0q" from string with no digits in it -- both return d == 0 and ok == false.
// Would be good to tell them apart somehow since string with no digits should be default value and
// "0q" should be minimum value.
bool ok;
double d = value.toDouble(&ok);
double d = it->second.toDouble(&ok);
if ((d == 0 && !ok) || isnan(d))
return defaultValue;
if (d < min || max <= min)
......
......@@ -92,7 +92,7 @@ void SVGAngle::setValueAsString(const String& s)
m_valueAsString = s;
bool bOK;
m_valueInSpecifiedUnits = m_valueAsString.deprecatedString().toDouble(&bOK);
m_valueInSpecifiedUnits = m_valueAsString.toDouble(&bOK);
m_unitType = SVG_ANGLETYPE_UNSPECIFIED;
if (!bOK) {
......
......@@ -227,7 +227,7 @@ void SVGAnimationElement::parseMappedAttribute(MappedAttribute *attr)
if (value == "indefinite")
m_repeatCount = DBL_MAX;
else
m_repeatCount = value.deprecatedString().toDouble();
m_repeatCount = value.toDouble();
}
else if (attr->name() == SVGNames::repeatDurAttr)
m_repeatDur = value.deprecatedString();
......
......@@ -78,15 +78,15 @@ void SVGComponentTransferFunctionElement::parseMappedAttribute(MappedAttribute *
else if (attr->name() == SVGNames::tableValuesAttr)
tableValuesBaseValue()->parse(value.deprecatedString());
else if (attr->name() == SVGNames::slopeAttr)
setSlopeBaseValue(value.deprecatedString().toDouble());
setSlopeBaseValue(value.toDouble());
else if (attr->name() == SVGNames::interceptAttr)
setInterceptBaseValue(value.deprecatedString().toDouble());
setInterceptBaseValue(value.toDouble());
else if (attr->name() == SVGNames::amplitudeAttr)
setAmplitudeBaseValue(value.deprecatedString().toDouble());
setAmplitudeBaseValue(value.toDouble());
else if (attr->name() == SVGNames::exponentAttr)
setExponentBaseValue(value.deprecatedString().toDouble());
setExponentBaseValue(value.toDouble());
else if (attr->name() == SVGNames::offsetAttr)
setOffsetBaseValue(value.deprecatedString().toDouble());
setOffsetBaseValue(value.toDouble());
else
SVGElement::parseMappedAttribute(attr);
}
......
......@@ -83,13 +83,13 @@ void SVGFECompositeElement::parseMappedAttribute(MappedAttribute *attr)
else if (attr->name() == SVGNames::in2Attr)
setIn2BaseValue(value);
else if (attr->name() == SVGNames::k1Attr)
setK1BaseValue(value.deprecatedString().toDouble());
setK1BaseValue(value.toDouble());
else if (attr->name() == SVGNames::k2Attr)
setK2BaseValue(value.deprecatedString().toDouble());
setK2BaseValue(value.toDouble());
else if (attr->name() == SVGNames::k3Attr)
setK3BaseValue(value.deprecatedString().toDouble());
setK3BaseValue(value.toDouble());
else if (attr->name() == SVGNames::k4Attr)
setK4BaseValue(value.deprecatedString().toDouble());
setK4BaseValue(value.toDouble());
else
SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
}
......
......@@ -63,7 +63,7 @@ void SVGFEDiffuseLightingElement::parseMappedAttribute(MappedAttribute *attr)
if (attr->name() == SVGNames::inAttr)
setIn1BaseValue(value);
else if (attr->name() == SVGNames::surfaceScaleAttr)
setSurfaceScaleBaseValue(value.deprecatedString().toDouble());
setSurfaceScaleBaseValue(value.toDouble());
else if (attr->name() == SVGNames::diffuseConstantAttr)
setDiffuseConstantBaseValue(value.toInt());
else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
......
......@@ -78,7 +78,7 @@ void SVGFEDisplacementMapElement::parseMappedAttribute(MappedAttribute* attr)
else if (attr->name() == SVGNames::in2Attr)
setIn2BaseValue(value);
else if (attr->name() == SVGNames::scaleAttr)
setScaleBaseValue(value.deprecatedString().toDouble());
setScaleBaseValue(value.toDouble());
else
SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
}
......
......@@ -68,25 +68,25 @@ void SVGFELightElement::parseMappedAttribute(MappedAttribute *attr)
{
const String& value = attr->value();
if (attr->name() == SVGNames::azimuthAttr)
setAzimuthBaseValue(value.deprecatedString().toDouble());
setAzimuthBaseValue(value.toDouble());
else if (attr->name() == SVGNames::elevationAttr)
setElevationBaseValue(value.deprecatedString().toDouble());
setElevationBaseValue(value.toDouble());
else if (attr->name() == SVGNames::xAttr)
setXBaseValue(value.deprecatedString().toDouble());
setXBaseValue(value.toDouble());
else if (attr->name() == SVGNames::yAttr)
setYBaseValue(value.deprecatedString().toDouble());
setYBaseValue(value.toDouble());
else if (attr->name() == SVGNames::zAttr)
setZBaseValue(value.deprecatedString().toDouble());
setZBaseValue(value.toDouble());
else if (attr->name() == SVGNames::pointsAtXAttr)
setPointsAtXBaseValue(value.deprecatedString().toDouble());
setPointsAtXBaseValue(value.toDouble());
else if (attr->name() == SVGNames::pointsAtYAttr)
setPointsAtYBaseValue(value.deprecatedString().toDouble());
setPointsAtYBaseValue(value.toDouble());
else if (attr->name() == SVGNames::pointsAtZAttr)
setPointsAtZBaseValue(value.deprecatedString().toDouble());
setPointsAtZBaseValue(value.toDouble());
else if (attr->name() == SVGNames::specularExponentAttr)
setSpecularExponentBaseValue(value.deprecatedString().toDouble());
setSpecularExponentBaseValue(value.toDouble());
else if (attr->name() == SVGNames::limitingConeAngleAttr)
setLimitingConeAngleBaseValue(value.deprecatedString().toDouble());
setLimitingConeAngleBaseValue(value.toDouble());
else
SVGElement::parseMappedAttribute(attr);
}
......
......@@ -55,9 +55,9 @@ void SVGFEOffsetElement::parseMappedAttribute(MappedAttribute *attr)
{
const String& value = attr->value();
if (attr->name() == SVGNames::dxAttr)
setDxBaseValue(value.deprecatedString().toDouble());
setDxBaseValue(value.toDouble());
else if (attr->name() == SVGNames::dyAttr)
setDyBaseValue(value.deprecatedString().toDouble());
setDyBaseValue(value.toDouble());
else if (attr->name() == SVGNames::inAttr)
setIn1BaseValue(value);
else
......
......@@ -69,11 +69,11 @@ void SVGFESpecularLightingElement::parseMappedAttribute(MappedAttribute *attr)
if (attr->name() == SVGNames::inAttr)
setIn1BaseValue(value);
else if (attr->name() == SVGNames::surfaceScaleAttr)
setSurfaceScaleBaseValue(value.deprecatedString().toDouble());
setSurfaceScaleBaseValue(value.toDouble());
else if (attr->name() == SVGNames::specularConstantAttr)
setSpecularConstantBaseValue(value.deprecatedString().toDouble());
setSpecularConstantBaseValue(value.toDouble());
else if (attr->name() == SVGNames::specularExponentAttr)
setSpecularExponentBaseValue(value.deprecatedString().toDouble());
setSpecularExponentBaseValue(value.toDouble());
else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
DeprecatedStringList numbers = DeprecatedStringList::split(' ', value.deprecatedString());
setKernelUnitLengthXBaseValue(numbers[0].toDouble());
......
......@@ -88,7 +88,7 @@ void SVGFETurbulenceElement::parseMappedAttribute(MappedAttribute *attr)
setBaseFrequencyYBaseValue(numbers[1].toDouble());
}
else if (attr->name() == SVGNames::seedAttr)
setSeedBaseValue(value.deprecatedString().toDouble());
setSeedBaseValue(value.toDouble());
else if (attr->name() == SVGNames::numOctavesAttr)
setNumOctavesBaseValue(value.deprecatedString().toUInt());
else
......
......@@ -53,7 +53,7 @@ void SVGStopElement::parseMappedAttribute(MappedAttribute *attr)
if(value.endsWith("%"))
setOffsetBaseValue(value.deprecatedString().left(value.length() - 1).toDouble() / 100.);
else
setOffsetBaseValue(value.deprecatedString().toDouble());
setOffsetBaseValue(value.toDouble());
} else
SVGStyledElement::parseMappedAttribute(attr);
......
......@@ -68,6 +68,7 @@ public:
{ return m_string.endsWith(s.domString(), caseSensitive); }
int toInt(bool* ok = 0) const { return m_string.toInt(ok); }
double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); }
bool percentage(int& p) const { return m_string.percentage(p); }
Length* toLengthArray(int& len) const { return m_string.toLengthArray(len); }
Length* toCoordsArray(int& len) const { return m_string.toCoordsArray(len); }
......
......@@ -130,6 +130,7 @@ public:
Vector<String> split(UChar separator, bool allowEmptyEntries = false) const;
int toInt(bool* ok = 0) const;
double toDouble(bool* ok = 0) const;
Length* toLengthArray(int& len) const;
Length* toCoordsArray(int& len) const;
bool percentage(int &_percentage) const;
......
......@@ -355,6 +355,16 @@ int String::toInt(bool* ok) const
return m_impl->toInt(ok);
}
double String::toDouble(bool* ok) const
{
if (!m_impl) {
if (ok)
*ok = false;
return 0;
}
return m_impl->toDouble(ok);
}
String String::copy() const
{
if (!m_impl)
......
......@@ -28,14 +28,17 @@
#include "StringImpl.h"
#include "AtomicString.h"
#include "CString.h"
#include "DeprecatedString.h"
#include "Length.h"
#include "StringHash.h"
#include "TextEncoding.h"
#include <kjs/identifier.h>
#include <wtf/Assertions.h>
#include <unicode/ubrk.h>
#include <unicode/ustring.h>
#include <assert.h>
#include <JavaScriptCore/dtoa.h>
using namespace WTF;
......@@ -626,6 +629,21 @@ int StringImpl::toInt(bool* ok) const
return DeprecatedConstString(reinterpret_cast<const DeprecatedChar*>(m_data), i).string().toInt(ok);
}
double StringImpl::toDouble(bool* ok) const
{
if (!m_length) {
if (ok)
*ok = false;
return 0;
}
char *end;
CString latin1String = Latin1Encoding().encode(characters(), length());
double val = kjs_strtod(latin1String, &end);
if (ok)
*ok = end == 0 || *end == '\0';
return val;
}
static bool equal(const UChar* a, const char* b, int length)
{
ASSERT(length >= 0);
......
......@@ -94,8 +94,8 @@ public:
bool containsOnlyWhitespace() const;
bool containsOnlyWhitespace(unsigned from, unsigned len) const;
// ignores trailing garbage, unlike DeprecatedString
int toInt(bool* ok = 0) const;
int toInt(bool* ok = 0) const; // ignores trailing garbage, unlike DeprecatedString
double toDouble(bool* ok = 0) const;
Length* toCoordsArray(int& len) const;
Length* toLengthArray(int& len) const;
......
......@@ -70,11 +70,11 @@ void DeprecatedSlider::updateFromElement()
const AtomicString& maxStr = static_cast<HTMLInputElement*>(node())->getAttribute(maxAttr);
const AtomicString& precision = static_cast<HTMLInputElement*>(node())->getAttribute(precisionAttr);
double minVal = minStr.isNull() ? 0.0 : minStr.deprecatedString().toDouble();
double maxVal = maxStr.isNull() ? 100.0 : maxStr.deprecatedString().toDouble();
double minVal = minStr.isNull() ? 0.0 : minStr.toDouble();
double maxVal = maxStr.isNull() ? 100.0 : maxStr.toDouble();
minVal = min(minVal, maxVal); // Make sure the range is sane.
double val = value.isNull() ? (maxVal + minVal)/2.0 : value.deprecatedString().toDouble();
double val = value.isNull() ? (maxVal + minVal)/2.0 : value.toDouble();
val = max(minVal, min(val, maxVal)); // Make sure val is within min/max.
// Force integer value if not float.
......
......@@ -317,13 +317,13 @@ PrimaryExpr:
LITERAL
{
$$ = new StringExpression(*$1);
PARSER->deleteString($1);
PARSER->deleteString($1);
PARSER->registerParseNode($$);
}
|
NUMBER
{
$$ = new Number($1->deprecatedString().toDouble());
$$ = new Number($1->toDouble());
PARSER->deleteString($1);
PARSER->registerParseNode($$);
}
......
Supports Markdown
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