Changeset 242360 in webkit
- Timestamp:
- Mar 4, 2019, 8:58:33 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/svg/dom/SVGAngle-expected.txt (modified) (3 diffs)
-
LayoutTests/svg/dom/SVGAngle.html (modified) (3 diffs)
-
LayoutTests/svg/dom/SVGLength-px-expected.txt (modified) (3 diffs)
-
LayoutTests/svg/dom/SVGLength-px-with-context-expected.txt (modified) (7 diffs)
-
LayoutTests/svg/dom/SVGLength-px-with-context.html (modified) (7 diffs)
-
LayoutTests/svg/dom/SVGLength-px.html (modified) (3 diffs)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/dtoa.cpp (modified) (5 diffs)
-
Source/WTF/wtf/text/AtomicString.cpp (modified) (1 diff)
-
Source/WTF/wtf/text/AtomicString.h (modified) (1 diff)
-
Source/WTF/wtf/text/StringBuilder.cpp (modified) (2 diffs)
-
Source/WTF/wtf/text/StringBuilder.h (modified) (2 diffs)
-
Source/WTF/wtf/text/WTFString.cpp (modified) (3 diffs)
-
Source/WTF/wtf/text/WTFString.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r242358 r242360 1 2019-03-03 Darin Adler <darin@apple.com> 2 3 Prepare to improve handling of conversion of float to strings 4 https://bugs.webkit.org/show_bug.cgi?id=195262 5 6 Reviewed by Daniel Bates. 7 8 * svg/dom/SVGAngle-expected.txt: 9 * svg/dom/SVGAngle.html: 10 * svg/dom/SVGLength-px-expected.txt: 11 * svg/dom/SVGLength-px-with-context-expected.txt: 12 * svg/dom/SVGLength-px-with-context.html: 13 * svg/dom/SVGLength-px.html: 14 Remove checks that depend on the precision and number of serialization. 15 The current tests depend on behavior that we'd like to change in the future and 16 some of them had already been updated since the behavior is different in different 17 web browsers. Tricky issue because of the mix of single and double precision in 18 the SVG engine and the JavaScript language, and straightforward to keep the tests 19 useful without this unnecessary dependency. Generally we check the units of the 20 result of valueAsString, and not the numeric result. Another idea would be to 21 check the numeric part of the result by converting it back to a number and 22 comparing it as a number rather than as a string. 23 1 24 2019-03-04 Truitt Savell <tsavell@apple.com> 2 25 -
trunk/LayoutTests/svg/dom/SVGAngle-expected.txt
r219663 r242360 67 67 Check valid arguments for 'newValueSpecifiedUnits', that should only modify the 'valueAsString' 68 68 PASS angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, parseFloat(Math.PI.toFixed(5))) is undefined. 69 PASS angle.valueAsString is "3.14159rad"69 PASS angle.valueAsString.slice(-3) is "rad" 70 70 PASS angle.value.toFixed(1) is "180.0" 71 71 PASS angle.valueInSpecifiedUnits.toFixed(5) is Math.PI.toFixed(5) … … 171 171 PASS angle.value.toFixed(1) is "180.0" 172 172 PASS angle.valueInSpecifiedUnits.toFixed(5) is "3.14159" 173 PASS angle.valueAsString is "3.14159rad"173 PASS angle.valueAsString.slice(-3) is "rad" 174 174 PASS angle.unitType is SVGAngle.SVG_ANGLETYPE_RAD 175 175 … … 178 178 PASS angle.value.toFixed(1) is "180.0" 179 179 PASS angle.valueInSpecifiedUnits.toFixed(5) is "3.14159" 180 PASS angle.valueAsString is "3.14159rad"180 PASS angle.valueAsString.slice(-3) is "rad" 181 181 PASS angle.unitType is SVGAngle.SVG_ANGLETYPE_RAD 182 182 -
trunk/LayoutTests/svg/dom/SVGAngle.html
r217390 r242360 90 90 debug("Check valid arguments for 'newValueSpecifiedUnits', that should only modify the 'valueAsString'"); 91 91 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, parseFloat(Math.PI.toFixed(5)))"); 92 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); 92 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 93 shouldBeEqualToString("angle.valueAsString.slice(-3)", "rad"); 93 94 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); 94 95 shouldBe("angle.valueInSpecifiedUnits.toFixed(5)", "Math.PI.toFixed(5)"); … … 214 215 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); 215 216 shouldBeEqualToString("angle.valueInSpecifiedUnits.toFixed(5)", Math.PI.toFixed(5)); 216 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); 217 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 218 shouldBeEqualToString("angle.valueAsString.slice(-3)", "rad"); 217 219 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); 218 220 … … 222 224 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); 223 225 shouldBeEqualToString("angle.valueInSpecifiedUnits.toFixed(5)", Math.PI.toFixed(5)); 224 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); 226 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 227 shouldBeEqualToString("angle.valueAsString.slice(-3)", "rad"); 225 228 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); 226 229 -
trunk/LayoutTests/svg/dom/SVGLength-px-expected.txt
r219663 r242360 49 49 Convert from px to cm 50 50 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM) is undefined. 51 PASS length.valueAsString is "0.0529167cm"51 PASS length.valueAsString.slice(-2) is "cm" 52 52 PASS length.valueInSpecifiedUnits.toFixed(7) is "0.0529167" 53 53 PASS length.value.toFixed(1) is "2.0" … … 58 58 Convert from px to mm 59 59 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM) is undefined. 60 PASS length.valueAsString is "0.529167mm"60 PASS length.valueAsString.slice(-2) is "mm" 61 61 PASS length.valueInSpecifiedUnits.toFixed(6) is "0.529167" 62 62 PASS length.value.toFixed(1) is "2.0" … … 67 67 Convert from px to in 68 68 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN) is undefined. 69 PASS length.valueAsString is "0.0208333in"69 PASS length.valueAsString.slice(-2) is "in" 70 70 PASS length.valueInSpecifiedUnits.toFixed(7) is "0.0208333" 71 71 PASS length.value.toFixed(1) is "2.0" -
trunk/LayoutTests/svg/dom/SVGLength-px-with-context-expected.txt
r71014 r242360 22 22 Convert from px to percentage 23 23 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PERCENTAGE) is undefined. 24 PASS length.valueAsString is "1.33333%"24 PASS length.valueAsString.slice(-1) is "%" 25 25 PASS length.valueInSpecifiedUnits.toFixed(5) is "1.33333" 26 26 PASS length.value.toFixed(1) is "2.0" … … 31 31 Convert from px to ems 32 32 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_EMS) is undefined. 33 PASS length.valueAsString is "0.166667em"33 PASS length.valueAsString.slice(-2) is "em" 34 34 PASS length.valueInSpecifiedUnits.toFixed(6) is "0.166667" 35 35 PASS length.value.toFixed(1) is "2.0" … … 40 40 Convert from px to exs 41 41 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_EXS) is undefined. 42 PASS length.valueAsString.slice(-2) is "ex" 42 43 PASS length.valueInSpecifiedUnits.toFixed(1) is "0.2" 43 44 PASS length.value.toFixed(1) is "2.0" … … 48 49 Convert from px to cm 49 50 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM) is undefined. 50 PASS length.valueAsString is "0.0529167cm"51 PASS length.valueAsString.slice(-2) is "cm" 51 52 PASS length.valueInSpecifiedUnits.toFixed(7) is "0.0529167" 52 53 PASS length.value.toFixed(1) is "2.0" … … 57 58 Convert from px to mm 58 59 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM) is undefined. 59 PASS length.valueAsString is "0.529167mm"60 PASS length.valueAsString.slice(-2) is "mm" 60 61 PASS length.valueInSpecifiedUnits.toFixed(6) is "0.529167" 61 62 PASS length.value.toFixed(1) is "2.0" … … 66 67 Convert from px to in 67 68 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN) is undefined. 68 PASS length.valueAsString is "0.0208333in"69 PASS length.valueAsString.slice(-2) is "in" 69 70 PASS length.valueInSpecifiedUnits.toFixed(7) is "0.0208333" 70 71 PASS length.value.toFixed(1) is "2.0" … … 84 85 Convert from px to pc 85 86 PASS length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PC) is undefined. 87 PASS length.valueAsString.slice(-2) is "pc" 86 88 PASS length.valueInSpecifiedUnits.toFixed(3) is "0.125" 87 89 PASS length.value.toFixed(1) is "2.0" -
trunk/LayoutTests/svg/dom/SVGLength-px-with-context.html
r217390 r242360 81 81 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PERCENTAGE)"); 82 82 referenceValue = Number(2 / svgWidth * 100).toFixed(5); 83 shouldBeEqualToString("length.valueAsString", referenceValue + "%"); 83 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 84 shouldBeEqualToString("length.valueAsString.slice(-1)", "%"); 84 85 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(5)", referenceValue); 85 86 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 94 95 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_EMS)"); 95 96 referenceValue = Number(2 / fontSize).toFixed(6); 96 shouldBeEqualToString("length.valueAsString", referenceValue + "em"); 97 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 98 shouldBeEqualToString("length.valueAsString.slice(-2)", "em"); 97 99 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(6)", referenceValue); 98 100 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 107 109 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_EXS)"); 108 110 referenceValue = Number(2 / calculateXHeight()).toFixed(1); 109 // Don't check valueAsString here, it's unreliable across browsers. 111 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 112 shouldBeEqualToString("length.valueAsString.slice(-2)", "ex"); 110 113 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(1)", referenceValue); 111 114 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 120 123 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM)"); 121 124 referenceValue = Number(2 * 2.54 / cssPixelsPerInch).toFixed(7); 122 shouldBeEqualToString("length.valueAsString", referenceValue + "cm"); 125 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 126 shouldBeEqualToString("length.valueAsString.slice(-2)", "cm"); 123 127 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(7)", referenceValue); 124 128 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 133 137 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM)"); 134 138 referenceValue = Number(2 * 25.4 / cssPixelsPerInch).toFixed(6); 135 shouldBeEqualToString("length.valueAsString", referenceValue + "mm"); 139 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 140 shouldBeEqualToString("length.valueAsString.slice(-2)", "mm"); 136 141 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(6)", referenceValue); 137 142 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 146 151 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN)"); 147 152 referenceValue = Number(2 / cssPixelsPerInch).toFixed(7); 148 shouldBeEqualToString("length.valueAsString", referenceValue + "in"); 153 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 154 shouldBeEqualToString("length.valueAsString.slice(-2)", "in"); 149 155 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(7)", referenceValue); 150 156 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 172 178 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PC)"); 173 179 referenceValue = Number(2 / cssPixelsPerInch * 6).toFixed(3); 174 // Don't check valueAsString here, it's unreliable across browsers. 180 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 181 shouldBeEqualToString("length.valueAsString.slice(-2)", "pc"); 175 182 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(3)", referenceValue); 176 183 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); -
trunk/LayoutTests/svg/dom/SVGLength-px.html
r217390 r242360 94 94 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM)"); 95 95 referenceValue = Number(2 * 2.54 / cssPixelsPerInch).toFixed(7); 96 shouldBeEqualToString("length.valueAsString", referenceValue + "cm"); 96 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 97 shouldBeEqualToString("length.valueAsString.slice(-2)", "cm"); 97 98 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(7)", referenceValue); 98 99 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 107 108 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM)"); 108 109 referenceValue = Number(2 * 25.4 / cssPixelsPerInch).toFixed(6); 109 shouldBeEqualToString("length.valueAsString", referenceValue + "mm"); 110 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 111 shouldBeEqualToString("length.valueAsString.slice(-2)", "mm"); 110 112 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(6)", referenceValue); 111 113 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); … … 120 122 shouldBeUndefined("length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN)"); 121 123 referenceValue = Number(2 / cssPixelsPerInch).toFixed(7); 122 shouldBeEqualToString("length.valueAsString", referenceValue + "in"); 124 // Exact result of valueAsString depends on precision, no trivial way to correctly test it, especially across engines. 125 shouldBeEqualToString("length.valueAsString.slice(-2)", "in"); 123 126 shouldBeEqualToString("length.valueInSpecifiedUnits.toFixed(7)", referenceValue); 124 127 shouldBeEqualToString("length.value.toFixed(1)", "2.0"); -
trunk/Source/WTF/ChangeLog
r242356 r242360 1 2019-03-03 Darin Adler <darin@apple.com> 2 3 Prepare to improve handling of conversion of float to strings 4 https://bugs.webkit.org/show_bug.cgi?id=195262 5 6 Reviewed by Daniel Bates. 7 8 * wtf/dtoa.cpp: 9 (WTF::truncateTrailingZeros): Renamed from 10 formatStringTruncatingTrailingZerosIfNeeded and removed the calls 11 to double_conversion::StringBuilder::Finalizer, since the caller 12 already does that. 13 (WTF::numberToFixedPrecisionString): Added an overload for float 14 and updated to use the new truncateTrailingZeros. 15 (WTF::numberToFixedWidthString): Added an overload for float. 16 17 * wtf/text/AtomicString.cpp: 18 (WTF::AtomicString::number): Added float overload. This is a 19 behavior change, but in all cases for the better. The old behavior 20 was to convert to double first and then do "shortest form" 21 conversion, and it's always better to just do that as float. 22 * wtf/text/AtomicString.h: Added float overload of AtomicString::number. 23 24 * wtf/text/StringBuilder.cpp: 25 (WTF::StringBuilder::appendFixedPrecisionNumber): Added float 26 overload. 27 (WTF::StringBuilder::appendShortestFormNumber): Renamed from 28 appendECMAScriptNumber and did the above. 29 (WTF::StringBuilder::appendFixedWidthNumber): Ditto. 30 * wtf/text/StringBuilder.h: Added overloads for float and 31 appendShortestFormNumber. The appendNumber and appendECMAScriptNumber 32 functions are now inlines in the header, since they are expressed 33 entirely in terms of the other functions. 34 35 * wtf/text/WTFString.cpp: 36 (WTF::String::numberToStringFixedPrecision): Added float overload. 37 Removed unnecessary explicit conversion to String. 38 (WTF::String::numberToStringShortest): Renamed from 39 numberToStringECMAScript and did the above. 40 (WTF::String::numberToStringFixedWidth): Ditto. 41 42 * wtf/text/WTFString.h: Added overloads for float and 43 numberToStringShortest. The number and numberToStringECMAScript 44 functions are now inlines in the header, since they are expressed 45 entirely in terms of the other functions. 46 1 47 2019-03-04 Andy Estes <aestes@apple.com> 2 48 -
trunk/Source/WTF/wtf/dtoa.cpp
r242330 r242360 39 39 } 40 40 41 static inline const char* formatStringTruncatingTrailingZerosIfNeeded(NumberToStringBuffer& buffer, double_conversion::StringBuilder& builder)41 static inline void truncateTrailingZeros(NumberToStringBuffer& buffer, double_conversion::StringBuilder& builder) 42 42 { 43 43 size_t length = builder.position(); … … 50 50 // No decimal separator found, early exit. 51 51 if (decimalPointPosition == length) 52 return builder.Finalize();52 return; 53 53 54 54 size_t pastMantissa = decimalPointPosition + 1; … … 66 66 // No trailing zeros found to strip. 67 67 if (truncatedLength == pastMantissa) 68 return builder.Finalize();68 return; 69 69 70 70 // If we removed all trailing zeros, remove the decimal point as well. … … 74 74 // Truncate the mantissa, and return the final result. 75 75 builder.RemoveCharacters(truncatedLength, pastMantissa); 76 return builder.Finalize();77 76 } 78 77 79 const char* numberToFixedPrecisionString( double d, unsigned significantFigures, NumberToStringBuffer& buffer, bool truncateTrailingZeros)78 const char* numberToFixedPrecisionString(float number, unsigned significantFigures, NumberToStringBuffer& buffer, bool shouldTruncateTrailingZeros) 80 79 { 81 // Mimic sprintf("%.[precision]g", ...), but use dtoas rounding facilities. 80 // For now, just call the double precision version. 81 // Do that here instead of at callers to pave the way to add a more efficient code path later. 82 return numberToFixedPrecisionString(static_cast<double>(number), significantFigures, buffer, shouldTruncateTrailingZeros); 83 } 84 85 const char* numberToFixedPrecisionString(double d, unsigned significantFigures, NumberToStringBuffer& buffer, bool shouldTruncateTrailingZeros) 86 { 87 // Mimic sprintf("%.[precision]g", ...). 82 88 // "g": Signed value printed in f or e format, whichever is more compact for the given value and precision. 83 89 // The e format is used only when the exponent of the value is less than –4 or greater than or equal to the … … 87 93 auto& converter = double_conversion::DoubleToStringConverter::EcmaScriptConverter(); 88 94 converter.ToPrecision(d, significantFigures, &builder); 89 if (!truncateTrailingZeros) 90 return builder.Finalize(); 91 return formatStringTruncatingTrailingZerosIfNeeded(buffer, builder); 95 if (shouldTruncateTrailingZeros) 96 truncateTrailingZeros(buffer, builder); 97 return builder.Finalize(); 98 } 99 100 const char* numberToFixedWidthString(float number, unsigned decimalPlaces, NumberToStringBuffer& buffer) 101 { 102 // For now, just call the double precision version. 103 // Do that here instead of at callers to pave the way to add a more efficient code path later. 104 return numberToFixedWidthString(static_cast<double>(number), decimalPlaces, buffer); 92 105 } 93 106 94 107 const char* numberToFixedWidthString(double d, unsigned decimalPlaces, NumberToStringBuffer& buffer) 95 108 { 96 // Mimic sprintf("%.[precision]f", ...) , but use dtoas rounding facilities.109 // Mimic sprintf("%.[precision]f", ...). 97 110 // "f": Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits. 98 111 // The number of digits before the decimal point depends on the magnitude of the number, and -
trunk/Source/WTF/wtf/text/AtomicString.cpp
r237099 r242360 102 102 } 103 103 104 AtomicString AtomicString::number(float number) 105 { 106 NumberToStringBuffer buffer; 107 return numberToString(number, buffer); 108 } 109 104 110 AtomicString AtomicString::number(double number) 105 111 { -
trunk/Source/WTF/wtf/text/AtomicString.h
r237099 r242360 108 108 WTF_EXPORT_PRIVATE static AtomicString number(unsigned long); 109 109 WTF_EXPORT_PRIVATE static AtomicString number(unsigned long long); 110 WTF_EXPORT_PRIVATE static AtomicString number(float); 110 111 WTF_EXPORT_PRIVATE static AtomicString number(double); 111 112 // If we need more overloads of the number function, we can add all the others that String has, but these seem to do for now. -
trunk/Source/WTF/wtf/text/StringBuilder.cpp
r238143 r242360 379 379 } 380 380 381 void StringBuilder::appendNumber(unsigned intnumber)381 void StringBuilder::appendNumber(unsigned number) 382 382 { 383 383 numberToStringUnsigned<StringBuilder>(number, this); … … 404 404 } 405 405 406 void StringBuilder::appendNumber(double number, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy) 407 { 408 NumberToStringBuffer buffer; 409 append(numberToFixedPrecisionString(number, precision, buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros)); 410 } 411 412 void StringBuilder::appendECMAScriptNumber(double number) 406 void StringBuilder::appendFixedPrecisionNumber(float number, unsigned precision, TrailingZerosTruncatingPolicy policy) 407 { 408 NumberToStringBuffer buffer; 409 append(numberToFixedPrecisionString(number, precision, buffer, policy == TruncateTrailingZeros)); 410 } 411 412 void StringBuilder::appendFixedPrecisionNumber(double number, unsigned precision, TrailingZerosTruncatingPolicy policy) 413 { 414 NumberToStringBuffer buffer; 415 append(numberToFixedPrecisionString(number, precision, buffer, policy == TruncateTrailingZeros)); 416 } 417 418 void StringBuilder::appendShortestFormNumber(float number) 413 419 { 414 420 NumberToStringBuffer buffer; 415 421 append(numberToString(number, buffer)); 422 } 423 424 void StringBuilder::appendShortestFormNumber(double number) 425 { 426 NumberToStringBuffer buffer; 427 append(numberToString(number, buffer)); 428 } 429 430 void StringBuilder::appendFixedWidthNumber(float number, unsigned decimalPlaces) 431 { 432 NumberToStringBuffer buffer; 433 append(numberToFixedWidthString(number, decimalPlaces, buffer)); 416 434 } 417 435 -
trunk/Source/WTF/wtf/text/StringBuilder.h
r238143 r242360 217 217 218 218 WTF_EXPORT_PRIVATE void appendNumber(int); 219 WTF_EXPORT_PRIVATE void appendNumber(unsigned int);219 WTF_EXPORT_PRIVATE void appendNumber(unsigned); 220 220 WTF_EXPORT_PRIVATE void appendNumber(long); 221 221 WTF_EXPORT_PRIVATE void appendNumber(unsigned long); 222 222 WTF_EXPORT_PRIVATE void appendNumber(long long); 223 223 WTF_EXPORT_PRIVATE void appendNumber(unsigned long long); 224 WTF_EXPORT_PRIVATE void appendNumber(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 225 WTF_EXPORT_PRIVATE void appendECMAScriptNumber(double); 224 // FIXME: Change appendNumber to be appendShortestFormNumber instead of appendFixedPrecisionNumber. 225 void appendNumber(float); 226 void appendNumber(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 227 228 WTF_EXPORT_PRIVATE void appendShortestFormNumber(float); 229 WTF_EXPORT_PRIVATE void appendShortestFormNumber(double); 230 WTF_EXPORT_PRIVATE void appendFixedPrecisionNumber(float, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 231 WTF_EXPORT_PRIVATE void appendFixedPrecisionNumber(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 232 WTF_EXPORT_PRIVATE void appendFixedWidthNumber(float, unsigned decimalPlaces); 226 233 WTF_EXPORT_PRIVATE void appendFixedWidthNumber(double, unsigned decimalPlaces); 234 235 // FIXME: Delete in favor of the name appendShortestFormNumber or just appendNumber. 236 void appendECMAScriptNumber(float); 237 void appendECMAScriptNumber(double); 227 238 228 239 String toString() … … 383 394 } 384 395 396 inline void StringBuilder::appendNumber(float number) 397 { 398 appendFixedPrecisionNumber(number); 399 } 400 401 inline void StringBuilder::appendNumber(double number, unsigned precision, TrailingZerosTruncatingPolicy policy) 402 { 403 appendFixedPrecisionNumber(number, precision, policy); 404 } 405 406 inline void StringBuilder::appendECMAScriptNumber(float number) 407 { 408 // FIXME: This preserves existing behavior but is not what we want. 409 // In the future, this should either be a compilation error or call appendShortestFormNumber without converting to double. 410 appendShortestFormNumber(static_cast<double>(number)); 411 } 412 413 inline void StringBuilder::appendECMAScriptNumber(double number) 414 { 415 appendShortestFormNumber(number); 416 } 417 385 418 template <typename CharType> 386 419 bool equal(const StringBuilder& s, const CharType* buffer, unsigned length) -
trunk/Source/WTF/wtf/text/WTFString.cpp
r242308 r242360 455 455 } 456 456 457 String String::number(unsigned intnumber)457 String String::number(unsigned number) 458 458 { 459 459 return numberToStringUnsigned<String>(number); … … 480 480 } 481 481 482 String String::number (doublenumber, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy)482 String String::numberToStringFixedPrecision(float number, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy) 483 483 { 484 484 NumberToStringBuffer buffer; 485 return String(numberToFixedPrecisionString(number, precision, buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros));486 } 487 488 String String::numberToString ECMAScript(double number)485 return numberToFixedPrecisionString(number, precision, buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros); 486 } 487 488 String String::numberToStringFixedPrecision(double number, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy) 489 489 { 490 490 NumberToStringBuffer buffer; 491 return String(numberToString(number, buffer)); 491 return numberToFixedPrecisionString(number, precision, buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros); 492 } 493 494 String String::numberToStringShortest(float number) 495 { 496 NumberToStringBuffer buffer; 497 return numberToString(number, buffer); 498 } 499 500 String String::numberToStringShortest(double number) 501 { 502 NumberToStringBuffer buffer; 503 return numberToString(number, buffer); 492 504 } 493 505 … … 495 507 { 496 508 NumberToStringBuffer buffer; 497 return String(numberToFixedWidthString(number, decimalPlaces, buffer));509 return numberToFixedWidthString(number, decimalPlaces, buffer); 498 510 } 499 511 -
trunk/Source/WTF/wtf/text/WTFString.h
r242308 r242360 176 176 WTF_EXPORT_PRIVATE static String number(long long); 177 177 WTF_EXPORT_PRIVATE static String number(unsigned long long); 178 179 WTF_EXPORT_PRIVATE static String number(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 180 181 // Number to String conversion following the ECMAScript definition. 182 WTF_EXPORT_PRIVATE static String numberToStringECMAScript(double); 178 // FIXME: Change number to be numberToStringShortest instead of numberToStringFixedPrecision. 179 static String number(float); 180 static String number(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 181 182 WTF_EXPORT_PRIVATE static String numberToStringShortest(float); 183 WTF_EXPORT_PRIVATE static String numberToStringShortest(double); 184 WTF_EXPORT_PRIVATE static String numberToStringFixedPrecision(float, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 185 WTF_EXPORT_PRIVATE static String numberToStringFixedPrecision(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros); 186 WTF_EXPORT_PRIVATE static String numberToStringFixedWidth(float, unsigned decimalPlaces); 183 187 WTF_EXPORT_PRIVATE static String numberToStringFixedWidth(double, unsigned decimalPlaces); 188 189 // FIXME: Delete in favor of the name numberToStringShortest or just number. 190 static String numberToStringECMAScript(float); 191 static String numberToStringECMAScript(double); 184 192 185 193 // Find a single character or string, also with match function & latin1 forms. … … 629 637 { 630 638 return startsWithLettersIgnoringASCIICase(string.impl(), lowercaseLetters); 639 } 640 641 inline String String::number(float number) 642 { 643 return numberToStringFixedPrecision(number); 644 } 645 646 inline String String::number(double number, unsigned precision, TrailingZerosTruncatingPolicy policy) 647 { 648 return numberToStringFixedPrecision(number, precision, policy); 649 } 650 651 inline String String::numberToStringECMAScript(float number) 652 { 653 // FIXME: This preserves existing behavior but is not what we want. 654 // In the future, this should either be a compilation error or call numberToStringShortest without converting to double. 655 return numberToStringShortest(static_cast<double>(number)); 656 } 657 658 inline String String::numberToStringECMAScript(double number) 659 { 660 return numberToStringShortest(number); 631 661 } 632 662
Note:
See TracChangeset
for help on using the changeset viewer.