mirror of https://github.com/aria2/aria2
Remove nativeToUtf8 and utf8ToNative
They are now not needed since we use Windows specific command-line argument converter.pull/150/head
parent
3a8e8f8e8a
commit
fd0136259c
|
@ -176,20 +176,6 @@ void showCandidates
|
|||
|
||||
} // namespace
|
||||
|
||||
#ifdef __MINGW32__
|
||||
namespace {
|
||||
void optionNativeToUtf8(Option& op)
|
||||
{
|
||||
for(size_t i = 1, len = option::countOption(); i < len; ++i) {
|
||||
PrefPtr pref = option::i2p(i);
|
||||
if(op.definedLocal(pref) && !util::isUtf8(op.get(pref))) {
|
||||
op.put(pref, nativeToUtf8(op.get(pref)));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
#endif // __MINGW32__
|
||||
|
||||
error_code::Value option_processing(Option& op, bool standalone,
|
||||
std::vector<std::string>& uris,
|
||||
int argc, char** argv,
|
||||
|
@ -290,10 +276,6 @@ error_code::Value option_processing(Option& op, bool standalone,
|
|||
op.setParent(confOption);
|
||||
oparser->parse(op, cmdstream);
|
||||
oparser->parse(op, options);
|
||||
#ifdef __MINGW32__
|
||||
optionNativeToUtf8(op);
|
||||
optionNativeToUtf8(*confOption);
|
||||
#endif // __MINGW32__
|
||||
} catch(OptionHandlerException& e) {
|
||||
global::cerr()->printf("%s", e.stackTrace().c_str());
|
||||
const OptionHandler* h = oparser->find(e.getPref());
|
||||
|
|
51
src/util.cc
51
src/util.cc
|
@ -105,30 +105,17 @@ int utf8ToWChar(wchar_t* out, size_t outLength, const char* src)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
int ansiToWChar(wchar_t* out, size_t outLength, const char* src)
|
||||
{
|
||||
return MultiByteToWideChar(CP_ACP, 0, src, -1, out, outLength);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
int wCharToUtf8(char* out, size_t outLength, const wchar_t* src)
|
||||
{
|
||||
return WideCharToMultiByte(CP_UTF8, 0, src, -1, out, outLength, 0, 0);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
int wCharToAnsi(char* out, size_t outLength, const wchar_t* src)
|
||||
{
|
||||
return WideCharToMultiByte(CP_ACP, 0, src, -1, out, outLength, 0, 0);
|
||||
return WideCharToMultiByte(CP_UTF8, 0, src, -1, out, outLength,
|
||||
nullptr, nullptr);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::wstring utf8ToWChar(const char* src)
|
||||
{
|
||||
int len = utf8ToWChar(0, 0, src);
|
||||
int len = utf8ToWChar(nullptr, 0, src);
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -146,25 +133,9 @@ 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.c_str());
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
}
|
||||
auto buf = make_unique<char[]>((size_t)len);
|
||||
len = wCharToAnsi(buf.get(), len, wsrc.c_str());
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
} else {
|
||||
return buf.get();
|
||||
}
|
||||
}
|
||||
|
||||
std::string wCharToUtf8(const std::wstring& wsrc)
|
||||
{
|
||||
int len = wCharToUtf8(0, 0, wsrc.c_str());
|
||||
int len = wCharToUtf8(nullptr, 0, wsrc.c_str());
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
}
|
||||
|
@ -177,20 +148,6 @@ std::string wCharToUtf8(const std::wstring& wsrc)
|
|||
}
|
||||
}
|
||||
|
||||
std::string nativeToUtf8(const std::string& src)
|
||||
{
|
||||
int len = ansiToWChar(0, 0, src.c_str());
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
}
|
||||
auto buf = make_unique<wchar_t[]>((size_t)len);
|
||||
len = ansiToWChar(buf.get(), len, src.c_str());
|
||||
if(len <= 0) {
|
||||
abort();
|
||||
} else {
|
||||
return wCharToUtf8(std::wstring(buf.get()));
|
||||
}
|
||||
}
|
||||
#endif // __MINGW32__
|
||||
|
||||
namespace util {
|
||||
|
|
|
@ -103,11 +103,7 @@ std::wstring utf8ToWChar(const std::string& src);
|
|||
|
||||
std::wstring utf8ToWChar(const char* str);
|
||||
|
||||
std::string utf8ToNative(const std::string& src);
|
||||
|
||||
std::string wCharToUtf8(const std::wstring& wsrc);
|
||||
|
||||
std::string nativeToUtf8(const std::string& src);
|
||||
#else // !__MINGW32__
|
||||
# define utf8ToWChar(src) src
|
||||
# define utf8ToNative(src) src
|
||||
|
|
Loading…
Reference in New Issue