spaces fix

This commit is contained in:
Gergely Polonkai 2015-10-04 14:07:19 +02:00
parent 0e332f2709
commit 311bdf84bc
3 changed files with 82 additions and 82 deletions

View File

@ -18,15 +18,15 @@ Random rndGen;
static void initScreen() static void initScreen()
{ {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
throw Exception(std::wstring(L"Error initializing SDL: ") + throw Exception(std::wstring(L"Error initializing SDL: ") +
fromMbcs(SDL_GetError())); fromMbcs(SDL_GetError()));
atexit(SDL_Quit); atexit(SDL_Quit);
if (TTF_Init()) if (TTF_Init())
throw Exception(L"Error initializing font engine"); throw Exception(L"Error initializing font engine");
screen.setMode(VideoMode(800, 600, 24, screen.setMode(VideoMode(800, 600, 24,
getStorage()->get(L"fullscreen", 1) != 0)); getStorage()->get(L"fullscreen", 1) != 0));
screen.initCursors(); screen.initCursors();
SDL_Surface *mouse = loadImage(L"cursor.bmp"); SDL_Surface *mouse = loadImage(L"cursor.bmp");
SDL_SetColorKey(mouse, SDL_SRCCOLORKEY, SDL_MapRGB(mouse->format, 0, 0, 0)); SDL_SetColorKey(mouse, SDL_SRCCOLORKEY, SDL_MapRGB(mouse->format, 0, 0, 0));
screen.setMouseImage(mouse); screen.setMouseImage(mouse);
@ -51,7 +51,7 @@ static void initAudio()
static std::wstring getResourcesPath(const std::wstring& path) static std::wstring getResourcesPath(const std::wstring& path)
{ {
int idx = path.find_last_of(L'/'); int idx = path.find_last_of(L'/');
return path.substr(0, idx) + L"/../../"; return path.substr(0, idx) + L"/../../";
} }
#endif #endif
@ -59,7 +59,7 @@ static void loadResources(const std::wstring &selfPath)
{ {
StringList dirs; StringList dirs;
#ifdef WIN32 #ifdef WIN32
dirs.push_back(getStorage()->get(L"path", L"") + L"\\res"); dirs.push_back(getStorage()->get(L"path", L"") + L"\\res");
#else #else
#ifdef __APPLE__ #ifdef __APPLE__
dirs.push_back(getResourcesPath(selfPath)); dirs.push_back(getResourcesPath(selfPath));
@ -80,8 +80,8 @@ static void loadResources(const std::wstring &selfPath)
if (1124832535L + 60L*60L*24L*40L < time(NULL)) { if (1124832535L + 60L*60L*24L*40L < time(NULL)) {
Font font(L"laudcn2.ttf", 16); Font font(L"laudcn2.ttf", 16);
Area area; Area area;
showMessageWindow(&area, L"darkpattern.bmp", showMessageWindow(&area, L"darkpattern.bmp",
700, 100, &font, 255,255,255, 700, 100, &font, 255,255,255,
msg(L"expired")); msg(L"expired"));
} }
}*/ }*/
@ -93,7 +93,7 @@ int main(int argc, char *argv[])
#ifndef WIN32 #ifndef WIN32
ensureDirExists(fromMbcs(getenv("HOME")) + std::wstring(L"/.einstein")); ensureDirExists(fromMbcs(getenv("HOME")) + std::wstring(L"/.einstein"));
#endif #endif
try { try {
loadResources(fromUtf8(argv[0])); loadResources(fromUtf8(argv[0]));
initScreen(); initScreen();
@ -107,7 +107,6 @@ int main(int argc, char *argv[])
std::cerr << L"ERROR: Unknown exception" << std::endl; std::cerr << L"ERROR: Unknown exception" << std::endl;
} }
screen.doneCursors(); screen.doneCursors();
return 0; return 0;
} }

View File

@ -28,9 +28,9 @@ class UnpackedResourceStream: public ResourceStream
size_t size; size_t size;
long offset; long offset;
long pos; long pos;
public: public:
UnpackedResourceStream(std::ifstream &stream, long offset, UnpackedResourceStream(std::ifstream &stream, long offset,
size_t size); size_t size);
public: public:
@ -40,7 +40,7 @@ class UnpackedResourceStream: public ResourceStream
virtual long getPos() { return pos; }; virtual long getPos() { return pos; };
}; };
UnpackedResourceStream::UnpackedResourceStream(std::ifstream &s, UnpackedResourceStream::UnpackedResourceStream(std::ifstream &s,
long off, size_t sz): stream(s) long off, size_t sz): stream(s)
{ {
offset = off; offset = off;
@ -81,7 +81,7 @@ class MemoryResourceStream: public ResourceStream
size_t size; size_t size;
ResVariant *resource; ResVariant *resource;
long pos; long pos;
public: public:
MemoryResourceStream(ResVariant *resource); MemoryResourceStream(ResVariant *resource);
virtual ~MemoryResourceStream(); virtual ~MemoryResourceStream();
@ -140,15 +140,15 @@ ResourceFile::ResourceFile(const std::wstring &fileName, Buffer *buf):
buffer = new Buffer(); buffer = new Buffer();
ownBuffer = true; ownBuffer = true;
} }
stream.open(toMbcs(fileName).c_str(), std::ios::in | std::ios::binary); stream.open(toMbcs(fileName).c_str(), std::ios::in | std::ios::binary);
if (stream.fail()) if (stream.fail())
throw Exception(L"Error loading resource file '" + name + L"'"); throw Exception(L"Error loading resource file '" + name + L"'");
char sign[4]; char sign[4];
stream.read(sign, 4); stream.read(sign, 4);
int readed = stream.gcount(); int readed = stream.gcount();
if (stream.fail() || (readed != 4) || (sign[0] != 'C') || if (stream.fail() || (readed != 4) || (sign[0] != 'C') ||
(sign[1] != 'R') || (sign[2] != 'F') || sign[3]) (sign[1] != 'R') || (sign[2] != 'F') || sign[3])
throw Exception(L"Invalid resource file '" + name + L"'"); throw Exception(L"Invalid resource file '" + name + L"'");
@ -159,7 +159,7 @@ ResourceFile::ResourceFile(const std::wstring &fileName, Buffer *buf):
priority = readInt(stream); priority = readInt(stream);
readed += stream.gcount(); readed += stream.gcount();
if (stream.fail() || (readed != 12) || (major != 2) || (minor < 0)) if (stream.fail() || (readed != 12) || (major != 2) || (minor < 0))
throw Exception(L"Incompatible version of resource file '" + throw Exception(L"Incompatible version of resource file '" +
name + L"'"); name + L"'");
} }
@ -193,7 +193,7 @@ void ResourceFile::getDirectory(Directory &directory)
entry.group = readString(stream); entry.group = readString(stream);
directory.push_back(entry); directory.push_back(entry);
} }
if (stream.fail()) if (stream.fail())
throw Exception(L"Error reading " + name + L" directory"); throw Exception(L"Error reading " + name + L" directory");
} }
@ -202,29 +202,29 @@ void ResourceFile::getDirectory(Directory &directory)
void ResourceFile::unpack(char *in, int inSize, char *out, int outSize) void ResourceFile::unpack(char *in, int inSize, char *out, int outSize)
{ {
z_stream zs; z_stream zs;
memset(&zs, 0, sizeof(z_stream)); memset(&zs, 0, sizeof(z_stream));
zs.next_in = (Bytef*)in; zs.next_in = (Bytef*)in;
zs.avail_in = inSize; zs.avail_in = inSize;
zs.next_out = (Bytef*)out; zs.next_out = (Bytef*)out;
zs.avail_out = outSize; zs.avail_out = outSize;
if (inflateInit(&zs) != Z_OK) if (inflateInit(&zs) != Z_OK)
throw Exception(name + L": Error initializing inflate stream."); throw Exception(name + L": Error initializing inflate stream.");
if (inflate(&zs, Z_FINISH) != Z_STREAM_END) if (inflate(&zs, Z_FINISH) != Z_STREAM_END)
throw Exception(name + L": Error decompresing element."); throw Exception(name + L": Error decompresing element.");
if (inflateEnd(&zs) != Z_OK) if (inflateEnd(&zs) != Z_OK)
throw Exception(name + L": Error finishing decompresing."); throw Exception(name + L": Error finishing decompresing.");
} }
void ResourceFile::load(char *buf, long offset, long packedSize, void ResourceFile::load(char *buf, long offset, long packedSize,
long unpackedSize, int level) long unpackedSize, int level)
{ {
char *inBuf=NULL; char *inBuf=NULL;
try { try {
if (! level) { if (! level) {
stream.seekg(offset, std::ios::beg); stream.seekg(offset, std::ios::beg);
@ -250,7 +250,7 @@ void* ResourceFile::load(long offset, long packedSize, long unpackedSize,
int level) int level)
{ {
char *outBuf=NULL; char *outBuf=NULL;
try { try {
outBuf = (char*)malloc(unpackedSize); outBuf = (char*)malloc(unpackedSize);
if (! outBuf) if (! outBuf)
@ -278,7 +278,7 @@ void* ResourceFile::load(long offset, long packedSize, long unpackedSize,
SimpleResourceFile::SimpleResourceFile(const std::wstring &fileName, SimpleResourceFile::SimpleResourceFile(const std::wstring &fileName,
Buffer *buf): ResourceFile(fileName, buf) Buffer *buf): ResourceFile(fileName, buf)
{ {
Directory entries; Directory entries;
getDirectory(entries); getDirectory(entries);
for (Directory::iterator i = entries.begin(); i != entries.end(); i++) { for (Directory::iterator i = entries.begin(); i != entries.end(); i++) {
DirectoryEntry &e = *i; DirectoryEntry &e = *i;
@ -304,7 +304,7 @@ void SimpleResourceFile::load(const std::wstring &name, Buffer &outBuf)
if (i != directory.end()) { if (i != directory.end()) {
DirectoryEntry &e = (*i).second; DirectoryEntry &e = (*i).second;
outBuf.setSize(e.unpackedSize); outBuf.setSize(e.unpackedSize);
ResourceFile::load((char*)outBuf.getData(), e.offset, ResourceFile::load((char*)outBuf.getData(), e.offset,
e.packedSize, e.unpackedSize, e.level); e.packedSize, e.unpackedSize, e.level);
} else } else
throw Exception(L"Resource '" + name + L"' not found"); throw Exception(L"Resource '" + name + L"' not found");
@ -349,7 +349,7 @@ void* ResVariant::getRef()
memcpy(d, &self, sizeof(self)); memcpy(d, &self, sizeof(self));
data = d + sizeof(self); data = d + sizeof(self);
} }
refCnt++; refCnt++;
return data; return data;
} }
@ -389,7 +389,7 @@ void ResVariant::getData(Buffer &buffer)
{ {
buffer.setSize(unpackedSize); buffer.setSize(unpackedSize);
if (! refCnt) if (! refCnt)
file->load((char*)buffer.getData(), offset, packedSize, file->load((char*)buffer.getData(), offset, packedSize,
unpackedSize, level); unpackedSize, level);
else else
memcpy((char*)buffer.getData(), data, unpackedSize); memcpy((char*)buffer.getData(), data, unpackedSize);
@ -400,7 +400,7 @@ ResourceStream* ResVariant::createStream()
if (refCnt || level) if (refCnt || level)
return new MemoryResourceStream(this); return new MemoryResourceStream(this);
else else
return new UnpackedResourceStream(file->getStream(), offset, return new UnpackedResourceStream(file->getStream(), offset,
packedSize); packedSize);
} }
@ -429,7 +429,7 @@ class ScorePredicate
{ {
public: public:
int score; int score;
ScorePredicate(int sc) { score = sc; } ScorePredicate(int sc) { score = sc; }
bool operator() (const ResVariant *r) const { bool operator() (const ResVariant *r) const {
@ -452,7 +452,7 @@ void Resource::addVariant(ResourceFile *file, int i18nScore,
variants.push_back(new ResVariant(file, i18nScore, entry)); variants.push_back(new ResVariant(file, i18nScore, entry));
return; return;
} }
ScorePredicate p(i18nScore); ScorePredicate p(i18nScore);
Variants::iterator i = std::find_if(variants.begin(), variants.end(), p); Variants::iterator i = std::find_if(variants.begin(), variants.end(), p);
if (i != variants.end()) { if (i != variants.end()) {
@ -543,7 +543,7 @@ void ResourcesCollection::loadResourceFiles(StringList &directories)
while ((de = readdir(dir))) while ((de = readdir(dir)))
if (de->d_name[0] != '.') { if (de->d_name[0] != '.') {
std::wstring s(fromMbcs(de->d_name)); std::wstring s(fromMbcs(de->d_name));
if ((s.length() > 4) && if ((s.length() > 4) &&
(toLowerCase(s.substr(s.length() - 4)) == L".res")) (toLowerCase(s.substr(s.length() - 4)) == L".res"))
files.push_back(new ResourceFile(d + L"/" + s, &buffer)); files.push_back(new ResourceFile(d + L"/" + s, &buffer));
} }
@ -556,13 +556,13 @@ void ResourcesCollection::loadResourceFiles(StringList &directories)
void ResourcesCollection::processFiles() void ResourcesCollection::processFiles()
{ {
ResourceFile::Directory dir; ResourceFile::Directory dir;
for (std::vector<ResourceFile*>::iterator i = files.begin(); for (std::vector<ResourceFile*>::iterator i = files.begin();
i != files.end(); i++) i != files.end(); i++)
{ {
ResourceFile *file = *i; ResourceFile *file = *i;
file->getDirectory(dir); file->getDirectory(dir);
for (ResourceFile::Directory::iterator j = dir.begin(); for (ResourceFile::Directory::iterator j = dir.begin();
j != dir.end(); j++) j != dir.end(); j++)
{ {
ResourceFile::DirectoryEntry &de = *j; ResourceFile::DirectoryEntry &de = *j;
std::wstring name, ext, language, country; std::wstring name, ext, language, country;
@ -622,7 +622,7 @@ void ResourcesCollection::delRef(void *data)
v->delRef(data); v->delRef(data);
} }
void ResourcesCollection::forEachInGroup(const std::wstring &name, void ResourcesCollection::forEachInGroup(const std::wstring &name,
Visitor<Resource*> &visitor) Visitor<Resource*> &visitor)
{ {
if (groups.count(name) > 0) { if (groups.count(name) > 0) {
@ -671,4 +671,3 @@ void ResDataHolder::load(const std::wstring &name)
data = resources->getRef(name, s); data = resources->getRef(name, s);
size = (size_t)s; size = (size_t)s;
} }

View File

@ -87,7 +87,7 @@ const char * const g_utf8_skip = utf8_skip_data;
*/ */
static inline wchar_t static inline wchar_t
g_utf8_get_char_extended (const char *p, g_utf8_get_char_extended (const char *p,
size_t max_len) size_t max_len)
{ {
unsigned int i, len; unsigned int i, len;
wchar_t wc = (unsigned char) *p; wchar_t wc = (unsigned char) *p;
@ -129,7 +129,7 @@ g_utf8_get_char_extended (const char *p,
{ {
return (wchar_t)-1; return (wchar_t)-1;
} }
if (max_len >= 0 && len > max_len) if (max_len >= 0 && len > max_len)
{ {
for (i = 1; i < max_len; i++) for (i = 1; i < max_len; i++)
@ -143,7 +143,7 @@ g_utf8_get_char_extended (const char *p,
for (i = 1; i < len; ++i) for (i = 1; i < len; ++i)
{ {
wchar_t ch = ((unsigned char *)p)[i]; wchar_t ch = ((unsigned char *)p)[i];
if ((ch & 0xc0) != 0x80) if ((ch & 0xc0) != 0x80)
{ {
if (ch) if (ch)
@ -158,20 +158,20 @@ g_utf8_get_char_extended (const char *p,
if (UTF8_LENGTH(wc) != len) if (UTF8_LENGTH(wc) != len)
return (wchar_t)-1; return (wchar_t)-1;
return wc; return wc;
} }
/** /**
* g_utf8_get_char: * g_utf8_get_char:
* @p: a pointer to Unicode character encoded as UTF-8 * @p: a pointer to Unicode character encoded as UTF-8
* *
* Converts a sequence of bytes encoded as UTF-8 to a Unicode character. * Converts a sequence of bytes encoded as UTF-8 to a Unicode character.
* If @p does not point to a valid UTF-8 encoded character, results are * If @p does not point to a valid UTF-8 encoded character, results are
* undefined. If you are not sure that the bytes are complete * undefined. If you are not sure that the bytes are complete
* valid Unicode characters, you should use g_utf8_get_char_validated() * valid Unicode characters, you should use g_utf8_get_char_validated()
* instead. * instead.
* *
* Return value: the resulting character * Return value: the resulting character
**/ **/
wchar_t wchar_t
@ -202,7 +202,7 @@ g_utf8_get_char (const char *p)
* invalid input is stored here. * invalid input is stored here.
* @items_written: location to store number of characters written or %NULL. * @items_written: location to store number of characters written or %NULL.
* The value here stored does not include the trailing 0 * The value here stored does not include the trailing 0
* character. * character.
* @error: location to store the error occuring, or %NULL to ignore * @error: location to store the error occuring, or %NULL to ignore
* errors. Any of the errors in #GConvertError other than * errors. Any of the errors in #GConvertError other than
* %G_CONVERT_ERROR_NO_CONVERSION may occur. * %G_CONVERT_ERROR_NO_CONVERSION may occur.
@ -210,7 +210,7 @@ g_utf8_get_char (const char *p)
* Convert a string from UTF-8 to a 32-bit fixed width * Convert a string from UTF-8 to a 32-bit fixed width
* representation as UCS-4. A trailing 0 will be added to the * representation as UCS-4. A trailing 0 will be added to the
* string after the converted text. * string after the converted text.
* *
* Return value: a pointer to a newly allocated UCS-4 string. * Return value: a pointer to a newly allocated UCS-4 string.
* This value must be freed with g_free(). If an * This value must be freed with g_free(). If an
* error occurs, %NULL will be returned and * error occurs, %NULL will be returned and
@ -218,15 +218,15 @@ g_utf8_get_char (const char *p)
**/ **/
wchar_t * wchar_t *
g_utf8_to_ucs4 (const char *str, g_utf8_to_ucs4 (const char *str,
long len, long len,
long *items_read, long *items_read,
long *items_written, long *items_written,
wchar_t **error) const wchar_t **error)
{ {
wchar_t *result = NULL; wchar_t *result = NULL;
int n_chars, i; int n_chars, i;
const char *in; const char *in;
in = str; in = str;
n_chars = 0; n_chars = 0;
while ((len < 0 || str + len - in > 0) && *in) while ((len < 0 || str + len - in > 0) && *in)
@ -255,7 +255,7 @@ g_utf8_to_ucs4 (const char *str,
} }
result = (wchar_t*)malloc((n_chars + 1) * sizeof(wchar_t)); result = (wchar_t*)malloc((n_chars + 1) * sizeof(wchar_t));
in = str; in = str;
for (i=0; i < n_chars; i++) for (i=0; i < n_chars; i++)
{ {
@ -280,16 +280,16 @@ g_utf8_to_ucs4 (const char *str,
* @outbuf: output buffer, must have at least 6 bytes of space. * @outbuf: output buffer, must have at least 6 bytes of space.
* If %NULL, the length will be computed and returned * If %NULL, the length will be computed and returned
* and nothing will be written to @outbuf. * and nothing will be written to @outbuf.
* *
* Converts a single character to UTF-8. * Converts a single character to UTF-8.
* *
* Return value: number of bytes written * Return value: number of bytes written
**/ **/
int int
g_unichar_to_utf8 (wchar_t c, g_unichar_to_utf8 (wchar_t c,
char *outbuf) char *outbuf)
{ {
unsigned int len = 0; unsigned int len = 0;
int first; int first;
int i; int i;
@ -345,14 +345,14 @@ g_unichar_to_utf8 (wchar_t c,
* @items_read: location to store number of characters read read, or %NULL. * @items_read: location to store number of characters read read, or %NULL.
* @items_written: location to store number of bytes written or %NULL. * @items_written: location to store number of bytes written or %NULL.
* The value here stored does not include the trailing 0 * The value here stored does not include the trailing 0
* byte. * byte.
* @error: location to store the error occuring, or %NULL to ignore * @error: location to store the error occuring, or %NULL to ignore
* errors. Any of the errors in #GConvertError other than * errors. Any of the errors in #GConvertError other than
* %G_CONVERT_ERROR_NO_CONVERSION may occur. * %G_CONVERT_ERROR_NO_CONVERSION may occur.
* *
* Convert a string from a 32-bit fixed width representation as UCS-4. * Convert a string from a 32-bit fixed width representation as UCS-4.
* to UTF-8. The result will be terminated with a 0 byte. * to UTF-8. The result will be terminated with a 0 byte.
* *
* Return value: a pointer to a newly allocated UTF-8 string. * Return value: a pointer to a newly allocated UTF-8 string.
* This value must be freed with g_free(). If an * This value must be freed with g_free(). If an
* error occurs, %NULL will be returned and * error occurs, %NULL will be returned and
@ -360,10 +360,10 @@ g_unichar_to_utf8 (wchar_t c,
**/ **/
char * char *
g_ucs4_to_utf8 (const wchar_t *str, g_ucs4_to_utf8 (const wchar_t *str,
long len, long len,
long *items_read, long *items_read,
long *items_written, long *items_written,
wchar_t **error) const wchar_t **error)
{ {
int result_length; int result_length;
char *result = NULL; char *result = NULL;
@ -384,7 +384,7 @@ g_ucs4_to_utf8 (const wchar_t *str,
*error = L"Character out of range for UTF-8"; *error = L"Character out of range for UTF-8";
goto err_out; goto err_out;
} }
result_length += UTF8_LENGTH (str[i]); result_length += UTF8_LENGTH (str[i]);
} }
@ -394,7 +394,7 @@ g_ucs4_to_utf8 (const wchar_t *str,
i = 0; i = 0;
while (p < result + result_length) while (p < result + result_length)
p += g_unichar_to_utf8 (str[i++], p); p += g_unichar_to_utf8 (str[i++], p);
*p = '\0'; *p = '\0';
if (items_written) if (items_written)
@ -410,8 +410,8 @@ g_ucs4_to_utf8 (const wchar_t *str,
std::string toUtf8(const std::wstring &str) std::string toUtf8(const std::wstring &str)
{ {
long readed, writed; long readed, writed;
wchar_t *errMsg = NULL; const wchar_t *errMsg = NULL;
char *res = g_ucs4_to_utf8(str.c_str(), str.length(), &readed, char *res = g_ucs4_to_utf8(str.c_str(), str.length(), &readed,
&writed, &errMsg); &writed, &errMsg);
if (! res) { if (! res) {
@ -430,10 +430,9 @@ std::string toUtf8(const std::wstring &str)
std::wstring fromUtf8(const std::string &str) std::wstring fromUtf8(const std::string &str)
{ {
long readed, writed; long readed, writed;
wchar_t *errMsg = NULL; const wchar_t *errMsg = NULL;
wchar_t *res = g_utf8_to_ucs4(str.c_str(), str.length(), &readed, wchar_t *res = g_utf8_to_ucs4(str.c_str(), str.length(), &readed, &writed, &errMsg);
&writed, &errMsg);
if (! res) { if (! res) {
if (errMsg) if (errMsg)
throw Exception(errMsg); throw Exception(errMsg);
@ -443,7 +442,7 @@ std::wstring fromUtf8(const std::string &str)
std::wstring s(res); std::wstring s(res);
free(res); free(res);
return s; return s;
} }
@ -456,7 +455,7 @@ std::string toUtf8(const std::wstring &str)
{ {
if (! str.length()) if (! str.length())
return ""; return "";
int len = str.length(); int len = str.length();
int bufSize = (len + 1) * 6 + 1; int bufSize = (len + 1) * 6 + 1;
char buf[bufSize]; char buf[bufSize];
@ -472,11 +471,11 @@ std::wstring fromUtf8(const std::string &str)
{ {
if (! str.length()) if (! str.length())
return L""; return L"";
int len = str.length(); int len = str.length();
wchar_t buf[len + 1]; wchar_t buf[len + 1];
int res = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), len + 1, int res = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), len + 1,
buf, len + 1); buf, len + 1);
if (! res) if (! res)
throw Exception(L"Error converting UTF-8 to UCS-2"); throw Exception(L"Error converting UTF-8 to UCS-2");
@ -488,7 +487,7 @@ std::string toOem(const std::wstring &str)
{ {
if (! str.length()) if (! str.length())
return ""; return "";
int len = str.length(); int len = str.length();
int bufSize = (len + 1) * 6 + 1; int bufSize = (len + 1) * 6 + 1;
char buf[bufSize]; char buf[bufSize];
@ -504,11 +503,11 @@ std::wstring fromOem(const std::string &str)
{ {
if (! str.length()) if (! str.length())
return L""; return L"";
int len = str.length(); int len = str.length();
wchar_t buf[len + 1]; wchar_t buf[len + 1];
int res = MultiByteToWideChar(CP_OEMCP, 0, str.c_str(), len + 1, int res = MultiByteToWideChar(CP_OEMCP, 0, str.c_str(), len + 1,
buf, len + 1); buf, len + 1);
if (! res) if (! res)
throw Exception(L"Error converting OEM to UCS-2"); throw Exception(L"Error converting OEM to UCS-2");
@ -574,7 +573,7 @@ std::wstring fromMbcs(const std::string &str)
std::ostream& operator << (std::ostream &stream, const std::wstring &str) std::ostream& operator << (std::ostream &stream, const std::wstring &str)
{ {
#ifdef WIN32 #ifdef WIN32
if ((stream == std::cout) || (stream == std::cerr) || if ((stream == std::cout) || (stream == std::cerr) ||
(stream == std::clog)) (stream == std::clog))
stream << toOem(str); stream << toOem(str);
else else
@ -587,10 +586,13 @@ std::ostream& operator << (std::ostream &stream, const std::wstring &str)
int getUtf8Length(unsigned char c) int getUtf8Length(unsigned char c)
{ {
int mask, len; int mask, len;
UTF8_COMPUTE(c, mask, len); UTF8_COMPUTE(c, mask, len);
if (-1 == len)
if (-1 == len) {
throw Exception(L"Invalid utf-8 character"); throw Exception(L"Invalid utf-8 character");
else } else {
return len; return len;
}
} }