Fixed compilation errors in Win32

This commit is contained in:
Tsuda Kageyu 2013-06-21 01:45:53 +09:00
parent 2316a9661a
commit 8be47ec8dc
3 changed files with 17 additions and 25 deletions

View File

@ -75,29 +75,21 @@ namespace
}
String ext;
#ifdef _WIN32
// Avoids direct conversion from FileName to String
// because String can't decode strings in local encodings properly.
if(!fileName.wstr().empty()) {
const wchar_t *pext = PathFindExtensionW(fileName.wstr().c_str());
if(*pext == L'.')
ext = String(pext + 1).upper();
}
else {
const char *pext = PathFindExtensionA(fileName.str().c_str());
if(*pext == '.')
ext = String(pext + 1).upper();
}
#else
{
#ifdef _WIN32
String s = fileName.toString();
#else
String s = fileName;
const size_t pos = s.rfind(".");
if(pos != String::npos)
#endif
const int pos = s.rfind(".");
if(pos != -1)
ext = s.substr(pos + 1).upper();
}
#endif
// If this list is updated, the method defaultFileExtensions() should also be
// updated. However at some point that list should be created at the same time

View File

@ -43,7 +43,7 @@ namespace
{
#ifdef _WIN32
const wstring wstr = msg.toWString();
const std::wstring wstr = msg.toWString();
const int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
if(len != 0) {
std::vector<char> buf(len);

View File

@ -139,16 +139,16 @@ const std::string &FileName::str() const
String FileName::toString() const
{
if(!m_wname.empty()) {
return String(m_wname);
if(!d->data->wname.empty()) {
return String(d->data->wname);
}
else if(!m_name.empty()) {
const int len = MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, NULL, 0);
else if(!d->data->name.empty()) {
const int len = MultiByteToWideChar(CP_ACP, 0, d->data->name.c_str(), -1, NULL, 0);
if(len == 0)
return String::null;
std::vector<wchar_t> buf(len);
MultiByteToWideChar(CP_ACP, 0, m_name.c_str(), -1, &buf[0], len);
MultiByteToWideChar(CP_ACP, 0, d->data->name.c_str(), -1, &buf[0], len);
return String(&buf[0]);
}