2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
#include "vcpkg_Checks.h"
|
|
|
|
#include "vcpkglib_helpers.h"
|
|
|
|
|
2017-01-06 06:25:50 +08:00
|
|
|
namespace vcpkg::details
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
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-11-03 11:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname)
|
|
|
|
{
|
|
|
|
auto it = fields->find(fieldname);
|
|
|
|
if (it == fields->end())
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string value = std::move(it->second);
|
|
|
|
fields->erase(it);
|
|
|
|
return value;
|
|
|
|
}
|
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 11:26:52 +08:00
|
|
|
Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname);
|
2016-09-27 12:12:04 +08:00
|
|
|
return it->second;
|
2016-11-03 11:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname)
|
|
|
|
{
|
|
|
|
auto it = fields->find(fieldname);
|
|
|
|
Checks::check_exit(it != fields->end(), "Required field not present: %s", fieldname);
|
|
|
|
|
|
|
|
const std::string value = std::move(it->second);
|
|
|
|
fields->erase(it);
|
|
|
|
return value;
|
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2016-11-08 09:37:08 +08:00
|
|
|
std::string shorten_description(const std::string& desc)
|
|
|
|
{
|
|
|
|
auto simple_desc = std::regex_replace(desc.substr(0, 49), std::regex("\\n( |\\t)?"), "");
|
|
|
|
if (desc.size() > 49)
|
|
|
|
simple_desc.append("...");
|
|
|
|
return simple_desc;
|
|
|
|
}
|
2017-01-06 06:25:50 +08:00
|
|
|
}
|