aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkglib_helpers.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2016-09-18 20:50:08 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2016-09-18 20:54:03 -0700
commitccca198c1b1730b0241911cb56dc8e3504958b2a (patch)
treea2dd9b8b087a09afdcecc5cbb3377bed15127eb2 /toolsrc/src/vcpkglib_helpers.cpp
downloadvcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.tar.gz
vcpkg-ccca198c1b1730b0241911cb56dc8e3504958b2a.zip
Initial commit
Diffstat (limited to 'toolsrc/src/vcpkglib_helpers.cpp')
-rw-r--r--toolsrc/src/vcpkglib_helpers.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp
new file mode 100644
index 000000000..e947dc647
--- /dev/null
+++ b/toolsrc/src/vcpkglib_helpers.cpp
@@ -0,0 +1,50 @@
+#include "vcpkg_Checks.h"
+#include "vcpkglib_helpers.h"
+#include <unordered_map>
+
+namespace vcpkg {namespace details
+{
+ void optional_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, const std::string& fieldname)
+ {
+ auto it = fields.find(fieldname);
+ if (it == fields.end())
+ {
+ out.clear();
+ }
+
+ else
+ {
+ out = it->second;
+ }
+ };
+
+ void required_field(const std::unordered_map<std::string, std::string>& fields, std::string& out, 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;
+ };
+
+ void parse_depends(const std::string& depends_string, std::vector<std::string>& out)
+ {
+ size_t cur = 0;
+ do
+ {
+ auto pos = depends_string.find(',', cur);
+ if (pos == std::string::npos)
+ {
+ out.push_back(depends_string.substr(cur));
+ return;
+ }
+ 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);
+ }
+}}