mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-19 02:53:02 +08:00
vcpkglib_helpers: Return output instead of accepting it as arg
This commit is contained in:
parent
61cea6b1dc
commit
a098ecad03
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
namespace vcpkg {namespace details
|
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);
|
||||||
}}
|
}}
|
||||||
|
@ -8,25 +8,24 @@ namespace vcpkg
|
|||||||
{
|
{
|
||||||
BinaryParagraph::BinaryParagraph() = default;
|
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");
|
target_triplet.value = required_field(fields, "Architecture");
|
||||||
required_field(fields, version, "Version");
|
|
||||||
required_field(fields, target_triplet.value, "Architecture");
|
|
||||||
{
|
{
|
||||||
std::string multi_arch;
|
std::string multi_arch = required_field(fields, "Multi-Arch");
|
||||||
required_field(fields, multi_arch, "Multi-Arch");
|
|
||||||
Checks::check_throw(multi_arch == "same", "Multi-Arch must be 'same' but was %s", 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;
|
std::string deps = optional_field(fields, "Depends");
|
||||||
optional_field(fields, deps, "Depends");
|
|
||||||
if (!deps.empty())
|
if (!deps.empty())
|
||||||
{
|
{
|
||||||
depends.clear();
|
this->depends.clear();
|
||||||
parse_depends(deps, depends);
|
this->depends = parse_depends(deps);
|
||||||
}
|
}
|
||||||
optional_field(fields, maintainer, "Maintainer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)
|
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet)
|
||||||
|
@ -5,17 +5,16 @@ using namespace vcpkg::details;
|
|||||||
|
|
||||||
vcpkg::SourceParagraph::SourceParagraph() = default;
|
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");
|
std::string deps = optional_field(fields, "Build-Depends");
|
||||||
required_field(fields, version, "Version");
|
|
||||||
optional_field(fields, description, "Description");
|
|
||||||
std::string deps;
|
|
||||||
optional_field(fields, deps, "Build-Depends");
|
|
||||||
if (!deps.empty())
|
if (!deps.empty())
|
||||||
{
|
{
|
||||||
depends.clear();
|
this->depends.clear();
|
||||||
parse_depends(deps, depends);
|
this->depends = parse_depends(deps);
|
||||||
}
|
};
|
||||||
optional_field(fields, maintainer, "Maintainer");
|
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ namespace vcpkg
|
|||||||
StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields)
|
StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields)
|
||||||
: package(fields)
|
: package(fields)
|
||||||
{
|
{
|
||||||
std::string status_field;
|
std::string status_field = required_field(fields, "Status");
|
||||||
required_field(fields, status_field, "Status");
|
|
||||||
|
|
||||||
auto b = status_field.begin();
|
auto b = status_field.begin();
|
||||||
auto mark = b;
|
auto mark = b;
|
||||||
|
@ -4,29 +4,28 @@
|
|||||||
|
|
||||||
namespace vcpkg {namespace details
|
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);
|
auto it = fields.find(fieldname);
|
||||||
if (it == fields.end())
|
if (it == fields.end())
|
||||||
{
|
{
|
||||||
out.clear();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
return it->second;
|
||||||
{
|
|
||||||
out = 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);
|
auto it = fields.find(fieldname);
|
||||||
vcpkg::Checks::check_throw(it != fields.end(), "Required field not present: %s", 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;
|
size_t cur = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -34,17 +33,21 @@ namespace vcpkg {namespace details
|
|||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
{
|
{
|
||||||
out.push_back(depends_string.substr(cur));
|
out.push_back(depends_string.substr(cur));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
out.push_back(depends_string.substr(cur, pos - cur));
|
out.push_back(depends_string.substr(cur, pos - cur));
|
||||||
|
|
||||||
// skip comma and space
|
// skip comma and space
|
||||||
++pos;
|
++pos;
|
||||||
if (depends_string[pos] == ' ')
|
if (depends_string[pos] == ' ')
|
||||||
|
{
|
||||||
++pos;
|
++pos;
|
||||||
|
}
|
||||||
|
|
||||||
cur = pos;
|
cur = pos;
|
||||||
}
|
}
|
||||||
while (cur != std::string::npos);
|
while (cur != std::string::npos);
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user