Added ndn::toHex
diff --git a/Makefile.am b/Makefile.am
index d46b2e6..3ee6529 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,8 +39,9 @@
ndn-cpp/c/util/ndn_realloc.c ndn-cpp/c/util/ndn_realloc.h
libndn_cpp_la_SOURCES = \
- config.h ndn-cpp/common.hpp \
+ config.h \
ndn-cpp/closure.hpp \
+ ndn-cpp/common.hpp ndn-cpp/common.cpp \
ndn-cpp/data.cpp ndn-cpp/c/data.h ndn-cpp/data.hpp \
ndn-cpp/interest.cpp ndn-cpp/c/interest.h ndn-cpp/interest.hpp \
ndn-cpp/key.cpp ndn-cpp/c/key.h ndn-cpp/key.hpp \
diff --git a/ndn-cpp/common.cpp b/ndn-cpp/common.cpp
new file mode 100644
index 0000000..b4c6e45
--- /dev/null
+++ b/ndn-cpp/common.cpp
@@ -0,0 +1,28 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <sstream>
+#include "common.hpp"
+
+using namespace std;
+
+namespace ndn {
+
+string toHex(const vector<unsigned char> &array)
+{
+ ostringstream result;
+ result.flags(ios::hex | ios::uppercase);
+ for (unsigned int i = 0; i < array.size(); ++i) {
+ unsigned char x = array[i];
+ if (x < 16)
+ result << '0';
+ result << (unsigned int)x;
+ }
+
+ return result.str();
+}
+
+}
+
diff --git a/ndn-cpp/common.hpp b/ndn-cpp/common.hpp
index e477687..f82a77e 100644
--- a/ndn-cpp/common.hpp
+++ b/ndn-cpp/common.hpp
@@ -41,7 +41,14 @@
if (value)
vec.insert(vec.begin(), value, value + valueLength);
}
-
+
+/**
+ * Return the hex representation of the bytes in array.
+ * @param array The array of bytes.
+ * @return Hex string.
+ */
+std::string toHex(const std::vector<unsigned char> &array);
+
}
#endif