Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 3331 → Rev 3332

/branches/STF525/ccsrc/Framework/converter.hh
353,4 → 353,5
*/
std::vector<std::string> split_arguments_line(const std::string & p_value);
static const std::string lut;
}; // End of class converter
/branches/STF525/ccsrc/Framework/src/converter.cc
1,5 → 1,5
#include "converter.hh"
 
#include <stdexcept>
converter * converter::instance = NULL;
uint16_t converter::swap(const uint16_t p_value) {
12,8 → 12,8
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
}
const std::string converter::lut = "0123456789ABCDEF";
std::string converter::string_to_hexa(const std::string & p_value) {
static const char * const lut = "0123456789ABCDEF";
 
std::string input(p_value);
std::for_each(
37,56 → 37,42
}
std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value) {
std::ostringstream oss;
oss << std::setfill('0');
std::for_each(
p_value.begin(),
p_value.end(),
[&oss](uint8_t ch) {
oss << std::hex
<< std::setw(2)
<< static_cast<int>(ch);
}
);
return oss.str();
std::string ret;
ret.assign(p_value.size()*2, ' ');
for(size_t i=0; i<p_value.size(); i++){
uint8_t c = p_value[i];
ret[i*2] = lut[c>>4];
ret[i*2+1] = lut[c&0xF];
}
return ret;
}
 
inline uint8_t char2byte(const char ch) {
size_t s = converter::lut.find(ch);
if(s == std::string::npos)
throw (std::length_error(""));
return s;
}
 
std::vector<uint8_t> converter::hexa_to_bytes(const std::string & p_value) {
static const char * const lut = "0123456789ABCDEF";
 
// Sanity check
std::vector<uint8_t> output;
if (p_value.length() & 1) {
return output;
size_t i=0, idx = 0, outlen=(p_value.length()+1) / 2;
 
output.assign(outlen, 0x00);
try{
if (p_value.length() & 1)
output[idx++] = char2byte(p_value[i++]);
for(;idx<outlen;idx++){
uint8_t b0 = char2byte(p_value[i++]);
uint8_t b1 = char2byte(p_value[i++]);
output[idx] = (b0<<4)|b1;
}
}
std::string input(p_value);
std::for_each(
input.begin(),
input.end(),
[](char & c) {
c = std::toupper(c);
}
);
output.reserve(p_value.length() / 2);
for (uint32_t i = 0; i < p_value.length(); i += 2) {
char msbDigit = input[i];
const char *msbIndex = std::lower_bound(lut, lut + 16, msbDigit);
if (*msbIndex != msbDigit) {
output.clear();
return output;
}
char lsbDigit = input[i + 1];
const char* lsbIndex = std::lower_bound(lut, lut + 16, lsbDigit);
if (*lsbIndex != lsbDigit) {
output.clear();
return output;
}
output.push_back(((msbIndex - lut) << 4) | (lsbIndex - lut));
} // End of 'for' statement
return output;
catch (const std::length_error& le) {
output.clear();
}
return output;
}
 
std::string converter::time_to_string(const time_t p_time) {