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