mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-17 02:41:15 -03:00
Create an immortal C locale
This adds a function fish_c_locale() which returns an immortal locale_t corresponding to the C locale, and switches builtin_printf to use wcstod_l.
This commit is contained in:
@@ -271,19 +271,11 @@ template <>
|
||||
long double raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
|
||||
double val = wcstod(s, end);
|
||||
if (**end == L'\0') return val;
|
||||
|
||||
// The conversion using the user's locale failed. That may be due to the string not being a
|
||||
// valid floating point value. It could also be due to the locale using different separator
|
||||
// characters than the normal english convention. So try again by forcing the use of a locale
|
||||
// that employs the english convention for writing floating point numbers.
|
||||
//
|
||||
// TODO: switch to the wcstod_l() function to avoid changing the global locale.
|
||||
char *saved_locale = strdup(setlocale(LC_NUMERIC, NULL));
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
val = wcstod(s, end);
|
||||
setlocale(LC_NUMERIC, saved_locale);
|
||||
free(saved_locale);
|
||||
return val;
|
||||
return wcstod_l(s, end, fish_c_locale());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user