win32: add AnsiToWide/WideToAnsi functions. This change is for Lua (non-Unicode DLL) and external modules (Lua-GD, for instance).

This commit is contained in:
gocha 2012-07-25 07:07:06 +09:00
parent 6fb8ae96b1
commit 1e2dd85321
3 changed files with 34 additions and 0 deletions

View File

@ -198,6 +198,18 @@ MS932ToWide::MS932ToWide(const char *ms932Chars) {
MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,requiredChars);
}
AnsiToWide::AnsiToWide(const char *ansiChars) {
int requiredChars = MultiByteToWideChar(CP_ACP,0,ansiChars,-1,wideChars,0);
wideChars = new wchar_t[requiredChars];
MultiByteToWideChar(CP_ACP,0,ansiChars,-1,wideChars,requiredChars);
}
WideToAnsi::WideToAnsi(const wchar_t *wideChars) {
int requiredChars = WideCharToMultiByte(CP_ACP,0,wideChars,-1,ansiChars,0,NULL,NULL);
ansiChars = new char[requiredChars];
WideCharToMultiByte(CP_ACP,0,wideChars,-1,ansiChars,requiredChars,NULL,NULL);
}
extern "C" FILE *_tfwopen(const char *filename, const char *mode ) {
wchar_t mode_w[30];
lstrcpyn(mode_w,Utf8ToWide(mode),29);

View File

@ -236,6 +236,24 @@ public:
operator wchar_t *() { return wideChars; }
};
class AnsiToWide {
private:
wchar_t *wideChars;
public:
AnsiToWide(const char *ansiChars);
~AnsiToWide() { delete [] wideChars; }
operator wchar_t *() { return wideChars; }
};
class WideToAnsi {
private:
char *ansiChars;
public:
WideToAnsi(const wchar_t *wideChars);
~WideToAnsi() { delete [] ansiChars; }
operator char *() { return ansiChars; }
};
namespace std {
class u8nifstream: public std::ifstream
{

View File

@ -218,10 +218,14 @@
#define _tToChar WideToUtf8
#define _tFromChar Utf8ToWide
#define _tFromMS932 MS932ToWide
#define _tToAnsi WideToAnsi
#define _tFromAnsi AnsiToWide
#else
#define _tToChar
#define _tFromChar
#define _tFromMS932
#define _tToAnsi
#define _tFromAnsi
#endif
/****************************************************************************/