|
@@ -97,95 +97,99 @@ namespace aria2 {
|
|
|
|
|
|
#ifdef __MINGW32__
|
|
|
namespace {
|
|
|
-int utf8ToWChar(wchar_t* out, size_t outLength, const std::string& src)
|
|
|
+int utf8ToWChar(wchar_t* out, size_t outLength, const char* src)
|
|
|
{
|
|
|
- return MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1,
|
|
|
- out, outLength);
|
|
|
+ return MultiByteToWideChar(CP_UTF8, 0, src, -1, out, outLength);
|
|
|
}
|
|
|
} // namespace
|
|
|
|
|
|
namespace {
|
|
|
-int ansiToWChar(wchar_t* out, size_t outLength, const std::string& src)
|
|
|
+int ansiToWChar(wchar_t* out, size_t outLength, const char* src)
|
|
|
{
|
|
|
- return MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1,
|
|
|
- out, outLength);
|
|
|
+ return MultiByteToWideChar(CP_ACP, 0, src, -1, out, outLength);
|
|
|
}
|
|
|
} // namespace
|
|
|
|
|
|
namespace {
|
|
|
-int wCharToUtf8(char* out, size_t outLength, const std::wstring& src)
|
|
|
+int wCharToUtf8(char* out, size_t outLength, const wchar_t* src)
|
|
|
{
|
|
|
- return WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1,
|
|
|
- out, outLength, 0, 0);
|
|
|
+ return WideCharToMultiByte(CP_UTF8, 0, src, -1, out, outLength, 0, 0);
|
|
|
}
|
|
|
} // namespace
|
|
|
|
|
|
namespace {
|
|
|
-int wCharToAnsi(char* out, size_t outLength, const std::wstring& src)
|
|
|
+int wCharToAnsi(char* out, size_t outLength, const wchar_t* src)
|
|
|
{
|
|
|
- return WideCharToMultiByte(CP_ACP, 0, src.c_str(), -1,
|
|
|
- out, outLength, 0, 0);
|
|
|
+ return WideCharToMultiByte(CP_ACP, 0, src, -1, out, outLength, 0, 0);
|
|
|
}
|
|
|
} // namespace
|
|
|
|
|
|
-std::wstring utf8ToWChar(const std::string& src)
|
|
|
+std::wstring utf8ToWChar(const char* src)
|
|
|
{
|
|
|
int len = utf8ToWChar(0, 0, src);
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
}
|
|
|
- wchar_t* buf = new wchar_t[len];
|
|
|
+ array_ptr<wchar_t> buf(new wchar_t[len]);
|
|
|
len = utf8ToWChar(buf, len, src);
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
} else {
|
|
|
- return buf;
|
|
|
+ std::wstring dest(buf);
|
|
|
+ return dest;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::string const std::string& src
|
|
|
+std::wstring utf8ToWChar(const std::string& src)
|
|
|
+{
|
|
|
+ return utf8ToWChar(src.c_str());
|
|
|
+}
|
|
|
+
|
|
|
+std::string utf8ToNative(const std::string& src)
|
|
|
{
|
|
|
std::wstring wsrc = utf8ToWChar(src);
|
|
|
- int len = wCharToAnsi(0, 0, wsrc);
|
|
|
+ int len = wCharToAnsi(0, 0, wsrc.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
}
|
|
|
- char* buf = new char[len];
|
|
|
- len = wCharToAnsi(buf, len, wsrc);
|
|
|
+ array_ptr<char> buf(new char[len]);
|
|
|
+ len = wCharToAnsi(buf, len, wsrc.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
} else {
|
|
|
- return buf;
|
|
|
+ std::string dest(buf);
|
|
|
+ return dest;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
std::string wCharToUtf8(const std::wstring& wsrc)
|
|
|
{
|
|
|
- int len = wCharToUtf8(0, 0, wsrc);
|
|
|
+ int len = wCharToUtf8(0, 0, wsrc.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
}
|
|
|
- char* buf = new char[len];
|
|
|
- len = wCharToUtf8(buf, len, wsrc);
|
|
|
+ array_ptr<char> buf(new char[len]);
|
|
|
+ len = wCharToUtf8(buf, len, wsrc.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
} else {
|
|
|
- return buf;
|
|
|
+ std::string dest(buf);
|
|
|
+ return dest;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
std::string nativeToUtf8(const std::string& src)
|
|
|
{
|
|
|
- int len = ansiToWChar(0, 0, src);
|
|
|
+ int len = ansiToWChar(0, 0, src.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
}
|
|
|
- wchar_t* buf = new wchar_t[len];
|
|
|
- len = ansiToWChar(buf, len, src);
|
|
|
+ array_ptr<wchar_t> buf(new wchar_t[len]);
|
|
|
+ len = ansiToWChar(buf, len, src.c_str());
|
|
|
if(len == 0) {
|
|
|
abort();
|
|
|
} else {
|
|
|
- return wCharToUtf8(buf);
|
|
|
+ return wCharToUtf8(std::wstring(buf));
|
|
|
}
|
|
|
}
|
|
|
#endif // __MINGW32__
|