akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1 | #ifndef NLSR_NAME_HELPER_HPP |
| 2 | #define NLSR_NAME_HELPER_HPP |
| 3 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 4 | #include <boost/algorithm/string.hpp> |
| 5 | #include <boost/algorithm/string/regex_find_format.hpp> |
| 6 | #include <boost/regex.hpp> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 7 | #include <boost/cstdint.hpp> |
| 8 | #include <ndn-cxx/name-component.hpp> |
| 9 | #include <ndn-cxx/name.hpp> |
| 10 | |
| 11 | namespace nlsr { |
| 12 | namespace util { |
| 13 | /** |
| 14 | * @brief search a name component in ndn::Name and return the position of the component |
| 15 | * @param name where to search the searchString |
| 16 | * @param searchString, the string to search in name |
| 17 | * @retrun int32_t -1 if searchString not found else return the position |
| 18 | * starting from 0 |
| 19 | */ |
| 20 | |
| 21 | inline static int32_t |
| 22 | getNameComponentPosition(const ndn::Name& name, const std::string& searchString) |
| 23 | { |
| 24 | ndn::name::Component component(searchString); |
| 25 | size_t nameSize = name.size(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 26 | for (uint32_t i = 0; i < nameSize; i++) { |
| 27 | if (component == name[i]) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 28 | return (int32_t)i; |
| 29 | } |
| 30 | } |
| 31 | return -1; |
| 32 | } |
| 33 | |
| 34 | } //namespace util |
| 35 | |
| 36 | } // namespace nlsr |
| 37 | |
| 38 | #endif //NLSR_NAME_HELPER_HPP |