Name (internal): Make fromEscapedString return a Blob and make it a member of Name.
diff --git a/src/name.cpp b/src/name.cpp
index 22476af..d785fdd 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -7,6 +7,7 @@
#include <stdexcept>
#include <algorithm>
+#include <string.h>
#include <ndn-cpp/name.hpp>
#include "c/name.h"
@@ -125,26 +126,6 @@
}
Name::Component
-Name::Component::fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
-{
- string trimmedString(escapedString + beginOffset, escapedString + endOffset);
- trim(trimmedString);
- string component = unescape(trimmedString);
-
- if (component.find_first_not_of(".") == string::npos) {
- // Special case for component of only periods.
- if (component.size() <= 2)
- // Zero, one or two periods is illegal. Ignore this component.
- return Component();
- else
- // Remove 3 periods.
- return Component((const uint8_t *)&component[3], component.size() - 3);
- }
- else
- return Component((const uint8_t *)&component[0], component.size());
-}
-
-Name::Component
Name::Component::fromNumber(uint64_t number)
{
shared_ptr<vector<uint8_t> > value(new vector<uint8_t>());
@@ -241,7 +222,7 @@
if (iComponentEnd == string::npos)
iComponentEnd = uri.size();
- Component component = Component::fromEscapedString(&uri[0], iComponentStart, iComponentEnd);
+ Component component(fromEscapedString(&uri[0], iComponentStart, iComponentEnd));
// Ignore illegal components. This also gets rid of a trailing '/'.
if (component.getValue())
components_.push_back(Component(component));
@@ -352,6 +333,32 @@
return true;
}
+Blob
+Name::fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
+{
+ string trimmedString(escapedString + beginOffset, escapedString + endOffset);
+ trim(trimmedString);
+ string value = unescape(trimmedString);
+
+ if (value.find_first_not_of(".") == string::npos) {
+ // Special case for component of only periods.
+ if (value.size() <= 2)
+ // Zero, one or two periods is illegal. Ignore this component.
+ return Blob();
+ else
+ // Remove 3 periods.
+ return Blob((const uint8_t *)&value[3], value.size() - 3);
+ }
+ else
+ return Blob((const uint8_t *)&value[0], value.size());
+}
+
+Blob
+Name::fromEscapedString(const char *escapedString)
+{
+ return fromEscapedString(escapedString, 0, ::strlen(escapedString));
+}
+
void
Name::toEscapedString(const vector<uint8_t>& value, ostringstream& result)
{