Committed patch removing unnecessary Unicode-Ansi conversions (fixed #2123)
This commit is contained in:
parent
a96ec0ad46
commit
37820af7f8
|
@ -36,56 +36,7 @@
|
||||||
|
|
||||||
// Here is the catch: cppcheck core is Ansi code (using char type).
|
// Here is the catch: cppcheck core is Ansi code (using char type).
|
||||||
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
|
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
|
||||||
// of called functions. So we must convert data given to WinAPI functions from
|
// of called functions. Thus, we explicitly call *A versions of the functions.
|
||||||
// ANSI to Unicode. Likewise we must convert data we get from WinAPI from
|
|
||||||
// Unicode to ANSI.
|
|
||||||
|
|
||||||
// Note that qmake creates VS project files that define UNICODE but don't
|
|
||||||
// define _UNICODE! Which means e.g. TCHAR macros don't work properly.
|
|
||||||
|
|
||||||
#if defined(UNICODE)
|
|
||||||
|
|
||||||
static bool TransformUcs2ToAnsi(LPCWSTR psUcs, LPSTR psAnsi, int nAnsi)
|
|
||||||
{
|
|
||||||
WideCharToMultiByte(CP_ACP, 0, psUcs, -1, psAnsi, nAnsi, NULL, NULL);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool TransformAnsiToUcs2(LPCSTR psAnsi, LPWSTR psUcs, UINT nUcs)
|
|
||||||
{
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, psAnsi, -1, psUcs, nUcs);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL MyIsDirectory(const std::string& path)
|
|
||||||
{
|
|
||||||
WCHAR * unicodeCleanPath = new WCHAR[path.size() + 1];
|
|
||||||
TransformAnsiToUcs2(path.c_str(), unicodeCleanPath, path.size() + 1);
|
|
||||||
// See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
|
|
||||||
BOOL res = PathIsDirectory(unicodeCleanPath);
|
|
||||||
delete [] unicodeCleanPath;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static HANDLE MyFindFirstFile(const std::string& path, LPWIN32_FIND_DATA findData)
|
|
||||||
{
|
|
||||||
WCHAR * unicodeOss = new wchar_t[path.size() + 1];
|
|
||||||
TransformAnsiToUcs2(path.c_str(), unicodeOss, path.size() + 1);
|
|
||||||
HANDLE hFind = FindFirstFile(unicodeOss, findData);
|
|
||||||
delete [] unicodeOss;
|
|
||||||
return hFind;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL MyFileExists(const std::string& path)
|
|
||||||
{
|
|
||||||
WCHAR * unicodeOss = new wchar_t[path.size() + 1];
|
|
||||||
TransformAnsiToUcs2(path.c_str(), unicodeOss, path.size() + 1);
|
|
||||||
BOOL result = PathFileExists(unicodeOss);
|
|
||||||
delete [] unicodeOss;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // defined(UNICODE)
|
|
||||||
|
|
||||||
static BOOL MyIsDirectory(const std::string& path)
|
static BOOL MyIsDirectory(const std::string& path)
|
||||||
{
|
{
|
||||||
|
@ -93,13 +44,13 @@ static BOOL MyIsDirectory(const std::string& path)
|
||||||
return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
|
return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
#else
|
#else
|
||||||
// See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
|
// See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
|
||||||
return PathIsDirectory(path.c_str());
|
return PathIsDirectoryA(path.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE MyFindFirstFile(const std::string& path, LPWIN32_FIND_DATA findData)
|
static HANDLE MyFindFirstFile(const std::string& path, LPWIN32_FIND_DATAA findData)
|
||||||
{
|
{
|
||||||
HANDLE hFind = FindFirstFile(path.c_str(), findData);
|
HANDLE hFind = FindFirstFileA(path.c_str(), findData);
|
||||||
return hFind;
|
return hFind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,13 +62,11 @@ static BOOL MyFileExists(const std::string& path)
|
||||||
if (fa != INVALID_FILE_ATTRIBUTES && !(fa & FILE_ATTRIBUTE_DIRECTORY))
|
if (fa != INVALID_FILE_ATTRIBUTES && !(fa & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
#else
|
#else
|
||||||
BOOL result = PathFileExists(path.c_str());
|
BOOL result = PathFileExistsA(path.c_str());
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined(UNICODE)
|
|
||||||
|
|
||||||
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path)
|
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path)
|
||||||
{
|
{
|
||||||
// oss is the search string passed into FindFirst and FindNext.
|
// oss is the search string passed into FindFirst and FindNext.
|
||||||
|
@ -151,7 +100,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WIN32_FIND_DATA ffd;
|
WIN32_FIND_DATAA ffd;
|
||||||
HANDLE hFind = MyFindFirstFile(oss.str(), &ffd);
|
HANDLE hFind = MyFindFirstFile(oss.str(), &ffd);
|
||||||
if (INVALID_HANDLE_VALUE == hFind)
|
if (INVALID_HANDLE_VALUE == hFind)
|
||||||
return;
|
return;
|
||||||
|
@ -160,16 +109,10 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
||||||
if (ffd.cFileName[0] == '.' || ffd.cFileName[0] == '\0')
|
if (ffd.cFileName[0] == '.' || ffd.cFileName[0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#if defined(UNICODE)
|
const char* ansiFfd = ffd.cFileName;
|
||||||
std::size_t length = wcslen(ffd.cFileName);
|
|
||||||
char * ansiFfd = new char[length + 1];
|
|
||||||
TransformUcs2ToAnsi(ffd.cFileName, ansiFfd, length + 1);
|
|
||||||
#else // defined(UNICODE)
|
|
||||||
const char * ansiFfd = &ffd.cFileName[0];
|
|
||||||
if (strchr(ansiFfd,'?')) {
|
if (strchr(ansiFfd,'?')) {
|
||||||
ansiFfd = &ffd.cAlternateFileName[0];
|
ansiFfd = ffd.cAlternateFileName;
|
||||||
}
|
}
|
||||||
#endif // defined(UNICODE)
|
|
||||||
|
|
||||||
std::ostringstream fname;
|
std::ostringstream fname;
|
||||||
fname << bdir.str() << ansiFfd;
|
fname << bdir.str() << ansiFfd;
|
||||||
|
@ -191,10 +134,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
||||||
// Directory
|
// Directory
|
||||||
FileLister::recursiveAddFiles(files, fname.str());
|
FileLister::recursiveAddFiles(files, fname.str());
|
||||||
}
|
}
|
||||||
#if defined(UNICODE)
|
} while (FindNextFileA(hFind, &ffd) != FALSE);
|
||||||
delete [] ansiFfd;
|
|
||||||
#endif // defined(UNICODE)
|
|
||||||
} while (FindNextFile(hFind, &ffd) != FALSE);
|
|
||||||
|
|
||||||
if (INVALID_HANDLE_VALUE != hFind) {
|
if (INVALID_HANDLE_VALUE != hFind) {
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
|
|
Loading…
Reference in New Issue