NetFlex  0.0.0
C++11 HTTP Server Library.
utils.hpp
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <string>
26 #include <vector>
27 
28 namespace netflex {
29 
30 namespace parsing {
31 
32 namespace utils {
33 
35 extern const char SP;
36 
38 extern const char HTAB;
39 
41 extern const char VT;
42 
44 extern const char FF;
45 
47 extern const char CR;
48 
50 extern const char LF;
51 
58 bool is_space_delimiter(char c);
59 
66 bool is_whitespace_delimiter(char c);
67 
74 bool is_crlf(const std::string& buffer);
75 
82 char consume_whitespaces(std::string& buffer);
83 
91 std::string consume_word(std::string& buffer, char ending = 0);
92 
99 std::string consume_words(std::string& buffer);
100 
108 std::string consume_word_with_ending(std::string& buffer, char ending);
109 
116 bool consume_crlf(std::string& buffer);
117 
127 bool parse_words(std::string& buffer, std::string& out);
128 
138 bool parse_next_word(std::string& buffer, std::string& out);
139 
151 bool parse_next_word_with_ending(std::string& buffer, std::string& word, char ending);
152 
160 std::vector<std::string> split(const std::string& str, char sep);
161 
167 void trim(std::string& str);
168 
174 void ltrim(std::string& str);
175 
181 void rtrim(std::string& str);
182 
188 void to_lower(std::string& str);
189 
195 void to_upper(std::string& str);
196 
197 } // namespace utils
198 
199 } // namespace parsing
200 
201 } // namespace netflex
Definition: client.hpp:33