mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #2004 from randomstuff/stringutil-c-locale
Use the C locale for non-Windows CharArrayFromFormatV() and StringFromFormat()
This commit is contained in:
@ -22,9 +22,18 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_WIN32) && !defined(ANDROID)
|
||||||
|
static locale_t GetCLocale()
|
||||||
|
{
|
||||||
|
static locale_t c_locale = newlocale(LC_ALL_MASK, "C", NULL);
|
||||||
|
return c_locale;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// faster than sscanf
|
// faster than sscanf
|
||||||
bool AsciiToHex(const std::string& _szValue, u32& result)
|
bool AsciiToHex(const std::string& _szValue, u32& result)
|
||||||
{
|
{
|
||||||
@ -77,7 +86,13 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
|
|||||||
c_locale = _create_locale(LC_ALL, ".1252");
|
c_locale = _create_locale(LC_ALL, ".1252");
|
||||||
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
|
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
|
||||||
#else
|
#else
|
||||||
|
#if !defined(ANDROID)
|
||||||
|
locale_t previousLocale = uselocale(GetCLocale());
|
||||||
|
#endif
|
||||||
writtenCount = vsnprintf(out, outsize, format, args);
|
writtenCount = vsnprintf(out, outsize, format, args);
|
||||||
|
#if !defined(ANDROID)
|
||||||
|
uselocale(previousLocale);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (writtenCount > 0 && writtenCount < outsize)
|
if (writtenCount > 0 && writtenCount < outsize)
|
||||||
@ -112,8 +127,14 @@ std::string StringFromFormatV(const char* format, va_list args)
|
|||||||
std::string temp = buf;
|
std::string temp = buf;
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
#else
|
#else
|
||||||
|
#if !defined(ANDROID)
|
||||||
|
locale_t previousLocale = uselocale(GetCLocale());
|
||||||
|
#endif
|
||||||
if (vasprintf(&buf, format, args) < 0)
|
if (vasprintf(&buf, format, args) < 0)
|
||||||
ERROR_LOG(COMMON, "Unable to allocate memory for string");
|
ERROR_LOG(COMMON, "Unable to allocate memory for string");
|
||||||
|
#if !defined(ANDROID)
|
||||||
|
uselocale(previousLocale);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string temp = buf;
|
std::string temp = buf;
|
||||||
free(buf);
|
free(buf);
|
||||||
|
Reference in New Issue
Block a user