Changeset 129165 in webkit


Ignore:
Timestamp:
Sep 20, 2012 2:03:56 PM (12 years ago)
Author:
Patrick Gansterer
Message:

Source/WebCore: Add String::numberToFixedPrecisionString()
https://bugs.webkit.org/show_bug.cgi?id=96330

Reviewed by Benjamin Poulain.

  • platform/text/TextStream.cpp:

(WebCore::TextStream::operator<<): Use the new function instead of String::number() with flags.

Source/WebKit2: Add String::numberToStringFixedWidth()
https://bugs.webkit.org/show_bug.cgi?id=96330

Reviewed by Benjamin Poulain.

  • win/WebKit2.def:
  • win/WebKit2CFLite.def:

Source/WTF: Add String::numberToStringFixedWidth()
https://bugs.webkit.org/show_bug.cgi?id=96330

Reviewed by Benjamin Poulain.

Add this new function as replacement for the ShouldRoundDecimalPlaces flag of String::number()
and remove the now unnecessary branch in String::number() for the old flags.

  • wtf/text/WTFString.cpp:

(WTF::String::number):
(WTF::String::numberToStringFixedWidth):

  • wtf/text/WTFString.h:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r129089 r129165  
     12012-09-20  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Add String::numberToStringFixedWidth()
     4        https://bugs.webkit.org/show_bug.cgi?id=96330
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Add this new function as replacement for the ShouldRoundDecimalPlaces flag of String::number()
     9        and remove the now unnecessary branch in String::number() for the old flags.
     10
     11        * wtf/text/WTFString.cpp:
     12        (WTF::String::number):
     13        (WTF::String::numberToStringFixedWidth):
     14        * wtf/text/WTFString.h:
     15
    1162012-09-19  Geoffrey Garen  <ggaren@apple.com>
    217
  • trunk/Source/WTF/wtf/text/WTFString.cpp

    r128908 r129165  
    451451}
    452452
    453 String String::number(double number, unsigned flags, unsigned precision)
     453String String::number(double number, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy)
    454454{
    455455    NumberToStringBuffer buffer;
    456 
    457     // Mimic String::format("%.[precision]g", ...), but use dtoas rounding facilities.
    458     if (flags & ShouldRoundSignificantFigures)
    459         return String(numberToFixedPrecisionString(number, precision, buffer, flags & ShouldTruncateTrailingZeros));
    460 
    461     // Mimic String::format("%.[precision]f", ...), but use dtoas rounding facilities.
    462     return String(numberToFixedWidthString(number, precision, buffer));
     456    return String(numberToFixedPrecisionString(number, precision, buffer, trailingZerosTruncatingPolicy == TruncateTrailingZeros));
    463457}
    464458
     
    467461    NumberToStringBuffer buffer;
    468462    return String(numberToString(number, buffer));
     463}
     464
     465String String::numberToStringFixedWidth(double number, unsigned decimalPlaces)
     466{
     467    NumberToStringBuffer buffer;
     468    return String(numberToFixedWidthString(number, decimalPlaces, buffer));
    469469}
    470470
  • trunk/Source/WTF/wtf/text/WTFString.h

    r128609 r129165  
    9898class ASCIILiteral;
    9999
    100 enum FloatConversionFlags {
    101     ShouldRoundSignificantFigures = 1 << 0,
    102     ShouldRoundDecimalPlaces = 1 << 1,
    103     ShouldTruncateTrailingZeros = 1 << 2
     100enum TrailingZerosTruncatingPolicy {
     101    KeepTrailingZeros,
     102    TruncateTrailingZeros
    104103};
    105104
     
    234233    WTF_EXPORT_STRING_API static String number(unsigned long long);
    235234
    236     WTF_EXPORT_STRING_API static String number(double, unsigned = ShouldRoundSignificantFigures | ShouldTruncateTrailingZeros, unsigned precision = 6);
     235    WTF_EXPORT_STRING_API static String number(double, unsigned precision = 6, TrailingZerosTruncatingPolicy = TruncateTrailingZeros);
    237236
    238237    // Number to String conversion following the ECMAScript definition.
    239238    WTF_EXPORT_STRING_API static String numberToStringECMAScript(double);
     239    WTF_EXPORT_STRING_API static String numberToStringFixedWidth(double, unsigned decimalPlaces);
    240240
    241241    // Find a single character or string, also with match function & latin1 forms.
     
    661661
    662662using WTF::CString;
     663using WTF::KeepTrailingZeros;
    663664using WTF::String;
    664665using WTF::emptyString;
     
    684685using WTF::isSpaceOrNewline;
    685686using WTF::reverseFind;
    686 using WTF::ShouldRoundDecimalPlaces;
    687687using WTF::ASCIILiteral;
    688688
  • trunk/Source/WebCore/ChangeLog

    r129164 r129165  
     12012-09-20  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Add String::numberToFixedPrecisionString()
     4        https://bugs.webkit.org/show_bug.cgi?id=96330
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * platform/text/TextStream.cpp:
     9        (WebCore::TextStream::operator<<): Use the new function instead of String::number() with flags.
     10
    1112012-09-20  Adam Klein  <adamk@chromium.org>
    212
  • trunk/Source/WebCore/platform/text/TextStream.cpp

    r128564 r129165  
    8888TextStream& TextStream::operator<<(float f)
    8989{
    90     m_text.append(String::number(f, ShouldRoundDecimalPlaces, 2));
     90    m_text.append(String::numberToStringFixedWidth(f, 2));
    9191    return *this;
    9292}
     
    9494TextStream& TextStream::operator<<(double d)
    9595{
    96     m_text.append(String::number(d, ShouldRoundDecimalPlaces, 2));
     96    m_text.append(String::numberToStringFixedWidth(d, 2));
    9797    return *this;
    9898}
  • trunk/Source/WebKit2/ChangeLog

    r129140 r129165  
     12012-09-20  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Add String::numberToStringFixedWidth()
     4        https://bugs.webkit.org/show_bug.cgi?id=96330
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * win/WebKit2.def:
     9        * win/WebKit2CFLite.def:
     10
    1112012-09-17  Jon Lee  <jonlee@apple.com>
    212
  • trunk/Source/WebKit2/win/WebKit2.def

    r128963 r129165  
    200200        ?number@String@WTF@@SA?AV12@H@Z
    201201        ?number@String@WTF@@SA?AV12@I@Z
    202         ?number@String@WTF@@SA?AV12@NII@Z
     202        ?number@String@WTF@@SA?AV12@NIW4TrailingZerosTruncatingPolicy@2@@Z
    203203        ?overrideUserPreferredLanguages@WebCore@@YAXABV?$Vector@VString@WTF@@$0A@@WTF@@@Z
    204204        ?numberOfScopedHTMLStyleChildren@Node@WebCore@@QBEIXZ
  • trunk/Source/WebKit2/win/WebKit2CFLite.def

    r128963 r129165  
    193193        ?number@String@WTF@@SA?AV12@H@Z
    194194        ?number@String@WTF@@SA?AV12@I@Z
    195         ?number@String@WTF@@SA?AV12@NII@Z
     195        ?number@String@WTF@@SA?AV12@NIW4TrailingZerosTruncatingPolicy@2@@Z
    196196        ?overrideUserPreferredLanguages@WebCore@@YAXABV?$Vector@VString@WTF@@$0A@@WTF@@@Z
    197197        ?numberOfScopedHTMLStyleChildren@Node@WebCore@@QBEIXZ
Note: See TracChangeset for help on using the changeset viewer.