1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int BYTE;
/*****************************************************************************/
/*********************************** Main **********************************/
/*****************************************************************************/
int main(int argc, char** argv)
{
std::vector<std::string> list_matches = {"82, 00, 01", "01, 00, 00, ff", "01, 01, 00, "};
std::vector<BYTE> list_bytes;
std::string match_str;
size_t nb_matches = list_matches.size(), pos, match;
BYTE byte;
list_bytes.reserve(3);
for(match=0; match < nb_matches; ++match) {
list_bytes.clear();
match_str = list_matches[match];
pos = match_str.find(", ");
while (pos != std::string::npos) {
if (sscanf(match_str.c_str(), "%x", &byte) == 1) {
list_bytes.push_back(byte);
}
match_str.erase(0, (pos + 1));
pos = match_str.find(", ");
}
// Extract last byte, if exists
if (match_str.size() > 0) {
if (sscanf(match_str.c_str(), "%x", &byte) == 1) {
list_bytes.push_back(byte);
}
}
// Display one match
std::cout << "Match:";
for(byte=0; byte < list_bytes.size(); ++byte) {
std::cout << " " << std::hex << list_bytes[byte] << std::dec;
}
std::cout << std::endl;
}
return EXIT_SUCCESS;
} |
Partager