summaryrefslogtreecommitdiffstats
path: root/Source/cmVisualStudioSlnParser.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmVisualStudioSlnParser.cxx')
-rw-r--r--Source/cmVisualStudioSlnParser.cxx189
1 files changed, 104 insertions, 85 deletions
diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx
index feab895..71c758e 100644
--- a/Source/cmVisualStudioSlnParser.cxx
+++ b/Source/cmVisualStudioSlnParser.cxx
@@ -80,19 +80,19 @@ bool cmVisualStudioSlnParser::ParsedLine::IsKeyValuePair() const
std::string cmVisualStudioSlnParser::ParsedLine::GetArgVerbatim() const
{
- if (this->Arg.second)
+ if (this->Arg.second) {
return Quote + this->Arg.first + Quote;
- else
- return this->Arg.first;
+ }
+ return this->Arg.first;
}
const std::string& cmVisualStudioSlnParser::ParsedLine::GetValue(
size_t idxValue) const
{
- if (idxValue < this->Values.size())
+ if (idxValue < this->Values.size()) {
return this->Values[idxValue].first;
- else
- return BadString;
+ }
+ return BadString;
}
std::string cmVisualStudioSlnParser::ParsedLine::GetValueVerbatim(
@@ -100,12 +100,12 @@ std::string cmVisualStudioSlnParser::ParsedLine::GetValueVerbatim(
{
if (idxValue < this->Values.size()) {
const StringData& data = this->Values[idxValue];
- if (data.second)
+ if (data.second) {
return Quote + data.first + Quote;
- else
- return data.first;
- } else
- return BadString;
+ }
+ return data.first;
+ }
+ return BadString;
}
class cmVisualStudioSlnParser::State
@@ -140,17 +140,17 @@ private:
std::stack<FileState> Stack;
std::string EndIgnoreTag;
DataGroupSet RequestedData;
- size_t CurrentLine;
+ size_t CurrentLine = 0;
void IgnoreUntilTag(const std::string& endTag);
};
cmVisualStudioSlnParser::State::State(DataGroupSet requestedData)
: RequestedData(requestedData)
- , CurrentLine(0)
{
- if (this->RequestedData.test(DataGroupProjectDependenciesBit))
+ if (this->RequestedData.test(DataGroupProjectDependenciesBit)) {
this->RequestedData.set(DataGroupProjectsBit);
+ }
this->Stack.push(FileStateStart);
}
@@ -206,7 +206,7 @@ bool cmVisualStudioSlnParser::State::Process(
this->Stack.push(FileStateTopLevel);
break;
case FileStateTopLevel:
- if (line.GetTag().compare("Project") == 0) {
+ if (line.GetTag() == "Project") {
if (line.GetValueCount() != 3) {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
@@ -218,14 +218,15 @@ bool cmVisualStudioSlnParser::State::Process(
return false;
}
this->Stack.push(FileStateProject);
- } else
+ } else {
this->IgnoreUntilTag("EndProject");
- } else if (line.GetTag().compare("Global") == 0) {
+ }
+ } else if (line.GetTag() == "Global") {
this->Stack.push(FileStateGlobal);
- } else if (line.GetTag().compare("VisualStudioVersion") == 0) {
+ } else if (line.GetTag() == "VisualStudioVersion") {
output.SetVisualStudioVersion(line.GetValue(0));
- } else if (line.GetTag().compare("MinimumVisualStudioVersion") == 0) {
+ } else if (line.GetTag() == "MinimumVisualStudioVersion") {
output.SetMinimumVisualStudioVersion(line.GetValue(0));
} else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
@@ -233,69 +234,75 @@ bool cmVisualStudioSlnParser::State::Process(
}
break;
case FileStateProject:
- if (line.GetTag().compare("EndProject") == 0)
+ if (line.GetTag() == "EndProject") {
this->Stack.pop();
- else if (line.GetTag().compare("ProjectSection") == 0) {
- if (line.GetArg().compare("ProjectDependencies") == 0 &&
- line.GetValue(0).compare("postProject") == 0) {
- if (this->RequestedData.test(DataGroupProjectDependenciesBit))
+ } else if (line.GetTag() == "ProjectSection") {
+ if (line.GetArg() == "ProjectDependencies" &&
+ line.GetValue(0) == "postProject") {
+ if (this->RequestedData.test(DataGroupProjectDependenciesBit)) {
this->Stack.push(FileStateProjectDependencies);
- else
+ } else {
this->IgnoreUntilTag("EndProjectSection");
- } else
+ }
+ } else {
this->IgnoreUntilTag("EndProjectSection");
+ }
} else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
}
break;
case FileStateProjectDependencies:
- if (line.GetTag().compare("EndProjectSection") == 0)
+ if (line.GetTag() == "EndProjectSection") {
this->Stack.pop();
- else if (line.IsKeyValuePair())
+ } else if (line.IsKeyValuePair()) {
// implement dependency storing here, once needed
;
- else {
+ } else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
}
break;
case FileStateGlobal:
- if (line.GetTag().compare("EndGlobal") == 0)
+ if (line.GetTag() == "EndGlobal") {
this->Stack.pop();
- else if (line.GetTag().compare("GlobalSection") == 0) {
- if (line.GetArg().compare("SolutionConfigurationPlatforms") == 0 &&
- line.GetValue(0).compare("preSolution") == 0) {
- if (this->RequestedData.test(DataGroupSolutionConfigurationsBit))
+ } else if (line.GetTag() == "GlobalSection") {
+ if (line.GetArg() == "SolutionConfigurationPlatforms" &&
+ line.GetValue(0) == "preSolution") {
+ if (this->RequestedData.test(DataGroupSolutionConfigurationsBit)) {
this->Stack.push(FileStateSolutionConfigurations);
- else
+ } else {
this->IgnoreUntilTag("EndGlobalSection");
- } else if (line.GetArg().compare("ProjectConfigurationPlatforms") ==
- 0 &&
- line.GetValue(0).compare("postSolution") == 0) {
- if (this->RequestedData.test(DataGroupProjectConfigurationsBit))
+ }
+ } else if (line.GetArg() == "ProjectConfigurationPlatforms" &&
+ line.GetValue(0) == "postSolution") {
+ if (this->RequestedData.test(DataGroupProjectConfigurationsBit)) {
this->Stack.push(FileStateProjectConfigurations);
- else
+ } else {
this->IgnoreUntilTag("EndGlobalSection");
- } else if (line.GetArg().compare("NestedProjects") == 0 &&
- line.GetValue(0).compare("preSolution") == 0) {
- if (this->RequestedData.test(DataGroupSolutionFiltersBit))
+ }
+ } else if (line.GetArg() == "NestedProjects" &&
+ line.GetValue(0) == "preSolution") {
+ if (this->RequestedData.test(DataGroupSolutionFiltersBit)) {
this->Stack.push(FileStateSolutionFilters);
- else
+ } else {
this->IgnoreUntilTag("EndGlobalSection");
- } else if (this->RequestedData.test(DataGroupGenericGlobalSectionsBit))
+ }
+ } else if (this->RequestedData.test(
+ DataGroupGenericGlobalSectionsBit)) {
this->Stack.push(FileStateGlobalSection);
- else
+ } else {
this->IgnoreUntilTag("EndGlobalSection");
+ }
} else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
}
break;
case FileStateSolutionConfigurations:
- if (line.GetTag().compare("EndGlobalSection") == 0)
+ if (line.GetTag() == "EndGlobalSection") {
this->Stack.pop();
- else if (line.IsKeyValuePair()) {
+ } else if (line.IsKeyValuePair()) {
output.AddConfiguration(line.GetValue(0));
} else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
@@ -303,9 +310,9 @@ bool cmVisualStudioSlnParser::State::Process(
}
break;
case FileStateProjectConfigurations:
- if (line.GetTag().compare("EndGlobalSection") == 0)
+ if (line.GetTag() == "EndGlobalSection") {
this->Stack.pop();
- else if (line.IsKeyValuePair()) {
+ } else if (line.IsKeyValuePair()) {
std::vector<std::string> tagElements =
cmSystemTools::SplitString(line.GetTag(), '.');
if (tagElements.size() != 3 && tagElements.size() != 4) {
@@ -324,7 +331,7 @@ bool cmVisualStudioSlnParser::State::Process(
return false;
}
- if (activeBuild.compare("ActiveCfg") == 0) {
+ if (activeBuild == "ActiveCfg") {
projectEntry->AddProjectConfiguration(solutionConfiguration,
line.GetValue(0));
}
@@ -334,23 +341,23 @@ bool cmVisualStudioSlnParser::State::Process(
}
break;
case FileStateSolutionFilters:
- if (line.GetTag().compare("EndGlobalSection") == 0)
+ if (line.GetTag() == "EndGlobalSection") {
this->Stack.pop();
- else if (line.IsKeyValuePair())
+ } else if (line.IsKeyValuePair()) {
// implement filter storing here, once needed
;
- else {
+ } else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
}
break;
case FileStateGlobalSection:
- if (line.GetTag().compare("EndGlobalSection") == 0)
+ if (line.GetTag() == "EndGlobalSection") {
this->Stack.pop();
- else if (line.IsKeyValuePair())
+ } else if (line.IsKeyValuePair()) {
// implement section storing here, once needed
;
- else {
+ } else {
result.SetError(ResultErrorInputStructure, this->GetCurrentLine());
return false;
}
@@ -385,11 +392,7 @@ void cmVisualStudioSlnParser::State::IgnoreUntilTag(const std::string& endTag)
this->EndIgnoreTag = endTag;
}
-cmVisualStudioSlnParser::ResultData::ResultData()
- : Result(ResultOK)
- , ResultLine(0)
-{
-}
+cmVisualStudioSlnParser::ResultData::ResultData() = default;
void cmVisualStudioSlnParser::ResultData::Clear()
{
@@ -487,34 +490,41 @@ bool cmVisualStudioSlnParser::ParseImpl(std::istream& input, cmSlnData& output,
{
std::string line;
// Does the .sln start with a Byte Order Mark?
- if (!this->ParseBOM(input, line, state))
+ if (!this->ParseBOM(input, line, state)) {
return false;
+ }
do {
line = cmTrimWhitespace(line);
- if (line.empty())
+ if (line.empty()) {
continue;
+ }
ParsedLine parsedLine;
switch (state.NextLineFormat()) {
case LineMultiValueTag:
- if (!this->ParseMultiValueTag(line, parsedLine, state))
+ if (!this->ParseMultiValueTag(line, parsedLine, state)) {
return false;
+ }
break;
case LineSingleValueTag:
- if (!this->ParseSingleValueTag(line, parsedLine, state))
+ if (!this->ParseSingleValueTag(line, parsedLine, state)) {
return false;
+ }
break;
case LineKeyValuePair:
- if (!this->ParseKeyValuePair(line, parsedLine, state))
+ if (!this->ParseKeyValuePair(line, parsedLine, state)) {
return false;
+ }
break;
case LineVerbatim:
parsedLine.CopyVerbatim(line);
break;
}
- if (parsedLine.IsComment())
+ if (parsedLine.IsComment()) {
continue;
- if (!state.Process(parsedLine, output, this->LastResult))
+ }
+ if (!state.Process(parsedLine, output, this->LastResult)) {
return false;
+ }
} while (state.ReadLine(input, line));
return state.Finished(this->LastResult);
}
@@ -533,8 +543,9 @@ bool cmVisualStudioSlnParser::ParseBOM(std::istream& input, std::string& line,
this->LastResult.SetError(ResultErrorReadingInput, 1);
return false;
}
- if (!this->LastResult.HadBOM)
+ if (!this->LastResult.HadBOM) {
line = bom + line; // it wasn't a BOM, prepend it to first line
+ }
return true;
}
@@ -544,9 +555,10 @@ bool cmVisualStudioSlnParser::ParseMultiValueTag(const std::string& line,
{
size_t idxEqualSign = line.find('=');
auto fullTag = cm::string_view(line).substr(0, idxEqualSign);
- if (!this->ParseTag(fullTag, parsedLine, state))
+ if (!this->ParseTag(fullTag, parsedLine, state)) {
return false;
- if (idxEqualSign != line.npos) {
+ }
+ if (idxEqualSign != std::string::npos) {
size_t idxFieldStart = idxEqualSign + 1;
if (idxFieldStart < line.size()) {
size_t idxParsing = idxFieldStart;
@@ -554,24 +566,27 @@ bool cmVisualStudioSlnParser::ParseMultiValueTag(const std::string& line,
for (;;) {
idxParsing = line.find_first_of(",\"", idxParsing);
bool fieldOver = false;
- if (idxParsing == line.npos) {
+ if (idxParsing == std::string::npos) {
fieldOver = true;
if (inQuotes) {
this->LastResult.SetError(ResultErrorInputStructure,
state.GetCurrentLine());
return false;
}
- } else if (line[idxParsing] == ',' && !inQuotes)
+ } else if (line[idxParsing] == ',' && !inQuotes) {
fieldOver = true;
- else if (line[idxParsing] == '"')
+ } else if (line[idxParsing] == '"') {
inQuotes = !inQuotes;
+ }
if (fieldOver) {
if (!this->ParseValue(
line.substr(idxFieldStart, idxParsing - idxFieldStart),
- parsedLine))
+ parsedLine)) {
return false;
- if (idxParsing == line.npos)
+ }
+ if (idxParsing == std::string::npos) {
break; // end of last field
+ }
idxFieldStart = idxParsing + 1;
}
++idxParsing;
@@ -587,11 +602,13 @@ bool cmVisualStudioSlnParser::ParseSingleValueTag(const std::string& line,
{
size_t idxEqualSign = line.find('=');
auto fullTag = cm::string_view(line).substr(0, idxEqualSign);
- if (!this->ParseTag(fullTag, parsedLine, state))
+ if (!this->ParseTag(fullTag, parsedLine, state)) {
return false;
- if (idxEqualSign != line.npos) {
- if (!this->ParseValue(line.substr(idxEqualSign + 1), parsedLine))
+ }
+ if (idxEqualSign != std::string::npos) {
+ if (!this->ParseValue(line.substr(idxEqualSign + 1), parsedLine)) {
return false;
+ }
}
return true;
}
@@ -601,7 +618,7 @@ bool cmVisualStudioSlnParser::ParseKeyValuePair(const std::string& line,
State& /*state*/)
{
size_t idxEqualSign = line.find('=');
- if (idxEqualSign == line.npos) {
+ if (idxEqualSign == std::string::npos) {
parsedLine.CopyVerbatim(line);
return true;
}
@@ -636,8 +653,9 @@ bool cmVisualStudioSlnParser::ParseTag(cm::string_view fullTag,
return false;
}
parsedLine.SetQuotedArg(arg.substr(1, arg.size() - 2));
- } else
+ } else {
parsedLine.SetArg(arg);
+ }
return true;
}
@@ -645,11 +663,12 @@ bool cmVisualStudioSlnParser::ParseValue(const std::string& value,
ParsedLine& parsedLine)
{
const std::string& trimmed = cmTrimWhitespace(value);
- if (trimmed.empty())
+ if (trimmed.empty()) {
parsedLine.AddValue(trimmed);
- else if (trimmed.front() == '"' && trimmed.back() == '"')
+ } else if (trimmed.front() == '"' && trimmed.back() == '"') {
parsedLine.AddQuotedValue(trimmed.substr(1, trimmed.size() - 2));
- else
+ } else {
parsedLine.AddValue(trimmed);
+ }
return true;
}