static int do_strtod (char *buf, int sign, double *xp) { # if USE_STRTOD_L if (C_Locale != (locale_t) 0) { *xp = sign * strtod_l (buf, NULL, C_Locale); return 1; } C_Locale = newlocale (LC_ALL_MASK, "C", (locale_t) 0); if (C_Locale != (locale_t) 0) { *xp = sign * strtod_l (buf, NULL, C_Locale); return 1; } /* drop */ # endif # ifdef HAVE_STRTOD *xp = sign * strtod (buf, NULL); # else *xp = sign * atof (buf); # endif return 1; }
double ScCLocale::strtod ( const char * str, char ** endptr ) { if(NULL == that()->cLocale) { // a sade workaround double result(0.0); setlocale(LC_NUMERIC, "C"); result = std::strtod(str, endptr); setlocale(LC_NUMERIC, ""); return result; } else { #if defined(Q_WS_WIN) return _strtod_l(str, endptr, that()->cLocale); #else #if defined(Q_OS_SOLARIS) or defined (Q_OS_OPENBSD) or defined (Q_OS_FREEBSD) char *oldlocale=setlocale(LC_NUMERIC, NULL); double result(0.0); setlocale(LC_NUMERIC, "C"); result = std::strtod(str, endptr); setlocale(LC_NUMERIC, oldlocale); return result; #else return strtod_l(str, endptr, that()->cLocale); #endif #endif } }
PUBLIC double cs_strtod(char* nptr, char** endptr) { #ifdef HAVE_STRTOD_L return strtod_l(nptr, endptr, csound_c_locale); #else return strtod(nptr, endptr); #endif }
int safe_atod(const char *s, double *ret_d) { char *x = NULL; double d = 0; locale_t loc; assert(s); assert(ret_d); loc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); if (loc == (locale_t) 0) return -errno; errno = 0; d = strtod_l(s, &x, loc); if (errno > 0) { freelocale(loc); return -errno; } if (!x || x == s || *x) { freelocale(loc); return -EINVAL; } freelocale(loc); *ret_d = (double) d; return 0; }
FP_ATTRIB static double my_strtod(const char *nptr, char **endptr) { if (locale_inited == 0) { hybris_locale = newlocale(LC_ALL_MASK, "C", 0); locale_inited = 1; } return strtod_l(nptr, endptr, hybris_locale); }
/** * Wrapper around strtod which uses the "C" locale so the decimal * point is always '.' */ double _mesa_strtod(const char *s, char **end) { #if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H) return strtod_l(s, end, loc_init.loc); #else return strtod(s, end); #endif }
/** * Wrapper around strtod which uses the "C" locale so the decimal * point is always '.' */ double _mesa_strtod(const char *s, char **end) { #if defined(_GNU_SOURCE) && defined(HAVE_STRTOD_L) return strtod_l(s, end, loc); #else return strtod(s, end); #endif }
/** * Wrapper around strtod which uses the "C" locale so the decimal * point is always '.' */ double glsl_strtod(const char *s, char **end) { #if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) static locale_t loc = NULL; if (!loc) { loc = newlocale(LC_CTYPE_MASK, "C", NULL); } return strtod_l(s, end, loc); #else return strtod(s, end); #endif }
static int time_clock_to_frames( const char *s, double fps, locale_t locale ) { char *pos, *copy = strdup( s ); int hours = 0, minutes = 0; double seconds; s = copy; pos = strrchr( s, ':' ); if ( pos ) { #if defined(__GLIBC__) || defined(__DARWIN__) if ( locale ) seconds = strtod_l( pos + 1, NULL, locale ); else #endif seconds = strtod( pos + 1, NULL ); *pos = 0; pos = strrchr( s, ':' ); if ( pos ) { minutes = atoi( pos + 1 ); *pos = 0; hours = atoi( s ); } else { minutes = atoi( s ); } } else { #if defined(__GLIBC__) || defined(__DARWIN__) if ( locale ) seconds = strtod_l( s, NULL, locale ); else #endif seconds = strtod( s, NULL ); } free( copy ); return lrint( fps * ( (hours * 3600) + (minutes * 60) + seconds ) ); }
bool strtodC(const char *s, double *r) { char *err; #ifdef HAVE_LOCALE_T double val = strtod_l(s, &err, get_C_LC_NUMERIC()); #else /* dictionary_setup_locale() invokes setlocale(LC_NUMERIC, "C") */ double val = strtod(s, &err); #endif /* HAVE_LOCALE_T */ if ('\0' != *err) return false; /* *r unaffected */ *r = val; return true; }
U_CDECL_END double DigitList::decimalStrToDouble(char *decstr, char **end) { umtx_initOnce(gCLocaleInitOnce, &initCLocale); #if U_USE_STRTOD_L return strtod_l(decstr, end, gCLocale); #else char *decimalPt = strchr(decstr, '.'); if (decimalPt) { // We need to know the decimal separator character that will be used with strtod(). // Depends on the C runtime global locale. // Most commonly is '.' char rep[MAX_DIGITS]; sprintf(rep, "%+1.1f", 1.0); *decimalPt = rep[2]; } return uprv_strtod(decstr, end); #endif }
static int time_clock_to_frames( mlt_property self, const char *s, double fps/*, locale_t locale */) { char *pos, *copy = strdup( s ); int hours = 0, minutes = 0; double seconds; s = copy; pos = strrchr( s, ':' ); #if 0 #if !defined(__GLIBC__) && !defined(__DARWIN__) && !defined(ANDROID_XLOCALE) char *orig_localename = NULL; if ( locale ) { // Protect damaging the global locale from a temporary locale on another thread. pthread_mutex_lock( &self->mutex ); // Get the current locale orig_localename = strdup( setlocale( LC_NUMERIC, NULL ) ); // Set the new locale setlocale( LC_NUMERIC, locale ); } #endif #endif if ( pos ) { #if 0 #if defined(__GLIBC__) || defined(__DARWIN__) if ( locale ) seconds = strtod_l( pos + 1, NULL, locale ); else #endif #endif seconds = strtod( pos + 1, NULL ); *pos = 0; pos = strrchr( s, ':' ); if ( pos ) { minutes = atoi( pos + 1 ); *pos = 0; hours = atoi( s ); } else { minutes = atoi( s ); } } else { #if 0 #if defined(__GLIBC__) || defined(__DARWIN__) if ( locale ) seconds = strtod_l( s, NULL, locale ); else #endif #endif seconds = strtod( s, NULL ); } #if 0 #if !defined(__GLIBC__) && !defined(__DARWIN__) && !defined(ANDROID_XLOCALE) if ( locale ) { // Restore the current locale setlocale( LC_NUMERIC, orig_localename ); free( orig_localename ); pthread_mutex_unlock( &self->mutex ); } #endif #endif free( copy ); return lrint( fps * ( (hours * 3600) + (minutes * 60) + seconds ) ); }
JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr) { return strtod_l(nptr, endptr, get_c_locale()); }
bool StringConverter::parse(const String& val, double& ret) { char* end; ret = strtod_l(val.c_str(), &end, _numLocale); return val.c_str() != end; }
SOL_API double sol_util_strtod_n(const char *nptr, char **endptr, ssize_t len, bool use_locale) { char *tmpbuf, *tmpbuf_endptr; double value; #if defined(HAVE_NEWLOCALE) && defined(HAVE_STRTOD_L) if (!use_locale) { if (!init_c_locale()) { /* not great, but a best effort to convert something */ use_locale = false; SOL_WRN("could not create locale 'C', use current locale."); } } #endif if (len < 0) len = (ssize_t)strlen(nptr); if (SOL_UNLIKELY(len > (DBL_MANT_DIG - DBL_MIN_EXP + 3))) { errno = EINVAL; return FP_NAN; } /* NOTE: Using a copy to ensure trailing \0 and strtod() so we * properly parse numbers with large precision. * * Since parsing it is complex (ie: * http://www.netlib.org/fp/dtoa.c), we take the short path to * call libc. */ tmpbuf = strndupa(nptr, len); errno = 0; #ifdef HAVE_NEWLOCALE if (!use_locale) { #ifdef HAVE_STRTOD_L value = strtod_l(tmpbuf, &tmpbuf_endptr, c_locale); #else /* fallback to query locale's decimal point and if it's * different than '.' we replace JSON's '.' with locale's * decimal point if the given number contains a '.'. * * We also replace any existing locale decimal_point with '.' * so it will return correct endptr. * * Extra care since decimal point may be multi-byte. */ struct lconv *lc = localeconv(); if (lc && lc->decimal_point && !streq(lc->decimal_point, ".")) { if (strchr(tmpbuf, '.') || strstr(tmpbuf, lc->decimal_point)) { int dplen = strlen(lc->decimal_point); const char *src, *src_end = tmpbuf + len; char *dst; if (dplen == 1) { for (src = tmpbuf, dst = tmpbuf; src < src_end; src++, dst++) { if (*src == '.') *dst = *lc->decimal_point; else if (*src == *lc->decimal_point) *dst = '.'; } } else { char *transl; unsigned count = 0; for (src = tmpbuf; src < src_end; src++) { if (*src == '.') count++; } transl = alloca(len + (count * dplen) + 1); for (src = tmpbuf, dst = transl; src < src_end;) { if (*src == '.') { memcpy(dst, lc->decimal_point, dplen); dst += dplen; src++; } else if ((src_end - src) >= dplen && streqn(src, lc->decimal_point, dplen)) { *dst = '.'; dst++; src += dplen; } else { *dst = *src; dst++; src++; } } *dst = '\0'; tmpbuf = transl; } } } value = strtod(tmpbuf, &tmpbuf_endptr); #endif } else #endif { value = strtod(tmpbuf, &tmpbuf_endptr); } if (endptr) *endptr = (char *)nptr + (tmpbuf_endptr - tmpbuf); return value; }
void ModelicaStrings_scanReal(_In_z_ const char* string, int startIndex, int unsignedNumber, _Out_ int* nextIndex, _Out_ double* number) { /* Grammar of real number: real ::= [sign] unsigned [fraction] [exponent] sign ::= '+' | '-' unsigned ::= digit [unsigned] fraction ::= '.' [unsigned] exponent ::= ('e' | 'E') [sign] unsigned digit ::= '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' */ int len = 0; /* Temporary variable for the length of a matched unsigned number. */ int total_length = 0; /* Total number of characters recognized as part of a decimal number. */ int token_start = ModelicaStrings_skipWhiteSpace(string, startIndex); /* Index of first char of token, after ws. */ int exp_len = 0; /* Total number of characters recognized as part of the non-numeric parts * of exponent (the 'e' and the sign). */ /* Scan sign of decimal number */ if (string[token_start-1] == '+' || string[token_start-1] == '-') { total_length = 1; if (unsignedNumber == 1) { goto Modelica_ERROR; } } /* Scan integer part of mantissa. */ len = MatchUnsignedInteger(string, token_start + total_length); total_length += len; /* Scan decimal part of mantissa. */ if (string[token_start + total_length-1] == '.') { total_length += 1; len = MatchUnsignedInteger(string, token_start + total_length); if (len > 0) { total_length += len; } } /* Scan exponent part of mantissa. */ if (string[token_start + total_length-1] == 'e' || string[token_start + total_length-1] == 'E') { /* total_length += 1; */ exp_len = 1; if (string[token_start + total_length] == '+' || string[token_start + total_length] == '-') { exp_len += 1; } len = MatchUnsignedInteger(string, token_start + total_length + exp_len); if (len == 0) { goto Modelica_ERROR; } total_length += exp_len + len; } /* Convert accumulated characters into a number. */ if (total_length > 0 && total_length < MAX_TOKEN_SIZE) { #if defined(NO_LOCALE) const char* const dec = "."; #elif defined(_MSC_VER) && _MSC_VER >= 1400 _locale_t loc = _create_locale(LC_NUMERIC, "C"); #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3) locale_t loc = newlocale(LC_NUMERIC, "C", NULL); #else char* dec = localeconv()->decimal_point; #endif char buf[MAX_TOKEN_SIZE+1]; /* Buffer for copying the part recognized as the number for passing to strtod(). */ char* endptr; /* For error checking of strtod(). */ double x; /* For receiving the result. */ strncpy(buf, string+token_start-1, (size_t)total_length); buf[total_length] = '\0'; #if !defined(NO_LOCALE) && (defined(_MSC_VER) && _MSC_VER >= 1400) x = _strtod_l(buf, &endptr, loc); _free_locale(loc); #elif !defined(NO_LOCALE) && (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= (2 << 16) + 3)) x = strtod_l(buf, &endptr, loc); freelocale(loc); #else if (*dec == '.') { x = strtod(buf, &endptr); } else if (NULL == strchr(buf, '.')) { x = strtod(buf, &endptr); } else { char* p = strchr(buf, '.'); *p = *dec; x = strtod(buf, &endptr); } #endif if (*endptr == 0) { *number = x; *nextIndex = token_start + total_length; return; } } /* Token missing or cannot be converted to result type. */ Modelica_ERROR: *nextIndex = startIndex; *number = 0; return; }
double strtod_c(const char *nptr, char **endptr) { return strtod_l(nptr, endptr, get_c_locale()); }
int soap_s2xsd__duration(struct soap *soap, const char *s, LONG64 *a) { LONG64 sign = 1, Y = 0, M = 0, D = 0, H = 0, N = 0, S = 0; float f = 0; *a = 0; if (s) { if (*s == '-') { sign = -1; s++; } if (*s != 'P' && *s != 'p') return soap->error = SOAP_TYPE; s++; /* date part */ while (s && *s) { char *r = NULL; LONG64 n; if (*s == 'T' || *s == 't') { s++; break; } n = soap_strtol(s, &r, 10); if (!r) return soap->error = SOAP_TYPE; s = r; switch (*s) { case 'Y': case 'y': Y = n; break; case 'M': case 'm': M = n; break; case 'D': case 'd': D = n; break; default: return soap->error = SOAP_TYPE; } s++; } /* time part */ while (s && *s) { char *r = NULL; LONG64 n; n = soap_strtol(s, &r, 10); if (!r) return soap->error = SOAP_TYPE; s = r; switch (*s) { case 'H': case 'h': H = n; break; case 'M': case 'm': N = n; break; case '.': S = n; #if defined(WITH_C_LOCALE) && defined(HAVE_STRTOD_L) # ifdef WIN32 f = (float)_strtod_l(s, NULL, SOAP_LOCALE(soap)); # else f = (float)strtod_l(s, NULL, SOAP_LOCALE(soap)); # endif #elif defined(HAVE_STRTOD) f = (float)strtod(s, NULL); #elif defined(WITH_C_LOCALE) && defined(HAVE_STRTOF_L) f = strtof_l((char*)s, NULL, SOAP_LOCALE(soap)); #elif defined(HAVE_STRTOF) f = strtof((char*)s, NULL); #endif s = NULL; continue; case 'S': case 's': S = n; break; default: return soap->error = SOAP_TYPE; } s++; } /* convert Y-M-D H:N:S.f to signed long long int milliseconds */ *a = sign * ((((((((((((Y * 12) + M) * 30) + D) * 24) + H) * 60) + N) * 60) + S) * 1000) + (LONG64)(1000.0 * f + 0.5)); } return soap->error; }