Name (internal): Make fromEscapedString return a Blob and make it a member of Name.
diff --git a/include/ndn-cpp/name.hpp b/include/ndn-cpp/name.hpp
index 5ff50d9..5e92e77 100644
--- a/include/ndn-cpp/name.hpp
+++ b/include/ndn-cpp/name.hpp
@@ -148,18 +148,6 @@
}
/**
- * Make a component value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
- * If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means this component value was not changed, and
- * the component should be skipped in a URI name.
- * @param escapedString The escaped string. It does not need to be null-terminated because we only scan to endOffset.
- * @param beginOffset The offset in escapedString of the beginning of the portion to decode.
- * @param endOffset The offset in escapedString of the end of the portion to decode.
- * @return The component value. If the escapedString is not a valid escaped component, then the component value is a null pointer.
- */
- static Component
- fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
-
- /**
* Create a component whose value is the network-ordered encoding of the number.
* Note: if the number is zero, the result is empty.
* @param number The number to be encoded.
@@ -446,6 +434,28 @@
match(const Name& name) const;
/**
+ * Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
+ * If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means this component value was not changed, and
+ * the component should be skipped in a URI name.
+ * @param escapedString The escaped string. It does not need to be null-terminated because we only scan to endOffset.
+ * @param beginOffset The offset in escapedString of the beginning of the portion to decode.
+ * @param endOffset The offset in escapedString of the end of the portion to decode.
+ * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
+ */
+ static Blob
+ fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
+
+ /**
+ * Make a Blob value by decoding the escapedString according to the NDN URI Scheme.
+ * If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means this component value was not changed, and
+ * the component should be skipped in a URI name.
+ * @param escapedString The null-terminated escaped string.
+ * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
+ */
+ static Blob
+ fromEscapedString(const char *escapedString);
+
+ /**
* Write the value to result, escaping characters according to the NDN URI Scheme.
* This also adds "..." to a value with zero or more ".".
* @param value the buffer with the value to escape
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)
{