summaryrefslogtreecommitdiff
path: root/kms++util/src/helpers.cpp
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 22:39:24 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 22:41:01 +0300
commit3c6ea25bcfafc513560c9e8a4baaf211bec2750c (patch)
treeed8b174bb669c0012af28338def51efd808e61fb /kms++util/src/helpers.cpp
parent9916712a62169606d845510028a3ea6f84bd442f (diff)
kms++util: split to subdirs
Diffstat (limited to 'kms++util/src/helpers.cpp')
-rw-r--r--kms++util/src/helpers.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/kms++util/src/helpers.cpp b/kms++util/src/helpers.cpp
new file mode 100644
index 0000000..2bf3a4f
--- /dev/null
+++ b/kms++util/src/helpers.cpp
@@ -0,0 +1,43 @@
+#include <kms++util/kms++util.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;
+}
+
+}