Make toEscapedString public static.
diff --git a/ndn-cpp/name.cpp b/ndn-cpp/name.cpp
index 9e60ca9..2886d1a 100644
--- a/ndn-cpp/name.cpp
+++ b/ndn-cpp/name.cpp
@@ -4,7 +4,6 @@
*/
#include <stdexcept>
-#include <sstream>
#include <algorithm>
#include "name.hpp"
@@ -12,51 +11,6 @@
namespace ndn {
-/**
- * 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
- * @param result the string stream to write to.
- */
-static void toEscapedString(const vector<unsigned char> &value, ostringstream &result)
-{
- bool gotNonDot = false;
- for (unsigned i = 0; i < value.size(); ++i) {
- if (value[i] != 0x2e) {
- gotNonDot = true;
- break;
- }
- }
- if (!gotNonDot) {
- // Special case for component of zero or more periods. Add 3 periods.
- result << "...";
- for (unsigned int i = 0; i < value.size(); ++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 (unsigned int i = 0; i < value.size(); ++i) {
- unsigned char x = value[i];
- // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
- if (x >= 0x30 && x <= 0x39 || x >= 0x41 && x <= 0x5a ||
- x >= 0x61 && x <= 0x7a || x == 0x2b || x == 0x2d ||
- x == 0x2e || x == 0x5f)
- result << x;
- else {
- result << '%';
- if (x < 16)
- result << '0';
- result << (unsigned int)x;
- }
- }
-
- // Restore.
- result.flags(saveFlags);
- }
-}
-
static const char *WHITESPACE_CHARS = " \n\r\t";
/**
@@ -298,4 +252,43 @@
return true;
}
+void Name::toEscapedString(const vector<unsigned char> &value, ostringstream &result)
+{
+ bool gotNonDot = false;
+ for (unsigned i = 0; i < value.size(); ++i) {
+ if (value[i] != 0x2e) {
+ gotNonDot = true;
+ break;
+ }
+ }
+ if (!gotNonDot) {
+ // Special case for component of zero or more periods. Add 3 periods.
+ result << "...";
+ for (unsigned int i = 0; i < value.size(); ++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 (unsigned int i = 0; i < value.size(); ++i) {
+ unsigned char x = value[i];
+ // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
+ if (x >= 0x30 && x <= 0x39 || x >= 0x41 && x <= 0x5a ||
+ x >= 0x61 && x <= 0x7a || x == 0x2b || x == 0x2d ||
+ x == 0x2e || x == 0x5f)
+ result << x;
+ else {
+ result << '%';
+ if (x < 16)
+ result << '0';
+ result << (unsigned int)x;
+ }
+ }
+
+ // Restore.
+ result.flags(saveFlags);
+ }
+}
+
}
diff --git a/ndn-cpp/name.hpp b/ndn-cpp/name.hpp
index 42269e4..45236d4 100644
--- a/ndn-cpp/name.hpp
+++ b/ndn-cpp/name.hpp
@@ -8,6 +8,7 @@
#include <vector>
#include <string>
+#include <sstream>
#include "c/name.h"
#include "encoding/binary-xml-wire-format.hpp"
@@ -175,7 +176,20 @@
components_.back().setSegment(segment);
}
+ /**
+ * Check if the N components of this name are the same as the first N components of the given name.
+ * @param name The Name to check.
+ * @return true if this matches the given name, otherwise false. This always returns true if this name is empty.
+ */
bool match(const Name &name);
+
+ /**
+ * 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
+ * @param result the string stream to write to.
+ */
+ static void toEscapedString(const std::vector<unsigned char> &value, std::ostringstream &result);
private:
std::vector<Component> components_;