@@ -26,6 +26,7 @@ static const StringPtr FALSE_STR("false");
2626static const StringPtr INFINITY_STR (" Infinity" );
2727static const StringPtr NEGATIVE_INFINITY_STR (" -Infinity" );
2828static const StringPtr NAN_STR (" NaN" );
29+ static const StringPtr ZERO_STR (" 0" );
2930
3031template <typename T>
3132inline unsigned int value_intDigitCount (T v)
@@ -107,24 +108,6 @@ extern "C"
107108 return ret;
108109 }
109110
110- inline bool value_u16StringsEqual (std::u16string s1, std::u16string s2)
111- {
112- // TODO: Rewrite this
113- std::transform (s1.begin (), s1.end (), s1.begin (), ::tolower);
114- std::transform (s2.begin (), s2.end (), s2.begin (), ::tolower);
115- return (s1.compare (s2) == 0 );
116- }
117-
118- inline bool value_stringsEqual (const char *s1, const char *s2)
119- {
120- // TODO: Remove this?
121- std::string str1 (s1);
122- std::string str2 (s2);
123- std::transform (str1.begin (), str1.end (), str1.begin (), ::tolower);
124- std::transform (str2.begin (), str2.end (), str2.begin (), ::tolower);
125- return (str1.compare (str2) == 0 );
126- }
127-
128111 inline long value_hexToDec (const char16_t *s, int n, bool *ok)
129112 {
130113 if (ok)
@@ -349,12 +332,11 @@ extern "C"
349332 }
350333
351334 // Special values
352- // TODO: Use a custom comparison function
353- if (value_u16StringsEqual (std::u16string (s), utf8::utf8to16 (std::string (" Infinity" )))) {
335+ if (string_compare_raw_case_sensitive (s, n, INFINITY_STR.data , INFINITY_STR.size ) == 0 ) {
354336 if (ok)
355337 *ok = true ;
356338 return std::numeric_limits<double >::infinity ();
357- } else if (value_u16StringsEqual ( std::u16string (s), utf8::utf8to16 ( std::string ( " -Infinity " ))) ) {
339+ } else if (string_compare_raw_case_sensitive (s, n, NEGATIVE_INFINITY_STR. data , NEGATIVE_INFINITY_STR. size ) == 0 ) {
358340 if (ok)
359341 *ok = true ;
360342 return -std::numeric_limits<double >::infinity ();
@@ -500,12 +482,9 @@ extern "C"
500482 if (!ok) {
501483 // At least one argument can't be converted to a number
502484 // Scratch compares strings as case insensitive
503- // TODO: Use a custom comparison function
504485 StringPtr *s1 = value_toStringPtr (v1);
505486 StringPtr *s2 = value_toStringPtr (v2);
506- std::string str1 = utf8::utf16to8 (std::u16string (s1->data ));
507- std::string str2 = utf8::utf16to8 (std::u16string (s2->data ));
508- int ret = strcasecmp (str1.c_str (), str2.c_str ());
487+ int ret = string_compare_case_insensitive (s1, s2);
509488 string_pool_free (s1);
510489 string_pool_free (s2);
511490 return ret;
0 commit comments