From 3c6ea25bcfafc513560c9e8a4baaf211bec2750c Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 11 Jun 2016 22:39:24 +0300 Subject: kms++util: split to subdirs --- kms++util/src/helpers.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 kms++util/src/helpers.cpp (limited to 'kms++util/src/helpers.cpp') 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 + +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; +} + +} -- cgit v1.2.3