blob: 60a58b4abd5291eda841352b10aad4624e998b34 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 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 **/
akmhoque31d1d4b2014-05-05 22:08:14 -050023#ifndef NLSR_NAME_HELPER_HPP
24#define NLSR_NAME_HELPER_HPP
25
akmhoque157b0a42014-05-13 00:26:37 -050026#include <boost/algorithm/string.hpp>
27#include <boost/algorithm/string/regex_find_format.hpp>
28#include <boost/regex.hpp>
akmhoque31d1d4b2014-05-05 22:08:14 -050029#include <boost/cstdint.hpp>
30#include <ndn-cxx/name-component.hpp>
31#include <ndn-cxx/name.hpp>
32
33namespace nlsr {
34namespace util {
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070035
akmhoque31d1d4b2014-05-05 22:08:14 -050036/**
37 * @brief search a name component in ndn::Name and return the position of the component
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070038 * @param name where to search the searchString
39 * @param searchString the string to search in name
40 * @return -1 if searchString not found else return the position
akmhoque31d1d4b2014-05-05 22:08:14 -050041 * starting from 0
42 */
akmhoque31d1d4b2014-05-05 22:08:14 -050043inline static int32_t
44getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
45{
46 ndn::name::Component component(searchString);
47 size_t nameSize = name.size();
akmhoque157b0a42014-05-13 00:26:37 -050048 for (uint32_t i = 0; i < nameSize; i++) {
49 if (component == name[i]) {
akmhoque31d1d4b2014-05-05 22:08:14 -050050 return (int32_t)i;
51 }
52 }
53 return -1;
54}
55
56} //namespace util
57
58} // namespace nlsr
59
60#endif //NLSR_NAME_HELPER_HPP