From df85caf71f8f629c6c6a58d0cb31ef8df13cc058 Mon Sep 17 00:00:00 2001 From: john30 Date: Mon, 29 Dec 2014 22:31:22 +0100 Subject: [PATCH] ignore case in class and name --- src/lib/ebus/message.cpp | 29 +++++++++++++++++++++-------- src/lib/ebus/message.h | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 56e07bdb..34233423 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include using namespace std; @@ -345,6 +347,13 @@ bool Message::isLessPollWeight(const Message* other) } +string strtolower(const string& str) +{ + string ret(str); + transform(ret.begin(), ret.end(), ret.begin(), ::tolower); + return ret; +} + result_t MessageMap::add(Message* message) { unsigned long long key = message->getKey(); @@ -354,8 +363,8 @@ result_t MessageMap::add(Message* message) } bool isPassive = message->isPassive(); bool isSet = message->isSet(); - string clazz = message->getClass(); - string name = message->getName(); + string clazz = strtolower(message->getClass()); + string name = strtolower(message->getName()); string nameKey = string(isPassive ? "P" : (isSet ? "W" : "R")) + clazz + FIELD_SEPARATOR + name; map::iterator nameIt = m_messagesByName.find(nameKey); if (nameIt != m_messagesByName.end()) { @@ -417,12 +426,14 @@ result_t MessageMap::addFromFile(vector::iterator& begin, const vector::iterator it = m_messagesByName.find(key); @@ -438,6 +449,8 @@ deque MessageMap::findAll(const string& clazz, const string& name, con { deque ret; + string lclass = strtolower(clazz); + string lname = strtolower(name); bool checkClass = clazz.length() > 0; bool checkName = name.length() > 0; bool checkPb = pb >= 0; @@ -446,13 +459,13 @@ deque MessageMap::findAll(const string& clazz, const string& name, con continue; Message* message = it->second; if (checkClass == true) { - string check = message->getClass(); - if (completeMatch ? (check != clazz) : (check.find(clazz) == check.npos)) + string check = strtolower(message->getClass()); + if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos)) continue; } if (checkName == true) { - string check = message->getName(); - if (completeMatch ? (check != name) : (check.find(name) == check.npos)) + string check = strtolower(message->getName()); + if (completeMatch ? (check != lname) : (check.find(lname) == check.npos)) continue; } if (checkPb == true && message->getId()[0] != pb) diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index f882cafb..792aeeb6 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -384,7 +384,7 @@ private: /** the number of distinct passive @a Message instances stored in @a m_messagesByKey. */ size_t m_passiveMessageCount; - /** the known @a Message instances by class and name. */ + /** the known @a Message instances by lowercase class and name. */ map m_messagesByName; /** the known @a Message instances by key. */