Skip to content

Commit

Permalink
Fixed Multi-byte conversions
Browse files Browse the repository at this point in the history
- Make sure the locale is set correctly (Linux doesn't default set it)
- And send correct size during w_char->char conversion
This means alternate languages with "emphasis" characters now work on
linux
  • Loading branch information
urkle committed Aug 16, 2010
1 parent 34a644a commit 7cec180
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions sources/impl/LowLevelSystemSDL.cpp
Expand Up @@ -51,6 +51,8 @@

#include "system/String.h"

#include <clocale>

extern int hplMain(const hpl::tString &asCommandLine);

#ifdef WIN32
Expand All @@ -62,6 +64,12 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLin
#else
int main(int argc, char *argv[])
{
if(!std::setlocale(LC_CTYPE, "")) {
fprintf(stderr, "Can't set the specified locale! Check LANG, LC_CTYPE, LC_ALL.\n");
return 1;
}


hpl::tString cmdline = "";
for (int i=1; i < argc; i++) {
if (cmdline.length()>0) {
Expand Down
8 changes: 4 additions & 4 deletions sources/system/String.cpp
Expand Up @@ -33,9 +33,9 @@ namespace hpl {
tWString cString::To16Char(const tString &asString)
{
tWString wsTemp;
size_t needed = mbstowcs(NULL,&asString[0],asString.length());
size_t needed = mbstowcs(NULL,&asString[0],0);
wsTemp.resize(needed);
mbstowcs(&wsTemp[0],&asString[0],asString.length());
mbstowcs(&wsTemp[0],&asString[0],needed);

return wsTemp;
}
Expand All @@ -45,9 +45,9 @@ namespace hpl {
tString cString::To8Char(const tWString &awsString)
{
tString sTemp;
size_t needed = wcstombs(NULL,&awsString[0],awsString.length());
size_t needed = wcstombs(NULL,&awsString[0],0);
sTemp.resize(needed);
wcstombs(&sTemp[0],&awsString[0],awsString.length());
wcstombs(&sTemp[0],&awsString[0],needed);

return sTemp;
}
Expand Down

0 comments on commit 7cec180

Please sign in to comment.