blob: 4c2c7c0c18d87d03cd1423de2fc3b34d550040ec [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventod90338d2021-01-07 17:50:05 -05002/*
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -04003 * Copyright (c) 2014-2022, The University of Memphis,
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05004 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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>
Davide Pesaventod90338d2021-01-07 17:50:05 -050021 */
22
akmhoque31d1d4b2014-05-05 22:08:14 -050023#ifndef NLSR_NAME_HELPER_HPP
24#define NLSR_NAME_HELPER_HPP
25
Davide Pesaventod90338d2021-01-07 17:50:05 -050026#include "common.hpp"
akmhoque31d1d4b2014-05-05 22:08:14 -050027
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040028namespace nlsr::util {
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070029
Nick G97e34942016-07-11 14:46:27 -050030/*!
31 \brief search a name component in ndn::Name and return the position of the component
32 \param name where to search the searchString
33 \param searchString the string to search in name
34 \return -1 if searchString not found else return the position
35 starting from 0
akmhoque31d1d4b2014-05-05 22:08:14 -050036 */
Davide Pesaventod90338d2021-01-07 17:50:05 -050037inline int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050038getNameComponentPosition(const ndn::Name& name, const std::string& searchString)
39{
40 ndn::name::Component component(searchString);
41 size_t nameSize = name.size();
akmhoque157b0a42014-05-13 00:26:37 -050042 for (uint32_t i = 0; i < nameSize; i++) {
43 if (component == name[i]) {
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040044 return static_cast<int32_t>(i);
akmhoque31d1d4b2014-05-05 22:08:14 -050045 }
46 }
47 return -1;
48}
49
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040050} // namespace nlsr::util
akmhoque31d1d4b2014-05-05 22:08:14 -050051
Davide Pesaventod90338d2021-01-07 17:50:05 -050052#endif // NLSR_NAME_HELPER_HPP