vcpkglib_helpers: Return output instead of accepting it as arg

This commit is contained in:
Alexander Karatarakis 2016-09-26 21:12:04 -07:00
parent 61cea6b1dc
commit a098ecad03
5 changed files with 37 additions and 37 deletions

View File

@ -4,9 +4,9 @@
namespace vcpkg {namespace details
{
void optional_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, const std::string& fieldname);
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname);
void required_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, const std::string& fieldname);
std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname);
void parse_depends(const std::string& depends_string, std::vector<std::string>& out);
std::vector<std::string> parse_depends(const std::string& depends_string);
}}

View File

@ -8,25 +8,24 @@ namespace vcpkg
{
BinaryParagraph::BinaryParagraph() = default;
BinaryParagraph::BinaryParagraph(const std::unordered_map<std::string, std::string>& fields)
BinaryParagraph::BinaryParagraph(const std::unordered_map<std::string, std::string>& fields) :
name(required_field(fields, "Package")),
version(required_field(fields, "Version")),
description(optional_field(fields, "Description")),
maintainer(optional_field(fields, "Maintainer"))
{
details::required_field(fields, name, "Package");
required_field(fields, version, "Version");
required_field(fields, target_triplet.value, "Architecture");
target_triplet.value = required_field(fields, "Architecture");
{
std::string multi_arch;
required_field(fields, multi_arch, "Multi-Arch");
std::string multi_arch = required_field(fields, "Multi-Arch");
Checks::check_throw(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch);
}
optional_field(fields, description, "Description");
std::string deps;
optional_field(fields, deps, "Depends");
std::string deps = optional_field(fields, "Depends");
if (!deps.empty())
{
depends.clear();
parse_depends(deps, depends);
this->depends.clear();
this->depends = parse_depends(deps);
}
optional_field(fields, maintainer, "Maintainer");
}
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)

View File

@ -5,17 +5,16 @@ using namespace vcpkg::details;
vcpkg::SourceParagraph::SourceParagraph() = default;
vcpkg::SourceParagraph::SourceParagraph(const std::unordered_map<std::string, std::string>& fields)
vcpkg::SourceParagraph::SourceParagraph(const std::unordered_map<std::string, std::string>& fields):
name(required_field(fields, "Source")),
version(required_field(fields, "Version")),
description(optional_field(fields, "Description")),
maintainer(optional_field(fields, "Maintainer"))
{
required_field(fields, name, "Source");
required_field(fields, version, "Version");
optional_field(fields, description, "Description");
std::string deps;
optional_field(fields, deps, "Build-Depends");
std::string deps = optional_field(fields, "Build-Depends");
if (!deps.empty())
{
depends.clear();
parse_depends(deps, depends);
}
optional_field(fields, maintainer, "Maintainer");
this->depends.clear();
this->depends = parse_depends(deps);
};
}

View File

@ -19,8 +19,7 @@ namespace vcpkg
StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields)
: package(fields)
{
std::string status_field;
required_field(fields, status_field, "Status");
std::string status_field = required_field(fields, "Status");
auto b = status_field.begin();
auto mark = b;

View File

@ -4,29 +4,28 @@
namespace vcpkg {namespace details
{
void optional_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, const std::string& fieldname)
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
{
auto it = fields.find(fieldname);
if (it == fields.end())
{
out.clear();
return std::string();
}
else
{
out = it->second;
}
return it->second;
};
void required_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, const std::string& fieldname)
std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
{
auto it = fields.find(fieldname);
vcpkg::Checks::check_throw(it != fields.end(), "Required field not present: %s", fieldname);
out = it->second;
return it->second;
};
void parse_depends(const std::string& depends_string, std::vector<std::string>& out)
std::vector<std::string> parse_depends(const std::string& depends_string)
{
std::vector<std::string> out;
size_t cur = 0;
do
{
@ -34,17 +33,21 @@ namespace vcpkg {namespace details
if (pos == std::string::npos)
{
out.push_back(depends_string.substr(cur));
return;
break;
}
out.push_back(depends_string.substr(cur, pos - cur));
// skip comma and space
++pos;
if (depends_string[pos] == ' ')
{
++pos;
}
cur = pos;
}
while (cur != std::string::npos);
return out;
}
}}