#include "Defs.h"
#include "Utils.h"
using namespace OpenZWave;
string OpenZWave::ToUpper
(
string const& _str
)
{
string upper = _str;
transform( upper.begin(), upper.end(), upper.begin(), ::toupper );
return upper;
}
string OpenZWave::ToLower
(
string const& _str
)
{
string lower = _str;
transform( lower.begin(), lower.end(), lower.begin(), ::tolower );
return lower;
}
std::string &OpenZWave::trim
(
std::string &s
)
{
if(s.size() == 0)
{
return s;
}
int val = 0;
for (size_t cur = 0; cur < s.size(); cur++)
{
if(s[cur] != ' ' && isalnum(s[cur]))
{
s[val] = s[cur];
val++;
}
}
s.resize(val);
return s;
}
void OpenZWave::split
(
std::vector<std::string>& lst,
const std::string& input,
const std::string& separators,
bool remove_empty
)
{
std::ostringstream word;
for (size_t n = 0; n < input.size(); ++n)
{
if (std::string::npos == separators.find(input[n]))
word << input[n];
else
{
if (!word.str().empty() || !remove_empty)
lst.push_back(word.str());
word.str("");
}
}
if (!word.str().empty() || !remove_empty)
lst.push_back(word.str());
}
void OpenZWave::PrintHex(std::string prefix, uint8_t const *data, uint32 const length) {
Log::Write(LogLevel_Info, "%s: %s", prefix.c_str(), PktToString(data, length).c_str());
}
string OpenZWave::PktToString(uint8 const *data, uint32 const length) {
char byteStr[5];
std::string str;
for( uint32 i=0; i<length; ++i )
{
if( i )
{
str += ", ";
}
snprintf( byteStr, sizeof(byteStr), "0x%.2x", data[i] );
str += byteStr;
}
return str;
}