logic: fixed handling non-ascii characters in cdb path and in cdb filename and command
This commit is contained in:
@@ -236,12 +236,12 @@ SettingsMigrator ProjectSettings::getMigrations() const
|
||||
const std::string language = migration->getValueFromSettings<std::string>(settings, "language_settings/language", "");
|
||||
const std::string standard = migration->getValueFromSettings<std::string>(settings, "language_settings/standard", "");
|
||||
|
||||
if (language == "C" && !utility::isPrefix("c", standard))
|
||||
if (language == "C" && !utility::isPrefix<std::string>("c", standard))
|
||||
{
|
||||
migration->setValueInSettings(settings, "language_settings/standard", "c" + standard);
|
||||
}
|
||||
|
||||
if (language == "C++" && !utility::isPrefix("c++", standard))
|
||||
if (language == "C++" && !utility::isPrefix<std::string>("c++", standard))
|
||||
{
|
||||
migration->setValueInSettings(settings, "language_settings/standard", "c++" + standard);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ FilePath::FilePath(FilePath&& other)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(const std::string& filePath, const std::string& base)
|
||||
FilePath::FilePath(const std::wstring& filePath, const std::wstring& base)
|
||||
: m_path(std::make_unique<boost::filesystem::path>(boost::filesystem::absolute(filePath, base)))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
explicit FilePath(const std::wstring& filePath);
|
||||
FilePath(const FilePath& other);
|
||||
FilePath(FilePath&& other);
|
||||
FilePath(const std::string& filePath, const std::string& base);
|
||||
FilePath(const std::wstring& filePath, const std::wstring& base);
|
||||
~FilePath();
|
||||
|
||||
boost::filesystem::path getPath() const;
|
||||
|
||||
@@ -237,23 +237,6 @@ namespace utility
|
||||
return str;
|
||||
}
|
||||
|
||||
bool isPrefix(const std::string& prefix, const std::string& text)
|
||||
{
|
||||
if (prefix.size() <= text.size())
|
||||
{
|
||||
std::pair<std::string::const_iterator, std::string::const_iterator> res =
|
||||
std::mismatch(prefix.begin(), prefix.end(), text.begin());
|
||||
|
||||
return res.first == prefix.end();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isPostfix(const std::string& postfix, const std::string& text)
|
||||
{
|
||||
return text.size() >= postfix.size() && text.rfind(postfix) == (text.size() - postfix.size());
|
||||
}
|
||||
|
||||
std::string toUpperCase(const std::string& in)
|
||||
{
|
||||
std::string out;
|
||||
|
||||
@@ -49,8 +49,11 @@ namespace utility
|
||||
|
||||
std::string substrBetween(const std::string& str, const std::string& delimiter1, const std::string& delimiter2);
|
||||
|
||||
bool isPrefix(const std::string& prefix, const std::string& text);
|
||||
bool isPostfix(const std::string& postfix, const std::string& text);
|
||||
template <typename StringType>
|
||||
bool isPrefix(const StringType& prefix, const StringType& text);
|
||||
|
||||
template <typename StringType>
|
||||
bool isPostfix(const StringType& postfix, const StringType& text);
|
||||
|
||||
std::string toUpperCase(const std::string& in);
|
||||
std::string toLowerCase(const std::string& in);
|
||||
@@ -154,6 +157,25 @@ namespace utility
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename StringType>
|
||||
bool isPrefix(const StringType& prefix, const StringType& text)
|
||||
{
|
||||
if (prefix.size() <= text.size())
|
||||
{
|
||||
std::pair<StringType::const_iterator, StringType::const_iterator> res =
|
||||
std::mismatch(prefix.begin(), prefix.end(), text.begin());
|
||||
|
||||
return res.first == prefix.end();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename StringType>
|
||||
bool isPostfix(const StringType& postfix, const StringType& text)
|
||||
{
|
||||
return text.size() >= postfix.size() && text.rfind(postfix) == (text.size() - postfix.size());
|
||||
}
|
||||
|
||||
template <typename StringType>
|
||||
bool equalsCaseInsensitive(const StringType& a, const StringType& b)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ std::vector<FilePath> IndexerCommandCxxCdb::getSourceFilesFromCDB(const FilePath
|
||||
{
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
|
||||
(clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error, clang::tooling::JSONCommandLineSyntax::AutoDetect));
|
||||
(clang::tooling::JSONCompilationDatabase::loadFromFile(utility::encodeToUtf8(compilationDatabasePath.wstr()), error, clang::tooling::JSONCommandLineSyntax::AutoDetect));
|
||||
|
||||
if (!error.empty())
|
||||
{
|
||||
@@ -23,10 +23,10 @@ std::vector<FilePath> IndexerCommandCxxCdb::getSourceFilesFromCDB(const FilePath
|
||||
{
|
||||
for (const clang::tooling::CompileCommand& command : cdb->getAllCompileCommands())
|
||||
{
|
||||
FilePath path = FilePath(command.Filename).makeCanonical();
|
||||
FilePath path = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical();
|
||||
if (!path.isAbsolute())
|
||||
{
|
||||
path = FilePath(command.Directory + '/' + command.Filename).makeCanonical();
|
||||
path = FilePath(utility::decodeFromUtf8(command.Directory + '/' + command.Filename)).makeCanonical();
|
||||
}
|
||||
filePaths.push_back(path);
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ CxxParser::~CxxParser()
|
||||
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
|
||||
{
|
||||
clang::tooling::CompileCommand compileCommand;
|
||||
compileCommand.Filename = indexerCommand->getSourceFilePath().str();
|
||||
compileCommand.Directory = indexerCommand->getWorkingDirectory().str();
|
||||
compileCommand.Filename = utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr());
|
||||
compileCommand.Directory = utility::encodeToUtf8(indexerCommand->getWorkingDirectory().wstr());
|
||||
compileCommand.CommandLine = utility::concat(
|
||||
utility::convert<std::wstring, std::string>(indexerCommand->getCompilerFlags(), [](const std::wstring & flag) { return utility::encodeToUtf8(flag); }),
|
||||
getCommandlineArgumentsEssential(
|
||||
@@ -82,7 +82,7 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
|
||||
)
|
||||
);
|
||||
|
||||
if (!utility::isPrefix("-", compileCommand.CommandLine.front()))
|
||||
if (!utility::isPrefix<std::string>("-", compileCommand.CommandLine.front()))
|
||||
{
|
||||
compileCommand.CommandLine.erase(compileCommand.CommandLine.begin());
|
||||
}
|
||||
@@ -126,7 +126,7 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr<TextAcc
|
||||
|
||||
void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath)
|
||||
{
|
||||
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, sourceFilePath.str()));
|
||||
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, utility::encodeToUtf8(sourceFilePath.wstr())));
|
||||
|
||||
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb =
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(cdbPath.str(),
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(utility::encodeToUtf8(cdbPath.wstr()),
|
||||
error,
|
||||
clang::tooling::JSONCommandLineSyntax::AutoDetect
|
||||
)
|
||||
@@ -96,10 +96,10 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
|
||||
|
||||
for (const clang::tooling::CompileCommand& command: cdb->getAllCompileCommands())
|
||||
{
|
||||
FilePath sourcePath = FilePath(command.Filename).makeCanonical();
|
||||
FilePath sourcePath = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical();
|
||||
if (!sourcePath.isAbsolute())
|
||||
{
|
||||
sourcePath = FilePath(command.Directory + '/' + command.Filename).makeCanonical();
|
||||
sourcePath = FilePath(utility::decodeFromUtf8(command.Directory + '/' + command.Filename)).makeCanonical();
|
||||
}
|
||||
|
||||
if (filesToIndex.find(sourcePath) != filesToIndex.end() &&
|
||||
@@ -109,7 +109,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxxCdb::getIndexerComman
|
||||
sourcePath,
|
||||
indexedPaths,
|
||||
excludedPaths,
|
||||
FilePath(command.Directory),
|
||||
FilePath(utility::decodeFromUtf8(command.Directory)),
|
||||
utility::concat(
|
||||
utility::convert<std::string, std::wstring>(command.CommandLine, [](const std::string& arg) { return utility::decodeFromUtf8(arg); }),
|
||||
compilerFlags
|
||||
|
||||
@@ -40,7 +40,7 @@ void utility::CompilationDatabase::init()
|
||||
{
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(m_filePath.str(), error, clang::tooling::JSONCommandLineSyntax::AutoDetect)
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(utility::encodeToUtf8(m_filePath.wstr()), error, clang::tooling::JSONCommandLineSyntax::AutoDetect)
|
||||
);
|
||||
|
||||
std::vector<clang::tooling::CompileCommand> commands = cdb->getAllCompileCommands();
|
||||
@@ -49,35 +49,36 @@ void utility::CompilationDatabase::init()
|
||||
std::set<FilePath> headers;
|
||||
|
||||
{
|
||||
const std::string frameworkIncludeFlag = "-iframework";
|
||||
const std::string systemIncludeFlag = "-isystem";
|
||||
const std::string quoteFlag = "-iquote";
|
||||
const std::string includeFlag = "-I";
|
||||
const std::wstring frameworkIncludeFlag = L"-iframework";
|
||||
const std::wstring systemIncludeFlag = L"-isystem";
|
||||
const std::wstring quoteFlag = L"-iquote";
|
||||
const std::wstring includeFlag = L"-I";
|
||||
for (clang::tooling::CompileCommand& command : commands)
|
||||
{
|
||||
const std::wstring commandDirectory = utility::decodeFromUtf8(command.Directory);
|
||||
for (size_t i = 0; i < command.CommandLine.size(); i++)
|
||||
{
|
||||
std::string argument = command.CommandLine[i];
|
||||
if (i + 1 < command.CommandLine.size() && !utility::isPrefix("-", command.CommandLine[i + 1]))
|
||||
std::wstring argument = utility::decodeFromUtf8(command.CommandLine[i]);
|
||||
if (i + 1 < command.CommandLine.size() && !utility::isPrefix<std::string>("-", command.CommandLine[i + 1]))
|
||||
{
|
||||
argument += command.CommandLine[++i];
|
||||
argument += utility::decodeFromUtf8(command.CommandLine[++i]);
|
||||
}
|
||||
|
||||
if (utility::isPrefix(frameworkIncludeFlag, argument))
|
||||
{
|
||||
frameworkHeaders.insert(FilePath(utility::trim(argument.substr(frameworkIncludeFlag.size())), command.Directory).makeCanonical());
|
||||
frameworkHeaders.insert(FilePath(utility::trim(argument.substr(frameworkIncludeFlag.size())), commandDirectory).makeCanonical());
|
||||
}
|
||||
else if (utility::isPrefix(systemIncludeFlag, argument))
|
||||
{
|
||||
systemHeaders.insert(FilePath(utility::trim(argument.substr(systemIncludeFlag.size())), command.Directory).makeCanonical());
|
||||
systemHeaders.insert(FilePath(utility::trim(argument.substr(systemIncludeFlag.size())), commandDirectory).makeCanonical());
|
||||
}
|
||||
else if (utility::isPrefix(quoteFlag, argument))
|
||||
{
|
||||
headers.insert(FilePath(utility::trim(argument.substr(quoteFlag.size())), command.Directory).makeCanonical());
|
||||
headers.insert(FilePath(utility::trim(argument.substr(quoteFlag.size())), commandDirectory).makeCanonical());
|
||||
}
|
||||
else if (utility::isPrefix(includeFlag, argument))
|
||||
{
|
||||
headers.insert(FilePath(utility::trim(argument.substr(includeFlag.size())), command.Directory).makeCanonical());
|
||||
headers.insert(FilePath(utility::trim(argument.substr(includeFlag.size())), commandDirectory).makeCanonical());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ std::vector<IncludeDirective> IncludeProcessing::getIncludeDirectives(std::share
|
||||
for (size_t i = 0; i < lines.size(); i++)
|
||||
{
|
||||
const std::string lineTrimmedToHash = utility::trim(lines[i]);
|
||||
if (utility::isPrefix("#", lineTrimmedToHash))
|
||||
if (utility::isPrefix<std::string>("#", lineTrimmedToHash))
|
||||
{
|
||||
const std::string lineTrimmedToInclude = utility::trim(lineTrimmedToHash.substr(1));
|
||||
if (utility::isPrefix("include", lineTrimmedToInclude))
|
||||
if (utility::isPrefix<std::string>("include", lineTrimmedToInclude))
|
||||
{
|
||||
std::string includeString = utility::substrBetween(lineTrimmedToInclude, "<", ">");
|
||||
bool usesBrackets = true;
|
||||
|
||||
@@ -20,7 +20,7 @@ std::vector<FilePath> CxxFrameworkPathDetector::getPaths() const
|
||||
std::vector<FilePath> frameworkPaths;
|
||||
for (const std::string& path : paths)
|
||||
{
|
||||
if (utility::isPostfix(" (framework directory)", path))
|
||||
if (utility::isPostfix<std::string>(" (framework directory)", path))
|
||||
{
|
||||
frameworkPaths.push_back(FilePath(utility::replace(path, " (framework directory)", "")).makeCanonical());
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ std::vector<FilePath> CxxHeaderPathDetector::getPaths() const
|
||||
std::vector<FilePath> headerPaths;
|
||||
for (const std::string& path : paths)
|
||||
{
|
||||
if (!utility::isPostfix(" (framework directory)", path))
|
||||
if (!utility::isPostfix<std::string>(" (framework directory)", path))
|
||||
{
|
||||
headerPaths.push_back(FilePath(path).makeCanonical());
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace utility
|
||||
utility::encodeToUtf8(gradleInitScriptPath.wstr())
|
||||
);
|
||||
|
||||
if (utility::isPrefix("[ERROR]", utility::trim(output)))
|
||||
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
|
||||
{
|
||||
// TODO: move error handling to caller of this function
|
||||
const std::wstring dialogMessage =
|
||||
@@ -109,7 +109,7 @@ namespace utility
|
||||
utility::encodeToUtf8(gradleInitScriptPath.wstr())
|
||||
);
|
||||
|
||||
if (utility::isPrefix("[ERROR]", utility::trim(output)))
|
||||
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
|
||||
{
|
||||
// TODO: move error handling to caller of this function
|
||||
const std::wstring dialogMessage =
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace utility
|
||||
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(output);
|
||||
for (const std::string& line: outputAccess->getAllLines())
|
||||
{
|
||||
if (utility::isPrefix("[ERROR]", utility::trim(line)))
|
||||
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(line)))
|
||||
{
|
||||
// TODO: move error handling to caller of this function
|
||||
const std::wstring dialogMessage =
|
||||
@@ -112,7 +112,7 @@ namespace utility
|
||||
60000
|
||||
));
|
||||
|
||||
if (outputAccess->getLineCount() > 0 && utility::isPrefix("Error", utility::trim(outputAccess->getLine(1))))
|
||||
if (outputAccess->getLineCount() > 0 && utility::isPrefix<std::string>("Error", utility::trim(outputAccess->getLine(1))))
|
||||
{
|
||||
// TODO: move error handling to caller of this function
|
||||
const std::wstring dialogMessage =
|
||||
@@ -129,7 +129,7 @@ namespace utility
|
||||
size_t startLine = 0;
|
||||
for (size_t i = 1; i <= outputAccess->getLineCount(); i++)
|
||||
{
|
||||
if (utility::isPrefix("<", utility::trim(outputAccess->getLine(i))))
|
||||
if (utility::isPrefix<std::string>("<", utility::trim(outputAccess->getLine(i))))
|
||||
{
|
||||
startLine = i;
|
||||
break;
|
||||
@@ -139,7 +139,7 @@ namespace utility
|
||||
size_t endLine = outputAccess->getLineCount();
|
||||
for (size_t i = outputAccess->getLineCount(); i > 0 ; i--)
|
||||
{
|
||||
if (utility::isPrefix("<", utility::trim(outputAccess->getLine(i))))
|
||||
if (utility::isPrefix<std::string>("<", utility::trim(outputAccess->getLine(i))))
|
||||
{
|
||||
endLine = i;
|
||||
break;
|
||||
@@ -147,7 +147,7 @@ namespace utility
|
||||
}
|
||||
for (size_t i = endLine + 1; i <= outputAccess->getLineCount(); i++)
|
||||
{
|
||||
if (utility::isPrefix("[", utility::trim(outputAccess->getLine(i))))
|
||||
if (utility::isPrefix<std::string>("[", utility::trim(outputAccess->getLine(i))))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
{
|
||||
const std::string foo = "foo";
|
||||
|
||||
TS_ASSERT(utility::isPrefix("", foo));
|
||||
TS_ASSERT(utility::isPrefix<std::string>("", foo));
|
||||
}
|
||||
|
||||
void test_prefix_of_bigger_text_is_detected_as_prefix()
|
||||
|
||||
Reference in New Issue
Block a user