vcpkg/toolsrc/src/vcpkglib_helpers.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2016-09-19 11:50:08 +08:00
#include "vcpkg_Checks.h"
#include "vcpkglib_helpers.h"
#include <unordered_map>
namespace vcpkg {namespace details
{
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())
{
return std::string();
2016-09-19 11:50:08 +08:00
}
return it->second;
2016-09-19 11:50:08 +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);
return it->second;
2016-09-19 11:50:08 +08:00
};
std::vector<std::string> parse_depends(const std::string& depends_string)
2016-09-19 11:50:08 +08:00
{
if (depends_string.empty())
{
return {};
}
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));
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-19 11:50:08 +08:00
++pos;
}
2016-09-19 11:50:08 +08:00
cur = pos;
}
while (cur != std::string::npos);
return out;
2016-09-19 11:50:08 +08:00
}
}}