diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-06-03 21:41:41 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-06-05 22:09:39 +0300 |
commit | dce7c0afa22ca6568bbf6cca6a9cd669ef8b4b28 (patch) | |
tree | 91b35552bd0718d29c72ba8da944bb4e3d82f323 /libkms++util/helpers.cpp | |
parent | 4864a696159a510053daf30e3bf96a3b255bb3ed (diff) |
util: add helpers
Diffstat (limited to 'libkms++util/helpers.cpp')
-rw-r--r-- | libkms++util/helpers.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libkms++util/helpers.cpp b/libkms++util/helpers.cpp new file mode 100644 index 0000000..4aa3194 --- /dev/null +++ b/libkms++util/helpers.cpp @@ -0,0 +1,44 @@ +#include "kms++util.h" +#include "strhelpers.h" + +using namespace std; + +namespace kms { + +Connector* resolve_connector(Card& card, const string& str) +{ + if (str.length() == 0) + return nullptr; + + auto connectors = card.get_connectors(); + + if (str[0] == '@') { + char* endptr; + unsigned id = strtoul(str.c_str() + 1, &endptr, 10); + if (*endptr == 0) { + Connector* c = card.get_connector(id); + if (!c) + return nullptr; + else + return c; + } + } else { + char* endptr; + unsigned idx = strtoul(str.c_str(), &endptr, 10); + if (*endptr == 0) { + if (idx >= connectors.size()) + return nullptr; + else + return connectors[idx]; + } + } + + for (Connector* conn : connectors) { + if (to_lower(conn->fullname()).find(to_lower(str)) != string::npos) + return conn; + } + + return nullptr; +} + +} |