ICU-20439 Updating double-conversion.

This commit is contained in:
Shane F. Carr 2019-03-15 17:36:32 -07:00
parent e8b94b5cce
commit 6c86dc108d
21 changed files with 157 additions and 43 deletions

View File

@ -579,7 +579,7 @@ static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
// Returns true, when the iterator is equal to end.
template<class Iterator>
static bool Advance (Iterator* it, char separator, int base, Iterator& end) {
static bool Advance (Iterator* it, uc16 separator, int base, Iterator& end) {
if (separator == StringToDoubleConverter::kNoSeparator) {
++(*it);
return *it == end;
@ -607,7 +607,7 @@ static bool Advance (Iterator* it, char separator, int base, Iterator& end) {
template<class Iterator>
static bool IsHexFloatString(Iterator start,
Iterator end,
char separator,
uc16 separator,
bool allow_trailing_junk) {
ASSERT(start != end);
@ -648,7 +648,7 @@ template <int radix_log_2, class Iterator>
static double RadixStringToIeee(Iterator* current,
Iterator end,
bool sign,
char separator,
uc16 separator,
bool parse_as_hex_float,
bool allow_trailing_junk,
double junk_string_value,

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(double-conversion VERSION 3.1.1)
project(double-conversion VERSION 3.1.4)
set(headers
double-conversion/bignum.h

View File

@ -1,3 +1,25 @@
2019-03-11:
Use relative includes in the library. This shouldn't have any visible effect
for consumers of the library.
Update version number.
2019-03-06:
Fix typo in test.
Update version number.
2019-03-03:
Fix separator characters when they they don't fit into 8 bits.
Update version number.
2019-02-16:
Check correctly for _MSC_VER.
Patch by Ben Boeckel
2019-01-17:
Allow the library to be compiled for Emscripten.
Patch by Tim Paine.
2018-09-15:
Update version numbers. This also updates the shared-library version number.

View File

@ -27,10 +27,10 @@
#include <cmath>
#include <double-conversion/bignum-dtoa.h>
#include "bignum-dtoa.h"
#include <double-conversion/bignum.h>
#include <double-conversion/ieee.h>
#include "bignum.h"
#include "ieee.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_BIGNUM_DTOA_H_
#define DOUBLE_CONVERSION_BIGNUM_DTOA_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -25,8 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <double-conversion/bignum.h>
#include <double-conversion/utils.h>
#include "bignum.h"
#include "utils.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_BIGNUM_H_
#define DOUBLE_CONVERSION_BIGNUM_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -29,9 +29,9 @@
#include <cmath>
#include <cstdarg>
#include <double-conversion/utils.h>
#include "utils.h"
#include <double-conversion/cached-powers.h>
#include "cached-powers.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_CACHED_POWERS_H_
#define DOUBLE_CONVERSION_CACHED_POWERS_H_
#include <double-conversion/diy-fp.h>
#include "diy-fp.h"
namespace double_conversion {

View File

@ -26,8 +26,8 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <double-conversion/diy-fp.h>
#include <double-conversion/utils.h>
#include "diy-fp.h"
#include "utils.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_DIY_FP_H_
#define DOUBLE_CONVERSION_DIY_FP_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -29,14 +29,14 @@
#include <locale>
#include <cmath>
#include <double-conversion/double-conversion.h>
#include "double-conversion.h"
#include <double-conversion/bignum-dtoa.h>
#include <double-conversion/fast-dtoa.h>
#include <double-conversion/fixed-dtoa.h>
#include <double-conversion/ieee.h>
#include <double-conversion/strtod.h>
#include <double-conversion/utils.h>
#include "bignum-dtoa.h"
#include "fast-dtoa.h"
#include "fixed-dtoa.h"
#include "ieee.h"
#include "strtod.h"
#include "utils.h"
namespace double_conversion {
@ -553,7 +553,7 @@ static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
// Returns true, when the iterator is equal to end.
template<class Iterator>
static bool Advance (Iterator* it, char separator, int base, Iterator& end) {
static bool Advance (Iterator* it, uc16 separator, int base, Iterator& end) {
if (separator == StringToDoubleConverter::kNoSeparator) {
++(*it);
return *it == end;
@ -581,7 +581,7 @@ static bool Advance (Iterator* it, char separator, int base, Iterator& end) {
template<class Iterator>
static bool IsHexFloatString(Iterator start,
Iterator end,
char separator,
uc16 separator,
bool allow_trailing_junk) {
ASSERT(start != end);
@ -622,7 +622,7 @@ template <int radix_log_2, class Iterator>
static double RadixStringToIeee(Iterator* current,
Iterator end,
bool sign,
char separator,
uc16 separator,
bool parse_as_hex_float,
bool allow_trailing_junk,
double junk_string_value,

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
#define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -25,11 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <double-conversion/fast-dtoa.h>
#include "fast-dtoa.h"
#include <double-conversion/cached-powers.h>
#include <double-conversion/diy-fp.h>
#include <double-conversion/ieee.h>
#include "cached-powers.h"
#include "diy-fp.h"
#include "ieee.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_FAST_DTOA_H_
#define DOUBLE_CONVERSION_FAST_DTOA_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -27,8 +27,8 @@
#include <cmath>
#include <double-conversion/fixed-dtoa.h>
#include <double-conversion/ieee.h>
#include "fixed-dtoa.h"
#include "ieee.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_FIXED_DTOA_H_
#define DOUBLE_CONVERSION_FIXED_DTOA_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_DOUBLE_H_
#define DOUBLE_CONVERSION_DOUBLE_H_
#include <double-conversion/diy-fp.h>
#include "diy-fp.h"
namespace double_conversion {

View File

@ -28,10 +28,10 @@
#include <climits>
#include <cstdarg>
#include <double-conversion/bignum.h>
#include <double-conversion/cached-powers.h>
#include <double-conversion/ieee.h>
#include <double-conversion/strtod.h>
#include "bignum.h"
#include "cached-powers.h"
#include "ieee.h"
#include "strtod.h"
namespace double_conversion {

View File

@ -28,7 +28,7 @@
#ifndef DOUBLE_CONVERSION_STRTOD_H_
#define DOUBLE_CONVERSION_STRTOD_H_
#include <double-conversion/utils.h>
#include "utils.h"
namespace double_conversion {

View File

@ -1735,6 +1735,33 @@ static double StrToD16(const uc16* str16, int length, int flags,
}
static double StrToD16(const char* str, int flags,
double empty_string_value,
int* processed_characters_count, bool* processed_all,
char char_separator, uc16 separator) {
uc16 str16[256];
int length = -1;
for (int i = 0;; i++) {
if (str[i] == char_separator) {
str16[i] = separator;
} else {
str16[i] = str[i];
}
if (str[i] == '\0') {
length = i;
break;
}
}
ASSERT(length < 256);
StringToDoubleConverter converter(flags, empty_string_value, Double::NaN(),
NULL, NULL, separator);
double result =
converter.StringToDouble(str16, length, processed_characters_count);
*processed_all = (length == *processed_characters_count);
return result;
}
static double StrToD(const char* str, int flags, double empty_string_value,
int* processed_characters_count, bool* processed_all,
uc16 separator = StringToDoubleConverter::kNoSeparator) {
@ -3207,7 +3234,7 @@ TEST(StringToDoubleSeparator) {
int flags;
int processed;
bool all_used;
char separator;
uc16 separator;
separator = '\'';
flags = StringToDoubleConverter::NO_FLAGS;
@ -3518,6 +3545,71 @@ TEST(StringToDoubleSeparator) {
CHECK_EQ(Double::NaN(),
StrToD("0x0 3.p -0", flags, 0.0, &processed, &all_used));
CHECK_EQ(0, processed);
separator = 0x202F;
char char_separator = '@';
flags = StringToDoubleConverter::ALLOW_HEX |
StringToDoubleConverter::ALLOW_HEX_FLOATS |
StringToDoubleConverter::ALLOW_LEADING_SPACES |
StringToDoubleConverter::ALLOW_TRAILING_SPACES;
CHECK_EQ(18.0,
StrToD16("0x1@2", flags, 0.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
CHECK_EQ(0.0, StrToD16("0x0@0", flags, 1.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
CHECK_EQ(static_cast<double>(0x123456789),
StrToD16("0x1@2@3@4@5@6@7@8@9", flags, Double::NaN(),
&processed, &all_used, char_separator, separator));
CHECK(all_used);
CHECK_EQ(18.0, StrToD16(" 0x1@2 ", flags, 0.0,
&processed, &all_used, char_separator, separator));
CHECK(all_used);
CHECK_EQ(static_cast<double>(0xabcdef),
StrToD16("0xa@b@c@d@e@f", flags, 0.0,
&processed, &all_used, char_separator, separator));
CHECK(all_used);
CHECK_EQ(Double::NaN(),
StrToD16("0x@1@2", flags, 0.0,
&processed, &all_used, char_separator, separator));
CHECK_EQ(0, processed);
CHECK_EQ(Double::NaN(),
StrToD16("0@x0", flags, 1.0,
&processed, &all_used, char_separator, separator));
CHECK_EQ(0, processed);
CHECK_EQ(Double::NaN(),
StrToD16("0x1@2@@3@4@5@6@7@8@9", flags, Double::NaN(),
&processed, &all_used, char_separator, separator));
CHECK_EQ(0, processed);
CHECK_EQ(3.0,
StrToD16("0x0@3p0", flags, 0.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
CHECK_EQ(0.0,
StrToD16("0x.0@0p0", flags, 0.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
CHECK_EQ(3.0,
StrToD16("0x3.0@0p0", flags, 0.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
CHECK_EQ(3.0,
StrToD16("0x0@3.p0", flags, 0.0, &processed, &all_used,
char_separator, separator));
CHECK(all_used);
}
TEST(StringToDoubleSpecialValues) {