| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2008, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2008, 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "wtf/text/Unicode.h" | 27 #include "wtf/text/Unicode.h" |
| 28 | 28 |
| 29 namespace WTF { | 29 namespace WTF { |
| 30 | 30 |
| 31 class Mutex; | 31 class Mutex; |
| 32 | 32 |
| 33 extern Mutex* s_dtoaP5Mutex; | 33 extern Mutex* s_dtoaP5Mutex; |
| 34 | 34 |
| 35 typedef char DtoaBuffer[80]; | 35 typedef char DtoaBuffer[80]; |
| 36 | 36 |
| 37 WTF_EXPORT void dtoa(DtoaBuffer result, double dd, bool& sign, int& exponent, un
signed& precision); | 37 WTF_EXPORT void dtoa(DtoaBuffer result, |
| 38 WTF_EXPORT void dtoaRoundSF(DtoaBuffer result, double dd, int ndigits, bool& sig
n, int& exponent, unsigned& precision); | 38 double dd, |
| 39 WTF_EXPORT void dtoaRoundDP(DtoaBuffer result, double dd, int ndigits, bool& sig
n, int& exponent, unsigned& precision); | 39 bool& sign, |
| 40 int& exponent, |
| 41 unsigned& precision); |
| 42 WTF_EXPORT void dtoaRoundSF(DtoaBuffer result, |
| 43 double dd, |
| 44 int ndigits, |
| 45 bool& sign, |
| 46 int& exponent, |
| 47 unsigned& precision); |
| 48 WTF_EXPORT void dtoaRoundDP(DtoaBuffer result, |
| 49 double dd, |
| 50 int ndigits, |
| 51 bool& sign, |
| 52 int& exponent, |
| 53 unsigned& precision); |
| 40 | 54 |
| 41 // Size = 80 for sizeof(DtoaBuffer) + some sign bits, decimal point, 'e', expone
nt digits. | 55 // Size = 80 for sizeof(DtoaBuffer) + some sign bits, decimal point, 'e', expone
nt digits. |
| 42 const unsigned NumberToStringBufferLength = 96; | 56 const unsigned NumberToStringBufferLength = 96; |
| 43 typedef char NumberToStringBuffer[NumberToStringBufferLength]; | 57 typedef char NumberToStringBuffer[NumberToStringBufferLength]; |
| 44 typedef LChar NumberToLStringBuffer[NumberToStringBufferLength]; | 58 typedef LChar NumberToLStringBuffer[NumberToStringBufferLength]; |
| 45 | 59 |
| 46 WTF_EXPORT const char* numberToString(double, NumberToStringBuffer); | 60 WTF_EXPORT const char* numberToString(double, NumberToStringBuffer); |
| 47 WTF_EXPORT const char* numberToFixedPrecisionString(double, unsigned significant
Figures, NumberToStringBuffer, bool truncateTrailingZeros = false); | 61 WTF_EXPORT const char* numberToFixedPrecisionString( |
| 48 WTF_EXPORT const char* numberToFixedWidthString(double, unsigned decimalPlaces,
NumberToStringBuffer); | 62 double, |
| 63 unsigned significantFigures, |
| 64 NumberToStringBuffer, |
| 65 bool truncateTrailingZeros = false); |
| 66 WTF_EXPORT const char* numberToFixedWidthString(double, |
| 67 unsigned decimalPlaces, |
| 68 NumberToStringBuffer); |
| 49 | 69 |
| 50 WTF_EXPORT double parseDouble(const LChar* string, size_t length, size_t& parsed
Length); | 70 WTF_EXPORT double parseDouble(const LChar* string, |
| 51 WTF_EXPORT double parseDouble(const UChar* string, size_t length, size_t& parsed
Length); | 71 size_t length, |
| 72 size_t& parsedLength); |
| 73 WTF_EXPORT double parseDouble(const UChar* string, |
| 74 size_t length, |
| 75 size_t& parsedLength); |
| 52 | 76 |
| 53 namespace Internal { | 77 namespace Internal { |
| 54 double parseDoubleFromLongString(const UChar* string, size_t length, size_t&
parsedLength); | 78 double parseDoubleFromLongString(const UChar* string, |
| 79 size_t length, |
| 80 size_t& parsedLength); |
| 55 } | 81 } |
| 56 | 82 |
| 57 inline double parseDouble(const LChar* string, size_t length, size_t& parsedLeng
th) | 83 inline double parseDouble(const LChar* string, |
| 58 { | 84 size_t length, |
| 59 return double_conversion::StringToDoubleConverter::StringToDouble(reinterpre
t_cast<const char*>(string), length, &parsedLength); | 85 size_t& parsedLength) { |
| 86 return double_conversion::StringToDoubleConverter::StringToDouble( |
| 87 reinterpret_cast<const char*>(string), length, &parsedLength); |
| 60 } | 88 } |
| 61 | 89 |
| 62 inline double parseDouble(const UChar* string, size_t length, size_t& parsedLeng
th) | 90 inline double parseDouble(const UChar* string, |
| 63 { | 91 size_t length, |
| 64 const size_t conversionBufferSize = 64; | 92 size_t& parsedLength) { |
| 65 if (length > conversionBufferSize) | 93 const size_t conversionBufferSize = 64; |
| 66 return Internal::parseDoubleFromLongString(string, length, parsedLength)
; | 94 if (length > conversionBufferSize) |
| 67 LChar conversionBuffer[conversionBufferSize]; | 95 return Internal::parseDoubleFromLongString(string, length, parsedLength); |
| 68 for (size_t i = 0; i < length; ++i) | 96 LChar conversionBuffer[conversionBufferSize]; |
| 69 conversionBuffer[i] = isASCII(string[i]) ? static_cast<LChar>(string[i])
: 0; | 97 for (size_t i = 0; i < length; ++i) |
| 70 return parseDouble(conversionBuffer, length, parsedLength); | 98 conversionBuffer[i] = |
| 99 isASCII(string[i]) ? static_cast<LChar>(string[i]) : 0; |
| 100 return parseDouble(conversionBuffer, length, parsedLength); |
| 71 } | 101 } |
| 72 | 102 |
| 73 } // namespace WTF | 103 } // namespace WTF |
| 74 | 104 |
| 75 using WTF::NumberToStringBuffer; | 105 using WTF::NumberToStringBuffer; |
| 76 using WTF::NumberToLStringBuffer; | 106 using WTF::NumberToLStringBuffer; |
| 77 using WTF::numberToString; | 107 using WTF::numberToString; |
| 78 using WTF::numberToFixedPrecisionString; | 108 using WTF::numberToFixedPrecisionString; |
| 79 using WTF::numberToFixedWidthString; | 109 using WTF::numberToFixedWidthString; |
| 80 using WTF::parseDouble; | 110 using WTF::parseDouble; |
| 81 | 111 |
| 82 #endif // WTF_dtoa_h | 112 #endif // WTF_dtoa_h |
| OLD | NEW |