name: Updating toEscapedString interface
Actual implementation is now based on const buffer, not const
std::vector.
Change-Id: Ie29c4be9df7cba0f1e71adb6b3684c9da23a0836
diff --git a/src/name.cpp b/src/name.cpp
index 0a0b0e3..b71c23c 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -259,10 +259,10 @@
}
void
-Name::toEscapedString(const vector<uint8_t>& value, std::ostream& result)
+Name::toEscapedString(const uint8_t *value, size_t valueSize, std::ostream& result)
{
bool gotNonDot = false;
- for (unsigned i = 0; i < value.size(); ++i) {
+ for (unsigned i = 0; i < valueSize; ++i) {
if (value[i] != 0x2e) {
gotNonDot = true;
break;
@@ -271,14 +271,14 @@
if (!gotNonDot) {
// Special case for component of zero or more periods. Add 3 periods.
result << "...";
- for (size_t i = 0; i < value.size(); ++i)
+ for (size_t i = 0; i < valueSize; ++i)
result << '.';
}
else {
// In case we need to escape, set to upper case hex and save the previous flags.
ios::fmtflags saveFlags = result.flags(ios::hex | ios::uppercase);
- for (size_t i = 0; i < value.size(); ++i) {
+ for (size_t i = 0; i < valueSize; ++i) {
uint8_t x = value[i];
// Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
if ((x >= 0x30 && x <= 0x39) || (x >= 0x41 && x <= 0x5a) ||
@@ -298,14 +298,6 @@
}
}
-string
-Name::toEscapedString(const vector<uint8_t>& value)
-{
- ostringstream result;
- toEscapedString(value, result);
- return result.str();
-}
-
bool
Name::breadthFirstLess(const Name& name1, const Name& name2)
{
@@ -363,6 +355,8 @@
void
Name::wireDecode(const Block &wire)
{
+ clear();
+
wire_ = wire;
wire_.parse();