forked from etr/libhttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_arg_value.h
More file actions
71 lines (59 loc) · 1.71 KB
/
Copy pathhttp_arg_value.h
File metadata and controls
71 lines (59 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#if !defined(_HTTPSERVER_HPP_INSIDE_) && !defined(HTTPSERVER_COMPILATION)
#error "Only <httpserver.h> or <httpserverpp> can be included directly."
#endif
#ifndef SRC_HTTPSERVER_HTTP_ARG_VALUE_HPP_
#define SRC_HTTPSERVER_HTTP_ARG_VALUE_HPP_
// Custom string_view for C++11, standard string_view for C++17 and above
#if __cplusplus >= 201703L
#include <string_view>
namespace httpserver
{
using string_view = std::string_view;
}
#else
#include "include/utils/string_view.h" // Use custom string_view for C++11
namespace httpserver
{
using string_view = StringView;
}
#endif
#include <string>
#include <vector>
namespace httpserver
{
class http_arg_value
{
public:
string_view get_flat_value() const
{
return values.empty() ? "" : values[0];
}
std::vector<string_view> get_all_values() const
{
return values;
}
// Conversion to std::string
operator std::string() const
{
string_view value = get_flat_value();
return std::string(value.data(), value.size()); // Explicit conversion
}
// Conversion to string_view
operator string_view() const
{
return get_flat_value();
}
// Conversion to std::vector<std::string>
operator std::vector<std::string>() const
{
std::vector<std::string> result;
for (auto const &value : values)
{
result.push_back(std::string(value.data(), value.size())); // Explicit conversion
}
return result;
}
std::vector<string_view> values;
};
} // end namespace httpserver
#endif // SRC_HTTPSERVER_HTTP_ARG_VALUE_HPP_