logic: more wstring usages

* removed header paths from VS Project setup message since VS doesn't send these anymore
* implemented using wstring in IDE communication
* fixed retrieving filepaths from QtDirectoryListbox that contain special characters
* use wstring for source extensions
* added special character as file extension to FileManagerTestSuite
This commit is contained in:
mlangkabel
2018-01-30 17:07:51 +01:00
parent 471b1757df
commit c99e79364f
46 changed files with 319 additions and 337 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ FileManager::~FileManager()
void FileManager::update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<std::string>& sourceExtensions
const std::vector<std::wstring>& sourceExtensions
){
m_sourcePaths = sourcePaths;
m_excludePaths = makeCanonical(excludePaths);
+2 -2
View File
@@ -17,7 +17,7 @@ public:
void update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<std::string>& sourceExtensions
const std::vector<std::wstring>& sourceExtensions
);
// returns a list of source paths (can be directories) specified in the project settings
@@ -36,7 +36,7 @@ private:
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::string> m_sourceExtensions;
std::vector<std::wstring> m_sourceExtensions;
std::set<FilePath> m_allSourceFilePaths;
};
+5
View File
@@ -396,6 +396,11 @@ std::string FilePath::extension() const
return m_path->extension().generic_string();
}
std::wstring FilePath::wExtension() const
{
return m_path->extension().generic_wstring();
}
FilePath FilePath::withoutExtension() const
{
return FilePath(getPath().replace_extension().wstring());
+1
View File
@@ -55,6 +55,7 @@ public:
std::wstring wFileName() const;
std::string extension() const;
std::wstring wExtension() const;
FilePath withoutExtension() const;
FilePath replaceExtension(const std::string& extension) const;
bool hasExtension(const std::vector<std::string>& extensions) const;
+5 -5
View File
@@ -50,10 +50,10 @@ FileInfo FileSystem::getFileInfoForPath(const FilePath& filePath)
}
std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks
const std::vector<FilePath>& paths, const std::vector<std::wstring>& fileExtensions, bool followSymLinks
){
std::set<std::string> ext;
for (const std::string& e : fileExtensions)
std::set<std::wstring> ext;
for (const std::wstring& e : fileExtensions)
{
ext.insert(utility::toLowerCase(e));
}
@@ -103,7 +103,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
}
if (boost::filesystem::is_regular_file(*it) &&
(!ext.size() || ext.find(utility::toLowerCase(it->path().extension().string())) != ext.end()))
(ext.empty() || ext.find(utility::toLowerCase(it->path().extension().wstring())) != ext.end()))
{
boost::filesystem::path p = boost::filesystem::canonical(it->path());
if (filePaths.find(p) != filePaths.end())
@@ -115,7 +115,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
}
}
}
else if (path.exists() && (!ext.size() || ext.find(utility::toLowerCase(path.extension())) != ext.end()))
else if (path.exists() && (ext.empty() || ext.find(utility::toLowerCase(path.wExtension())) != ext.end()))
{
const FilePath canonicalPath = path.getCanonical();
boost::filesystem::path p = canonicalPath.getPath();
+1 -1
View File
@@ -17,7 +17,7 @@ public:
static FileInfo getFileInfoForPath(const FilePath& filePath);
static std::vector<FileInfo> getFileInfosFromPaths(
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks = true);
const std::vector<FilePath>& paths, const std::vector<std::wstring>& fileExtensions, bool followSymLinks = true);
static std::set<FilePath> getSymLinkedDirectories(const std::vector<FilePath>& paths);
@@ -7,10 +7,10 @@
class MessageMoveIDECursor : public Message<MessageMoveIDECursor>
{
public:
MessageMoveIDECursor(const FilePath& FilePos, const unsigned int Row, const unsigned int Column)
: FilePosition(FilePos)
, Row(Row)
, Column(Column)
MessageMoveIDECursor(const FilePath& filePath, const unsigned int row, const unsigned int column)
: filePath(filePath)
, row(row)
, column(column)
{
}
@@ -21,12 +21,12 @@ public:
virtual void print(std::ostream& os) const
{
os << FilePosition.str() << ":" << Row << ":" << Column;
os << filePath.str() << ":" << row << ":" << column;
}
const FilePath FilePosition;
const unsigned int Row;
const unsigned int Column;
const FilePath filePath;
const unsigned int row;
const unsigned int column;
};
#endif // MESSAGE_MOVE_IDE_CURSOR_H
@@ -8,8 +8,7 @@ class MessagePingReceived
{
public:
MessagePingReceived()
: ideId("")
, ideName("")
: ideName(L"")
{
}
@@ -18,8 +17,7 @@ public:
return "MessagePingReceived";
}
std::string ideId;
std::string ideName;
std::wstring ideName;
};
#endif // MESSAGE_PING_RECEIVED_H
@@ -7,9 +7,8 @@ class MessageProjectNew
: public Message<MessageProjectNew>
{
public:
MessageProjectNew(const std::string cdbPath, const std::vector<std::string> headerPaths)
MessageProjectNew(const FilePath& cdbPath)
: cdbPath(cdbPath)
, headerPaths(headerPaths)
{
}
@@ -18,8 +17,7 @@ public:
return "MessageProjectNew";
}
const std::string cdbPath;
const std::vector<std::string> headerPaths;
const FilePath cdbPath;
};
#endif // MESSAGE_PROJECT_NEW_H
+10 -3
View File
@@ -10,7 +10,7 @@
namespace
{
template <typename StringType>
StringType doRreplace(StringType str, const StringType& from, const StringType& to)
StringType doReplace(StringType str, const StringType& from, const StringType& to)
{
size_t pos = 0;
@@ -215,6 +215,13 @@ namespace utility
return out;
}
std::wstring toLowerCase(const std::wstring& in)
{
std::wstring out;
std::transform(in.begin(), in.end(), std::back_inserter(out), tolower);
return out;
}
bool equalsCaseInsensitive(const std::string& a, const std::string& b)
{
if (a.size() == b.size())
@@ -233,12 +240,12 @@ namespace utility
std::string replace(std::string str, const std::string& from, const std::string& to)
{
return doRreplace(str, from, to);
return doReplace(str, from, to);
}
std::wstring replace(std::wstring str, const std::wstring& from, const std::wstring& to)
{
return doRreplace(str, from, to);
return doReplace(str, from, to);
}
std::string replaceBetween(const std::string& str, char startDelimiter, char endDelimiter, const std::string& to)
+22 -2
View File
@@ -14,6 +14,9 @@ namespace utility
template <typename ContainerType>
ContainerType split(const std::string& str, const std::string& delimiter);
template <typename ContainerType>
ContainerType split(const std::wstring& str, const std::wstring& delimiter);
std::deque<std::string> split(const std::string& str, char delimiter);
std::deque<std::string> split(const std::string& str, const std::string& delimiter);
std::vector<std::string> splitToVector(const std::string& str, char delimiter);
@@ -45,6 +48,7 @@ namespace utility
std::string toUpperCase(const std::string& in);
std::string toLowerCase(const std::string& in);
std::wstring toLowerCase(const std::wstring& in);
bool equalsCaseInsensitive(const std::string& a, const std::string& b);
std::string replace(std::string str, const std::string& from, const std::string& to);
@@ -80,8 +84,24 @@ namespace utility
pos = str.find(delimiter, oldPos);
c.push_back(str.substr(oldPos, pos - oldPos));
oldPos = pos + delimiter.size();
}
while (pos != std::string::npos);
} while (pos != std::string::npos);
return c;
}
template <typename ContainerType>
ContainerType split(const std::wstring& str, const std::wstring& delimiter)
{
size_t pos = 0;
size_t oldPos = 0;
ContainerType c;
do
{
pos = str.find(delimiter, oldPos);
c.push_back(str.substr(oldPos, pos - oldPos));
oldPos = pos + delimiter.size();
} while (pos != std::wstring::npos);
return c;
}