lib/icu/Win32: throw exception on error

This commit is contained in:
Max Kellermann
2016-04-13 11:51:01 +02:00
parent e228144159
commit b9f535cd49
6 changed files with 72 additions and 40 deletions

View File

@@ -30,6 +30,7 @@
#endif
#include <algorithm>
#include <stdexcept>
#include <assert.h>
#include <string.h>
@@ -100,11 +101,12 @@ PathToUTF8(PathTraitsFS::const_pointer_type path_fs)
#endif
#ifdef WIN32
const auto buffer = WideCharToMultiByte(CP_UTF8, path_fs);
if (buffer.IsNull())
try {
const auto buffer = WideCharToMultiByte(CP_UTF8, path_fs);
return FixSeparators(PathTraitsUTF8::string(buffer.c_str()));
} catch (const std::runtime_error &) {
return PathTraitsUTF8::string();
return FixSeparators(PathTraitsUTF8::string(buffer.c_str()));
}
#else
#ifdef HAVE_FS_CHARSET
if (fs_converter == nullptr)
@@ -132,11 +134,12 @@ PathFromUTF8(PathTraitsUTF8::const_pointer_type path_utf8)
#endif
#ifdef WIN32
const auto buffer = MultiByteToWideChar(CP_UTF8, path_utf8);
if (buffer.IsNull())
try {
const auto buffer = MultiByteToWideChar(CP_UTF8, path_utf8);
return PathTraitsFS::string(buffer.c_str());
} catch (const std::runtime_error &) {
return PathTraitsFS::string();
return PathTraitsFS::string(buffer.c_str());
}
#else
if (fs_converter == nullptr)
return path_utf8;