Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the C locale for non-Windows CharArrayFromFormatV() and StringFromFormat() #2004

Merged
merged 1 commit into from
Feb 25, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Source/Core/Common/StringUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@
#include <Windows.h>
#else
#include <iconv.h>
#include <locale.h>
#include <errno.h>
#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
bool AsciiToHex(const std::string& _szValue, u32& result)
{
Expand Down Expand Up @@ -77,7 +86,13 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
c_locale = _create_locale(LC_ALL, ".1252");
writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args);
#else
#if !defined(ANDROID)
locale_t previousLocale = uselocale(GetCLocale());
#endif
writtenCount = vsnprintf(out, outsize, format, args);
#if !defined(ANDROID)
uselocale(previousLocale);
#endif
#endif

if (writtenCount > 0 && writtenCount < outsize)
Expand Down Expand Up @@ -112,8 +127,14 @@ std::string StringFromFormatV(const char* format, va_list args)
std::string temp = buf;
delete[] buf;
#else
#if !defined(ANDROID)
locale_t previousLocale = uselocale(GetCLocale());
#endif
if (vasprintf(&buf, format, args) < 0)
ERROR_LOG(COMMON, "Unable to allocate memory for string");
#if !defined(ANDROID)
uselocale(previousLocale);
#endif

std::string temp = buf;
free(buf);
Expand Down