Pave a way for Windows Unicode builds.
Use UNICODE preprocessor define instead of QT_CORE_LIB when determining whether to use Ansi or Unicode data and functions. This only applies to Windows.
This commit is contained in:
parent
11bc5195b8
commit
d88cf4d3e4
|
@ -154,11 +154,13 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const st
|
||||||
|
|
||||||
#if (defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__))
|
#if (defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__))
|
||||||
|
|
||||||
// Windows QT build is Unicode build. And cppcheck is ANSI build. So we must
|
// Here is the catch: cppcheck core is Ansi code (using char type).
|
||||||
// convert data given to WinAPI functions from ANSI to Unicode. Likewise we
|
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
|
||||||
// must convert data we get from WinAPI from Unicode to ANSI.
|
// of called functions. So we must convert data given to WinAPI functions from
|
||||||
|
// ANSI to Unicode. Likewise we must convert data we get from WinAPI from
|
||||||
|
// Unicode to ANSI.
|
||||||
|
|
||||||
#if defined(QT_CORE_LIB)
|
#if defined(UNICODE)
|
||||||
|
|
||||||
static bool TransformUcs2ToAnsi(LPCWSTR psUcs, LPSTR psAnsi, int nAnsi)
|
static bool TransformUcs2ToAnsi(LPCWSTR psUcs, LPSTR psAnsi, int nAnsi)
|
||||||
{
|
{
|
||||||
|
@ -192,7 +194,7 @@ static HANDLE MyFindFirstFile(std::string path, LPWIN32_FIND_DATA findData)
|
||||||
return hFind;
|
return hFind;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // defined(QT_CORE_LIB)
|
#else // defined(UNICODE)
|
||||||
|
|
||||||
static BOOL MyIsDirectory(std::string path)
|
static BOOL MyIsDirectory(std::string path)
|
||||||
{
|
{
|
||||||
|
@ -207,7 +209,7 @@ static HANDLE MyFindFirstFile(std::string path, LPWIN32_FIND_DATA findData)
|
||||||
return hFind;
|
return hFind;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined(QT_CORE_LIB)
|
#endif // defined(UNICODE)
|
||||||
|
|
||||||
void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
|
void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive)
|
||||||
{
|
{
|
||||||
|
@ -258,12 +260,12 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const st
|
||||||
if (ffd.cFileName[0] == '.' || ffd.cFileName[0] == '\0')
|
if (ffd.cFileName[0] == '.' || ffd.cFileName[0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#if defined(QT_CORE_LIB)
|
#if defined(UNICODE)
|
||||||
char * ansiFfd = new char[wcslen(ffd.cFileName) + 1];
|
char * ansiFfd = new char[wcslen(ffd.cFileName) + 1];
|
||||||
TransformUcs2ToAnsi(ffd.cFileName, ansiFfd, wcslen(ffd.cFileName) + 1);
|
TransformUcs2ToAnsi(ffd.cFileName, ansiFfd, wcslen(ffd.cFileName) + 1);
|
||||||
#else // defined(QT_CORE_LIB)
|
#else // defined(UNICODE)
|
||||||
char * ansiFfd = &ffd.cFileName[0];
|
char * ansiFfd = &ffd.cFileName[0];
|
||||||
#endif // defined(QT_CORE_LIB)
|
#endif // defined(UNICODE)
|
||||||
|
|
||||||
std::ostringstream fname;
|
std::ostringstream fname;
|
||||||
fname << bdir.str().c_str() << ansiFfd;
|
fname << bdir.str().c_str() << ansiFfd;
|
||||||
|
@ -281,9 +283,9 @@ void FileLister::recursiveAddFiles(std::vector<std::string> &filenames, const st
|
||||||
// Directory
|
// Directory
|
||||||
FileLister::recursiveAddFiles(filenames, fname.str().c_str(), recursive);
|
FileLister::recursiveAddFiles(filenames, fname.str().c_str(), recursive);
|
||||||
}
|
}
|
||||||
#if defined(QT_CORE_LIB)
|
#if defined(UNICODE)
|
||||||
delete [] ansiFfd;
|
delete [] ansiFfd;
|
||||||
#endif // defined(QT_CORE_LIB)
|
#endif // defined(UNICODE)
|
||||||
}
|
}
|
||||||
while (FindNextFile(hFind, &ffd) != FALSE);
|
while (FindNextFile(hFind, &ffd) != FALSE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue