1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 04:11:35 +01:00

Add Utils::route6_entries

This commit is contained in:
Matias Fontanini
2016-03-06 19:18:33 -08:00
parent c082dfad67
commit 4dcef0f15d
8 changed files with 161 additions and 17 deletions

View File

@@ -63,7 +63,7 @@ namespace Tins {
namespace Internals {
bool from_hex(const string& str, uint32_t& result) {
unsigned i(0);
size_t i = 0;
result = 0;
while (i < str.size()) {
uint8_t tmp;
@@ -82,6 +82,29 @@ bool from_hex(const string& str, uint32_t& result) {
return true;
}
bool from_hex(const string& str, string& result) {
result = "";
for (size_t i = 0; i < str.size(); i+= 2) {
uint8_t value = 0;
for (size_t j = i; j < i + 2 && j < str.size(); ++j) {
if (str[j] >= 'A' && str[j] <= 'F') {
value = (value << 4) | (str[j] - 'A' + 10);
}
else if (str[j] >= 'a' && str[j] <= 'f') {
value = (value << 4) | (str[j] - 'a' + 10);
}
else if (str[j] >= '0' && str[j] <= '9') {
value = (value << 4) | (str[j] - '0');
}
else {
return false;
}
}
result.push_back(value);
}
return true;
}
void skip_line(std::istream& input) {
int c = 0;
while (c != '\n' && input) {