OLD | NEW |
1 /**************************************************************** | 1 /**************************************************************** |
2 * | 2 * |
3 * The author of this software is David M. Gay. | 3 * The author of this software is David M. Gay. |
4 * | 4 * |
5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. | 5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. |
6 * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. | 6 * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. |
| 7 * All rights reserved. |
7 * | 8 * |
8 * Permission to use, copy, modify, and distribute this software for any | 9 * Permission to use, copy, modify, and distribute this software for any |
9 * purpose without fee is hereby granted, provided that this entire notice | 10 * purpose without fee is hereby granted, provided that this entire notice |
10 * is included in all copies of any software which is or includes a copy | 11 * is included in all copies of any software which is or includes a copy |
11 * or modification of this software and in all copies of the supporting | 12 * or modification of this software and in all copies of the supporting |
12 * documentation for such software. | 13 * documentation for such software. |
13 * | 14 * |
14 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED | 15 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED |
15 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY | 16 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY |
16 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY | 17 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 85 } |
85 | 86 |
86 // Truncate the StringBuilder, and return the final result. | 87 // Truncate the StringBuilder, and return the final result. |
87 builder.SetPosition(truncatedLength + 1); | 88 builder.SetPosition(truncatedLength + 1); |
88 return builder.Finalize(); | 89 return builder.Finalize(); |
89 } | 90 } |
90 | 91 |
91 const char* numberToFixedPrecisionString(double d, | 92 const char* numberToFixedPrecisionString(double d, |
92 unsigned significantFigures, | 93 unsigned significantFigures, |
93 NumberToStringBuffer buffer) { | 94 NumberToStringBuffer buffer) { |
94 // Mimic String::format("%.[precision]g", ...), but use dtoas rounding facilit
ies. | 95 // Mimic String::format("%.[precision]g", ...), but use dtoas rounding |
95 // "g": Signed value printed in f or e format, whichever is more compact for t
he given value and precision. | 96 // facilities. |
96 // The e format is used only when the exponent of the value is less than -4 or
greater than or equal to the | 97 // "g": Signed value printed in f or e format, whichever is more compact for |
97 // precision argument. Trailing zeros are truncated, and the decimal point app
ears only if one or more digits follow it. | 98 // the given value and precision. |
98 // "precision": The precision specifies the maximum number of significant digi
ts printed. | 99 // The e format is used only when the exponent of the value is less than -4 or |
| 100 // greater than or equal to the precision argument. Trailing zeros are |
| 101 // truncated, and the decimal point appears only if one or more digits follow |
| 102 // it. |
| 103 // "precision": The precision specifies the maximum number of significant |
| 104 // digits printed. |
99 double_conversion::StringBuilder builder(buffer, NumberToStringBufferLength); | 105 double_conversion::StringBuilder builder(buffer, NumberToStringBufferLength); |
100 const double_conversion::DoubleToStringConverter& converter = | 106 const double_conversion::DoubleToStringConverter& converter = |
101 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 107 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
102 converter.ToPrecision(d, significantFigures, &builder); | 108 converter.ToPrecision(d, significantFigures, &builder); |
103 // FIXME: Trailing zeros should never be added in the first place. The | 109 // FIXME: Trailing zeros should never be added in the first place. The |
104 // current implementation does not strip when there is an exponent, eg. | 110 // current implementation does not strip when there is an exponent, eg. |
105 // 1.50000e+10. | 111 // 1.50000e+10. |
106 return formatStringTruncatingTrailingZerosIfNeeded(buffer, builder); | 112 return formatStringTruncatingTrailingZerosIfNeeded(buffer, builder); |
107 } | 113 } |
108 | 114 |
109 const char* numberToFixedWidthString(double d, | 115 const char* numberToFixedWidthString(double d, |
110 unsigned decimalPlaces, | 116 unsigned decimalPlaces, |
111 NumberToStringBuffer buffer) { | 117 NumberToStringBuffer buffer) { |
112 // Mimic String::format("%.[precision]f", ...), but use dtoas rounding facilit
ies. | 118 // Mimic String::format("%.[precision]f", ...), but use dtoas rounding |
113 // "f": Signed value having the form [ - ]dddd.dddd, where dddd is one or more
decimal digits. | 119 // facilities. |
114 // The number of digits before the decimal point depends on the magnitude of t
he number, and | 120 // "f": Signed value having the form [ - ]dddd.dddd, where dddd is one or more |
115 // the number of digits after the decimal point depends on the requested preci
sion. | 121 // decimal digits. The number of digits before the decimal point depends on |
116 // "precision": The precision value specifies the number of digits after the d
ecimal point. | 122 // the magnitude of the number, and the number of digits after the decimal |
117 // If a decimal point appears, at least one digit appears before it. | 123 // point depends on the requested precision. |
118 // The value is rounded to the appropriate number of digits. | 124 // "precision": The precision value specifies the number of digits after the |
| 125 // decimal point. If a decimal point appears, at least one digit appears |
| 126 // before it. The value is rounded to the appropriate number of digits. |
119 double_conversion::StringBuilder builder(buffer, NumberToStringBufferLength); | 127 double_conversion::StringBuilder builder(buffer, NumberToStringBufferLength); |
120 const double_conversion::DoubleToStringConverter& converter = | 128 const double_conversion::DoubleToStringConverter& converter = |
121 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 129 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
122 converter.ToFixed(d, decimalPlaces, &builder); | 130 converter.ToFixed(d, decimalPlaces, &builder); |
123 return builder.Finalize(); | 131 return builder.Finalize(); |
124 } | 132 } |
125 | 133 |
126 namespace Internal { | 134 namespace Internal { |
127 | 135 |
128 double parseDoubleFromLongString(const UChar* string, | 136 double parseDoubleFromLongString(const UChar* string, |
129 size_t length, | 137 size_t length, |
130 size_t& parsedLength) { | 138 size_t& parsedLength) { |
131 Vector<LChar> conversionBuffer(length); | 139 Vector<LChar> conversionBuffer(length); |
132 for (size_t i = 0; i < length; ++i) | 140 for (size_t i = 0; i < length; ++i) |
133 conversionBuffer[i] = isASCII(string[i]) ? string[i] : 0; | 141 conversionBuffer[i] = isASCII(string[i]) ? string[i] : 0; |
134 return parseDouble(conversionBuffer.data(), length, parsedLength); | 142 return parseDouble(conversionBuffer.data(), length, parsedLength); |
135 } | 143 } |
136 | 144 |
137 } // namespace Internal | 145 } // namespace Internal |
138 | 146 |
139 } // namespace WTF | 147 } // namespace WTF |
OLD | NEW |