Feature #4658: Better range definitions for VLAN_IDs

This commit is contained in:
Jaime Melis committed 2016-08-30 12:20:07 +02:00
1 parent e4ba4da388
commit d8ee69a09a
1 file changed
+63 -1
+63 -1
View File
@@ -46,7 +46,7 @@ public:
if (!reserved.empty())
{
one_util::split_unique(reserved, ',', reserved_bit);
set_reserved_bit(reserved);
}
};
@@ -326,6 +326,68 @@ private:
return rc;
}
/**
* The reserved bit string is separated by ',' for each element
* and by ':' for ranges.
* @param string with reserved bits
*/
void set_reserved_bit(std::string& reserved)
{
ostringstream oss;
std::vector<std::string> strings;
std::vector<std::string> range;
std::vector<std::string>::const_iterator it;
std::istringstream iss;
unsigned int bit, bit_start, bit_end;
strings = one_util::split(reserved, ',', true);
for (it = strings.begin(); it != strings.end(); it++)
{
// Try to split it by ':'
range = one_util::split(*it, ':', true);
iss.clear();
iss.str(range[0]);
iss >> bit_start;
if ( iss.fail() )
{
continue;
}
if (range.size() == 1)
{
bit_end = bit_start;
}
else if (range.size() == 2)
{
iss.clear();
iss.str(range[1]);
iss >> bit_end;
if ( iss.fail() )
{
continue;
}
}
else
{
continue;
}
for (bit = bit_start; bit <= bit_end; bit++)
{
reserved_bit.insert(bit);
}
}
}
};
#endif /*BITMAP_H_*/