*** empty log message ***
This commit is contained in:
parent
cc1d4dfdde
commit
c2b496f472
|
@ -34,9 +34,9 @@ template<typename InputIterator>
|
||||||
wchar_t decode_utf8_mb(InputIterator &iter, InputIterator last)
|
wchar_t decode_utf8_mb(InputIterator &iter, InputIterator last)
|
||||||
{
|
{
|
||||||
if (iter == last) throw std::runtime_error("incomplete UTF-8 sequence");
|
if (iter == last) throw std::runtime_error("incomplete UTF-8 sequence");
|
||||||
if(((*iter)&0xC0)!=0x80) throw std::runtime_error("invalid UTF-8 sequence");
|
if (((*iter) & 0xc0) != 0x80) throw std::runtime_error("invalid UTF-8 sequence");
|
||||||
|
|
||||||
return (wchar_t)((*iter++)&0x3F);
|
return (wchar_t)((*iter++) & 0x3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
|
@ -56,7 +56,7 @@ wchar_t decode_utf8(InputIterator &iter, InputIterator last)
|
||||||
}
|
}
|
||||||
else if (((*iter) & 0xf0) == 0xe0) // three bytes
|
else if (((*iter) & 0xf0) == 0xe0) // three bytes
|
||||||
{
|
{
|
||||||
wchar_t byte1 = (*iter++) & 0x1f;
|
wchar_t byte1 = (*iter++) & 0x0f;
|
||||||
wchar_t byte2 = decode_utf8_mb(iter, last);
|
wchar_t byte2 = decode_utf8_mb(iter, last);
|
||||||
wchar_t byte3 = decode_utf8_mb(iter, last);
|
wchar_t byte3 = decode_utf8_mb(iter, last);
|
||||||
ret = (byte1 << 12) | (byte2 << 6) | byte3;
|
ret = (byte1 << 12) | (byte2 << 6) | byte3;
|
||||||
|
@ -155,6 +155,21 @@ inline std::string wchar_utf8(const std::wstring &str)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::wstring safe_convert(std::string const& s)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return utf8_wchar(s);
|
||||||
|
}
|
||||||
|
catch (std::exception)
|
||||||
|
{
|
||||||
|
std::wstring ret;
|
||||||
|
for (const char* i = &*s.begin(); i < &*s.end(); ++i)
|
||||||
|
ret += *i;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -93,6 +93,7 @@ namespace
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.resize(size);
|
ret.resize(size);
|
||||||
size = wcstombs(&ret[0], ws.c_str(), size + 1);
|
size = wcstombs(&ret[0], ws.c_str(), size + 1);
|
||||||
|
if (size == -1) return s;
|
||||||
ret.resize(size);
|
ret.resize(size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -142,10 +143,18 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
assert(path.is_complete());
|
assert(path.is_complete());
|
||||||
close();
|
close();
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
std::wstring wpath(safe_convert(path.native_file_string()));
|
||||||
|
m_fd = ::_wopen(
|
||||||
|
wpath.c_str()
|
||||||
|
, map_open_mode(mode)
|
||||||
|
, S_IREAD | S_IWRITE);
|
||||||
|
#else
|
||||||
m_fd = ::open(
|
m_fd = ::open(
|
||||||
utf8_native(path.native_file_string()).c_str()
|
utf8_native(path.native_file_string()).c_str()
|
||||||
, map_open_mode(mode)
|
, map_open_mode(mode)
|
||||||
, S_IREAD | S_IWRITE);
|
, S_IREAD | S_IWRITE);
|
||||||
|
#endif
|
||||||
if (m_fd == -1)
|
if (m_fd == -1)
|
||||||
{
|
{
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
|
|
Loading…
Reference in New Issue