@@ -20,11 +20,11 @@ #include #include #include #include -#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) +#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) # include #endif #ifdef HAVE_XLOCALE_H # include #endif @@ -80,11 +80,11 @@ static struct { Class isa; } placeholder; -#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) +#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) static locale_t cLocale; #endif @interface OFString () - (size_t)of_getCString: (char *)cString @@ -625,11 +625,11 @@ if (self != [OFString class]) return; placeholder.isa = [OFStringPlaceholder class]; -#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) +#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif } @@ -2424,11 +2424,11 @@ if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; -#ifdef HAVE_STRTOF_L +#if defined(HAVE_STRTOF_L) || defined(HAVE_USELOCALE) const char *UTF8String = self.UTF8String; #else /* * If we have no strtof_l, we have no other choice but to replace "." * with the locale's decimal point. @@ -2440,12 +2440,16 @@ #endif char *endPtr = NULL; float value; errno = 0; -#ifdef HAVE_STRTOF_L +#if defined(HAVE_STRTOF_L) value = strtof_l(UTF8String, &endPtr, cLocale); +#elif defined(HAVE_USELOCALE) + locale_t previousLocale = uselocale(cLocale); + value = strtof(UTF8String, &endPtr); + uselocale(previousLocale); #else value = strtof(UTF8String, &endPtr); #endif if (value == HUGE_VALF && errno == ERANGE) @@ -2477,11 +2481,11 @@ if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; -#ifdef HAVE_STRTOD_L +#if defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE) const char *UTF8String = self.UTF8String; #else /* * If we have no strtod_l, we have no other choice but to replace "." * with the locale's decimal point. @@ -2493,12 +2497,16 @@ #endif char *endPtr = NULL; double value; errno = 0; -#ifdef HAVE_STRTOD_L +#if defined(HAVE_STRTOD_L) + value = strtod_l(UTF8String, &endPtr, cLocale); +#elif defined(HAVE_USELOCALE) + locale_t previousLocale = uselocale(cLocale); value = strtod_l(UTF8String, &endPtr, cLocale); + uselocale(previousLocale); #else value = strtod(UTF8String, &endPtr); #endif if (value == HUGE_VAL && errno == ERANGE)