src: Replace Tokenizer with the methods of ndn::Name
Purpose of this commit is to replace Tokenizer in all
places except conf-file-processor.*pp with the methods
of ndn::Name. One static method in class NameHelper
is added. Tokenizer will be removed finally when
configuration file parsing commit is complete.
Refs: 1533
Change-Id: I14a67655eb963c5cc5b045c3c9f7d516e405ff19
diff --git a/src/utility/name-helper.hpp b/src/utility/name-helper.hpp
new file mode 100644
index 0000000..5a01a1a
--- /dev/null
+++ b/src/utility/name-helper.hpp
@@ -0,0 +1,37 @@
+#ifndef NLSR_NAME_HELPER_HPP
+#define NLSR_NAME_HELPER_HPP
+
+#include <boost/cstdint.hpp>
+#include <ndn-cxx/name-component.hpp>
+#include <ndn-cxx/name.hpp>
+
+namespace nlsr {
+namespace util {
+/**
+ * @brief search a name component in ndn::Name and return the position of the component
+ * @param name where to search the searchString
+ * @param searchString, the string to search in name
+ * @retrun int32_t -1 if searchString not found else return the position
+ * starting from 0
+ */
+
+inline static int32_t
+getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
+{
+ ndn::name::Component component(searchString);
+ size_t nameSize = name.size();
+ for (uint32_t i = 0; i < nameSize; i++)
+ {
+ if (component == name[i])
+ {
+ return (int32_t)i;
+ }
+ }
+ return -1;
+}
+
+} //namespace util
+
+} // namespace nlsr
+
+#endif //NLSR_NAME_HELPER_HPP