trim whitespace from the Notification names - Related to #1797

This commit is contained in:
Justin Hammond 2019-05-17 19:59:01 +08:00
parent 6f7b02b887
commit f90e1cf657
3 changed files with 60 additions and 7 deletions

View file

@ -30,6 +30,7 @@
#include "tinyxml.h"
#include "Options.h"
#include "Utils.h"
#include "platform/Log.h"
using namespace OpenZWave;
@ -102,6 +103,7 @@ void NotificationCCTypes::ReadXML
continue;
}
nt->name = str;
trim(nt->name);
TiXmlElement const* AlarmEventElement = AlarmTypeElement->FirstChildElement();
while (AlarmEventElement) {
str = AlarmEventElement->Value();
@ -128,7 +130,7 @@ void NotificationCCTypes::ReadXML
continue;
}
ne->name = str;
trim(ne->name);
TiXmlElement const* nextElement = AlarmEventElement->FirstChildElement();
while (nextElement) {
str = nextElement->Value();
@ -208,7 +210,7 @@ void NotificationCCTypes::ReadXML
continue;
}
aep->name = str;
trim(aep->name);
if (ne->EventParams.find(aep->id) == ne->EventParams.end())
ne->EventParams[aep->id] = aep;
else {
@ -237,7 +239,7 @@ void NotificationCCTypes::ReadXML
AlarmTypeElement = AlarmTypeElement->NextSiblingElement();
}
Log::Write(LogLevel_Info, "Loaded %s With Revision %d", pDoc->GetUserData(), m_revision);
#if 0
#if 1
std::cout << "NotificationCCTypes" << std::endl;
for (std::map<uint32, NotificationCCTypes::NotificationTypes *>::iterator it = Notifications.begin(); it != Notifications.end(); it++) {
std::cout << "\tAlarmType:" << it->first << " Name: " << it->second->name << std::endl;
@ -251,6 +253,7 @@ void NotificationCCTypes::ReadXML
}
}
}
exit(0);
#endif
}

View file

@ -64,7 +64,7 @@ string OpenZWave::ToLower
// Remove WhiteSpaces from the begining and end of a string
//-----------------------------------------------------------------------------
std::string &OpenZWave::trim
std::string &OpenZWave::removewhitespace
(
std::string &s
)
@ -87,6 +87,21 @@ std::string &OpenZWave::trim
return s;
}
std::string& OpenZWave::ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::ptr_fun<int, int>(std::isgraph)));
return s;
}
std::string& OpenZWave::rtrim(std::string& s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
std::ptr_fun<int, int>(std::isgraph)).base(), s.end());
return s;
}
std::string& OpenZWave::trim(std::string& s) {
return OpenZWave::ltrim(OpenZWave::rtrim(s));
}
//-----------------------------------------------------------------------------
// <OpenZWave::split>
// Split a String into a vector, seperated by anything specified in seperators.
@ -199,4 +214,6 @@ struct tm *localtime_r(time_t *_clock, struct tm *_result)
_localtime64_s(_result, _clock);
return _result;
}
#endif
#endif

View file

@ -65,11 +65,44 @@ namespace OpenZWave
void split (std::vector<std::string>& lst, const std::string& input, const std::string& separators, bool remove_empty = true);
/**
* Trim Whitespace from the start and end of a string.
* remove all Whitespace from of a string.
* \param s the string to trim
* \return the trimmed string
*/
std::string &trim ( std::string &s );
std::string &removewhitespace ( std::string &s );
/**
* @brief Left Trim
*
* Trims whitespace from the left end of the provided std::string
*
* @param[out] s The std::string to trim
*
* @return The modified std::string&
*/
std::string& ltrim(std::string& s);
/**
* @brief Right Trim
*
* Trims whitespace from the right end of the provided std::string
*
* @param[out] s The std::string to trim
*
* @return The modified std::string&
*/
std::string& rtrim(std::string& s);
/**
* @brief Trim
*
* Trims whitespace from both ends of the provided std::string
*
* @param[out] s The std::string to trim
*
* @return The modified std::string&
*/
std::string& trim(std::string& s);
void PrintHex(std::string prefix, uint8_t const *data, uint32 const length);