name-helper.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, The University of Memphis,
4  * Regents of the University of California
5  *
6  * This file is part of NLSR (Named-data Link State Routing).
7  * See AUTHORS.md for complete list of NLSR authors and contributors.
8  *
9  * NLSR is free software: you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License as published by the Free Software Foundation,
11  * either version 3 of the License, or (at your option) any later version.
12  *
13  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21  */
22 
23 #ifndef NLSR_NAME_HELPER_HPP
24 #define NLSR_NAME_HELPER_HPP
25 
26 #include "common.hpp"
27 
28 namespace nlsr::util {
29 
37 inline int32_t
38 getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
39 {
40  ndn::name::Component component(searchString);
41  size_t nameSize = name.size();
42  for (uint32_t i = 0; i < nameSize; i++) {
43  if (component == name[i]) {
44  return static_cast<int32_t>(i);
45  }
46  }
47  return -1;
48 }
49 
50 } // namespace nlsr::util
51 
52 #endif // NLSR_NAME_HELPER_HPP
int32_t getNameComponentPosition(const ndn::Name &name, const std::string &searchString)
search a name component in ndn::Name and return the position of the component
Definition: name-helper.hpp:38