blob: 65052d88cc010c514a5f4af9ccb93828b6c17377 [file] [log] [blame]
Davide Pesavento35185332019-01-14 04:00:15 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2019, Arizona Board of Regents.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
19 */
20
21#ifndef NTG_UTIL_HPP
22#define NTG_UTIL_HPP
23
24#include <cctype>
25#include <string>
26
27namespace ndn {
28
29static inline bool
30parseParameterAndValue(const std::string& input, std::string& parameter, std::string& value)
31{
32 static const std::string allowedCharacters = ":/+._-%";
33 parameter = "";
34 value = "";
35
36 std::size_t i = 0;
37 // parse the parameter name
38 while (i < input.length() && input[i] != '=') {
39 parameter += input[i];
40 i++;
41 }
42 if (i == input.length()) {
43 return false;
44 }
45
46 // skip the equal sign
47 i++;
48
49 // parse the value
50 while (i < input.length() &&
51 (std::isalnum(input[i]) || allowedCharacters.find(input[i]) != std::string::npos)) {
52 value += input[i];
53 i++;
54 }
55
56 return !parameter.empty() && !value.empty() && i == input.length();
57}
58
59} // namespace ndn
60
61#endif // NTG_UTIL_HPP