Skip to content

Commit

Permalink
Probably fixed problems with allocation/deallocation of std::locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY authored and q4a committed Oct 7, 2018
1 parent adc3448 commit ff133f2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/xrCore/Text/StringConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ u16 mbhMulti2Wide(wchar_t* WideStr, wchar_t* WidePos, u16 WideStrSize, const cha
return dpos;
}

xr_string StringFromUTF8(const char* in, const std::locale& locale /*= std::locale("")*/)
xr_string StringFromUTF8(const char* in, const std::locale& locale)
{
using wcvt = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
auto wstr = wcvt{}.from_bytes(in);
Expand All @@ -140,7 +140,7 @@ xr_string StringFromUTF8(const char* in, const std::locale& locale /*= std::loca
return result;
}

xr_string StringToUTF8(const char* in, const std::locale& locale /*= std::locale("")*/)
xr_string StringToUTF8(const char* in, const std::locale& locale)
{
using wcvt = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
std::wstring wstr(xr_strlen(in), L'\0');
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/Text/StringConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ IC bool IsAlphaCharacter(wchar_t wc)
((wc >= 0xFF21) && (wc <= 0xFF3A)) || ((wc >= 0xFF41) && (wc <= 0xFF5A)));
}

XRCORE_API xr_string StringFromUTF8(const char* string, const std::locale& locale = std::locale(""));
XRCORE_API xr_string StringToUTF8(const char* string, const std::locale& locale = std::locale(""));
XRCORE_API xr_string StringFromUTF8(const char* string, const std::locale& locale);
XRCORE_API xr_string StringToUTF8(const char* string, const std::locale& locale);
2 changes: 1 addition & 1 deletion src/xrEngine/edit_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void type_pair::on_key_press(line_edit_control* const control)
{
case SDL_TEXTINPUT:
{
const std::locale locale("");
static std::locale locale("");
auto str = StringFromUTF8(event.text.text, locale);

if (std::isalpha(str[0], locale) || str[0] == char(-1)) // "я" = -1
Expand Down
3 changes: 2 additions & 1 deletion src/xrEngine/xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ pcstr KeyToMouseButtonName(const int dik)
bool CInput::get_dik_name(int dik, LPSTR dest_str, int dest_sz)
{
xr_string keyname;
static std::locale locale("");

if (dik < SDL_NUM_SCANCODES)
keyname = StringFromUTF8(SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)dik)));
keyname = StringFromUTF8(SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)dik)), locale);
else
keyname = KeyToMouseButtonName(dik);

Expand Down

0 comments on commit ff133f2

Please sign in to comment.