Line data Source code
1 : // Copyright (c) 2011-2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/edhttp
4 : // contact@m2osw.com
5 : //
6 : // This program is free software: you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation, either version 3 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 : #pragma once
19 :
20 : // C++
21 : //
22 : #include <map>
23 : #include <string>
24 : #include <vector>
25 :
26 :
27 :
28 : namespace edhttp
29 : {
30 :
31 :
32 481 : class string_part
33 : {
34 : public:
35 : typedef float level_t;
36 : typedef std::vector<string_part> vector_t; // do NOT use a map, we want to keep them in order!
37 :
38 : // an authoritative document at the IANA clearly says that
39 : // the default level (quality value) is 1.0f.
40 : //
41 : // Note: we use functions because these values are floating points and
42 : // for some odd reasons C++ doesn't support such as plain constants
43 : //
44 133 : static level_t constexpr DEFAULT_LEVEL() { return 1.0f; }
45 :
46 52 : static level_t constexpr UNDEFINED_LEVEL() { return -1.0f; }
47 :
48 : string_part(std::string const & name);
49 :
50 : std::string const & get_name() const;
51 : std::string const & get_value() const; // in case the first name has a "name=value" part
52 : void set_value(std::string const & value);
53 : level_t get_level() const;
54 : void set_level(level_t const level);
55 : std::string get_parameter(std::string const & name) const;
56 : void add_parameter(std::string const & name, std::string const & value);
57 : std::string to_string() const;
58 :
59 : bool operator < (string_part const & rhs) const;
60 :
61 : static char value_require_quotes(std::string const & value);
62 :
63 : private:
64 : typedef std::map<std::string, std::string> parameters_t;
65 :
66 : std::string f_name = std::string();
67 : std::string f_value = std::string();
68 87 : level_t f_level = DEFAULT_LEVEL(); // i.e. q=1.0
69 : // TODO add support for any other parameter
70 : parameters_t f_param = parameters_t();
71 : };
72 :
73 :
74 : } // namespace edhttp
75 : // vim: ts=4 sw=4 et
|