2016-09-19 11:50:08 +08:00
|
|
|
#include "vcpkg_Checks.h"
|
|
|
|
#include "vcpkglib_helpers.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace vcpkg {namespace details
|
|
|
|
{
|
2016-09-27 12:12:04 +08:00
|
|
|
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
auto it = fields.find(fieldname);
|
|
|
|
if (it == fields.end())
|
|
|
|
{
|
2016-09-27 12:12:04 +08:00
|
|
|
return std::string();
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2016-09-27 12:12:04 +08:00
|
|
|
return it->second;
|
2016-09-19 11:50:08 +08:00
|
|
|
};
|
|
|
|
|
2016-09-27 12:12:04 +08:00
|
|
|
std::string required_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
auto it = fields.find(fieldname);
|
2016-11-03 08:47:25 +08:00
|
|
|
vcpkg::Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname);
|
2016-09-27 12:12:04 +08:00
|
|
|
return it->second;
|
2016-09-19 11:50:08 +08:00
|
|
|
};
|
|
|
|
|
2016-09-27 12:12:04 +08:00
|
|
|
std::vector<std::string> parse_depends(const std::string& depends_string)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-03 10:39:45 +08:00
|
|
|
if (depends_string.empty())
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2016-09-27 12:12:04 +08:00
|
|
|
std::vector<std::string> out;
|
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
size_t cur = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
auto pos = depends_string.find(',', cur);
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
|
|
|
out.push_back(depends_string.substr(cur));
|
2016-09-27 12:12:04 +08:00
|
|
|
break;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
out.push_back(depends_string.substr(cur, pos - cur));
|
|
|
|
|
|
|
|
// skip comma and space
|
|
|
|
++pos;
|
|
|
|
if (depends_string[pos] == ' ')
|
2016-09-27 12:12:04 +08:00
|
|
|
{
|
2016-09-19 11:50:08 +08:00
|
|
|
++pos;
|
2016-09-27 12:12:04 +08:00
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
cur = pos;
|
|
|
|
}
|
|
|
|
while (cur != std::string::npos);
|
2016-09-27 12:12:04 +08:00
|
|
|
|
|
|
|
return out;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}}
|