25
25
26
26
#pragma once
27
27
28
- #include < locale>
29
28
#include < string>
30
29
31
30
namespace web { namespace details
32
31
{
33
- class uri_parser
32
+ namespace uri_parser
34
33
{
35
- public:
36
34
37
35
// / <summary>
38
36
// / Parses the uri, attempting to determine its validity.
39
37
// /
40
38
// / This function accepts both uris ('http://msn.com') and uri relative-references ('path1/path2?query')
41
39
// / </summary>
42
- static bool validate (const utility::string_t &encoded_string);
40
+ bool validate (const utility::string_t &encoded_string);
43
41
44
42
// / <summary>
45
43
// / Parses the uri, setting each provided string to the value of that component. Components
@@ -48,7 +46,7 @@ namespace web { namespace details
48
46
// /
49
47
// / This function accepts both uris ('http://msn.com') and uri relative-references ('path1/path2?query')
50
48
// / </summary>
51
- static bool parse (const utility::string_t &encoded_string, uri_components &components);
49
+ bool parse (const utility::string_t &encoded_string, uri_components &components);
52
50
53
51
// / <summary>
54
52
// / Unreserved characters are those that are allowed in a URI but do not have a reserved purpose. They include:
@@ -60,26 +58,17 @@ namespace web { namespace details
60
58
// / - '_' (underscore)
61
59
// / - '~' (tilde)
62
60
// / </summary>
63
- static bool is_unreserved (int c)
61
+ inline bool is_unreserved (int c)
64
62
{
65
63
return ::utility::details::is_alnum ((char )c) || c == ' -' || c == ' .' || c == ' _' || c == ' ~' ;
66
64
}
67
65
68
- // / <summary>
69
- // / Reserved characters includes the general delimiters and sub delimiters. Some characters
70
- // / are neither reserved nor unreserved, and must be percent-encoded.
71
- // / </summary>
72
- static bool is_reserved (int c)
73
- {
74
- return is_gen_delim (c) || is_sub_delim (c);
75
- }
76
-
77
66
// / <summary>
78
67
// / General delimiters serve as the delimiters between different uri components.
79
68
// / General delimiters include:
80
69
// / - All of these :/?#[]@
81
70
// / </summary>
82
- static bool is_gen_delim (int c)
71
+ inline bool is_gen_delim (int c)
83
72
{
84
73
return c == ' :' || c == ' /' || c == ' ?' || c == ' #' || c == ' [' || c == ' ]' || c == ' @' ;
85
74
}
@@ -90,7 +79,7 @@ namespace web { namespace details
90
79
// / uri segments. sub_delimiters include:
91
80
// / - All of these !$&'()*+,;=
92
81
// / </summary>
93
- static bool is_sub_delim (int c)
82
+ inline bool is_sub_delim (int c)
94
83
{
95
84
switch (c)
96
85
{
@@ -111,6 +100,15 @@ namespace web { namespace details
111
100
}
112
101
}
113
102
103
+ // / <summary>
104
+ // / Reserved characters includes the general delimiters and sub delimiters. Some characters
105
+ // / are neither reserved nor unreserved, and must be percent-encoded.
106
+ // / </summary>
107
+ inline bool is_reserved (int c)
108
+ {
109
+ return is_gen_delim (c) || is_sub_delim (c);
110
+ }
111
+
114
112
// / <summary>
115
113
// / Legal characters in the scheme portion include:
116
114
// / - Any alphanumeric character
@@ -120,7 +118,7 @@ namespace web { namespace details
120
118
// /
121
119
// / Note that the scheme must BEGIN with an alpha character.
122
120
// / </summary>
123
- static bool is_scheme_character (int c)
121
+ inline bool is_scheme_character (int c)
124
122
{
125
123
return ::utility::details::is_alnum ((char )c) || c == ' +' || c == ' -' || c == ' .' ;
126
124
}
@@ -132,7 +130,7 @@ namespace web { namespace details
132
130
// / - The sub-delimiters
133
131
// / - ':' (colon)
134
132
// / </summary>
135
- static bool is_user_info_character (int c)
133
+ inline bool is_user_info_character (int c)
136
134
{
137
135
return is_unreserved (c) || is_sub_delim (c) || c == ' %' || c == ' :' ;
138
136
}
@@ -146,7 +144,7 @@ namespace web { namespace details
146
144
// / - '[' (open bracket)
147
145
// / - ']' (close bracket)
148
146
// / </summary>
149
- static bool is_host_character (int c)
147
+ inline bool is_host_character (int c)
150
148
{
151
149
return is_unreserved (c) || is_sub_delim (c) || c == ' %' || c == ' :' || c == ' [' || c == ' ]' ;
152
150
}
@@ -161,7 +159,7 @@ namespace web { namespace details
161
159
// / Note that we don't currently support:
162
160
// / - IPv6 addresses (requires '[]')
163
161
// / </summary>
164
- static bool is_authority_character (int c)
162
+ inline bool is_authority_character (int c)
165
163
{
166
164
return is_unreserved (c) || is_sub_delim (c) || c == ' %' || c == ' @' || c == ' :' ;
167
165
}
@@ -174,7 +172,7 @@ namespace web { namespace details
174
172
// / - ':' (colon)
175
173
// / - '@' (ampersand)
176
174
// / </summary>
177
- static bool is_path_character (int c)
175
+ inline bool is_path_character (int c)
178
176
{
179
177
return is_unreserved (c) || is_sub_delim (c) || c == ' %' || c == ' /' || c == ' :' || c == ' @' ;
180
178
}
@@ -184,7 +182,7 @@ namespace web { namespace details
184
182
// / - Any path character
185
183
// / - '?' (question mark)
186
184
// / </summary>
187
- static bool is_query_character (int c)
185
+ inline bool is_query_character (int c)
188
186
{
189
187
return is_path_character (c) || c == ' ?' ;
190
188
}
@@ -194,22 +192,17 @@ namespace web { namespace details
194
192
// / - Any path character
195
193
// / - '?' (question mark)
196
194
// / </summary>
197
- static bool is_fragment_character (int c)
195
+ inline bool is_fragment_character (int c)
198
196
{
199
197
// this is intentional, they have the same set of legal characters
200
198
return is_query_character (c);
201
199
}
202
200
203
- private:
204
- uri_parser ();
205
- uri_parser (const uri_parser &);
206
- uri_parser & operator =(const uri_parser &);
207
-
208
201
// / <summary>
209
202
// / Parses the uri, setting the given pointers to locations inside the given buffer.
210
203
// / 'encoded' is expected to point to an encoded zero-terminated string containing a uri
211
204
// / </summary>
212
- static bool inner_parse (
205
+ bool inner_parse (
213
206
const utility::char_t *encoded,
214
207
const utility::char_t **scheme_begin, const utility::char_t **scheme_end,
215
208
const utility::char_t **uinfo_begin, const utility::char_t **uinfo_end,
@@ -218,7 +211,5 @@ namespace web { namespace details
218
211
const utility::char_t **path_begin, const utility::char_t **path_end,
219
212
const utility::char_t **query_begin, const utility::char_t **query_end,
220
213
const utility::char_t **fragment_begin, const utility::char_t **fragment_end);
221
-
222
- static const std::locale loc;
223
214
};
224
215
}}
0 commit comments