]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/src/setup/parser_utils.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / log / src / setup / parser_utils.hpp
1 /*
2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7 /*!
8 * \file parser_utils.hpp
9 * \author Andrey Semashev
10 * \date 31.03.2008
11 *
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
14 */
15
16 #ifndef BOOST_LOG_PARSER_UTILS_HPP_INCLUDED_
17 #define BOOST_LOG_PARSER_UTILS_HPP_INCLUDED_
18
19 #include <boost/log/detail/config.hpp>
20 #include <string>
21 #include <iostream>
22 #include <cctype>
23 #include <boost/log/utility/string_literal.hpp>
24 #include <boost/log/detail/header.hpp>
25
26 #ifdef BOOST_HAS_PRAGMA_ONCE
27 #pragma once
28 #endif
29
30 namespace boost {
31
32 BOOST_LOG_OPEN_NAMESPACE
33
34 namespace aux {
35
36 //! Some constants and algorithms needed for parsing
37 template< typename > struct char_constants;
38
39 #ifdef BOOST_LOG_USE_CHAR
40 template< >
41 struct char_constants< char >
42 {
43 typedef char char_type;
44 typedef std::basic_string< char_type > string_type;
45 typedef boost::log::basic_string_literal< char_type > literal_type;
46
47 static const char_type char_comment = '#';
48 static const char_type char_comma = ',';
49 static const char_type char_dot = '.';
50 static const char_type char_quote = '"';
51 static const char_type char_percent = '%';
52 static const char_type char_exclamation = '!';
53 static const char_type char_and = '&';
54 static const char_type char_or = '|';
55 static const char_type char_equal = '=';
56 static const char_type char_greater = '>';
57 static const char_type char_less = '<';
58 static const char_type char_underline = '_';
59 static const char_type char_backslash = '\\';
60 static const char_type char_section_bracket_left = '[';
61 static const char_type char_section_bracket_right = ']';
62 static const char_type char_paren_bracket_left = '(';
63 static const char_type char_paren_bracket_right = ')';
64
65 static const char_type* not_keyword() { return "not"; }
66 static const char_type* and_keyword() { return "and"; }
67 static const char_type* or_keyword() { return "or"; }
68 static const char_type* equal_keyword() { return "="; }
69 static const char_type* greater_keyword() { return ">"; }
70 static const char_type* less_keyword() { return "<"; }
71 static const char_type* not_equal_keyword() { return "!="; }
72 static const char_type* greater_or_equal_keyword() { return ">="; }
73 static const char_type* less_or_equal_keyword() { return "<="; }
74 static const char_type* begins_with_keyword() { return "begins_with"; }
75 static const char_type* ends_with_keyword() { return "ends_with"; }
76 static const char_type* contains_keyword() { return "contains"; }
77 static const char_type* matches_keyword() { return "matches"; }
78
79 static const char_type* message_text_keyword() { return "_"; }
80
81 static literal_type true_keyword() { return literal_type("true"); }
82 static literal_type false_keyword() { return literal_type("false"); }
83
84 static const char_type* default_level_attribute_name() { return "Severity"; }
85
86 static const char_type* core_section_name() { return "Core"; }
87 static const char_type* sink_section_name_prefix() { return "Sink:"; }
88
89 static const char_type* core_disable_logging_param_name() { return "DisableLogging"; }
90 static const char_type* filter_param_name() { return "Filter"; }
91
92 static const char_type* sink_destination_param_name() { return "Destination"; }
93 static const char_type* file_name_param_name() { return "FileName"; }
94 static const char_type* rotation_size_param_name() { return "RotationSize"; }
95 static const char_type* rotation_interval_param_name() { return "RotationInterval"; }
96 static const char_type* rotation_time_point_param_name() { return "RotationTimePoint"; }
97 static const char_type* append_param_name() { return "Append"; }
98 static const char_type* enable_final_rotation_param_name() { return "EnableFinalRotation"; }
99 static const char_type* auto_flush_param_name() { return "AutoFlush"; }
100 static const char_type* asynchronous_param_name() { return "Asynchronous"; }
101 static const char_type* format_param_name() { return "Format"; }
102 static const char_type* provider_id_param_name() { return "ProviderID"; }
103 static const char_type* log_name_param_name() { return "LogName"; }
104 static const char_type* source_name_param_name() { return "LogSource"; }
105 static const char_type* registration_param_name() { return "Registration"; }
106 static const char_type* local_address_param_name() { return "LocalAddress"; }
107 static const char_type* target_address_param_name() { return "TargetAddress"; }
108 static const char_type* target_param_name() { return "Target"; }
109 static const char_type* max_size_param_name() { return "MaxSize"; }
110 static const char_type* max_files_param_name() { return "MaxFiles"; }
111 static const char_type* min_free_space_param_name() { return "MinFreeSpace"; }
112 static const char_type* scan_for_files_param_name() { return "ScanForFiles"; }
113
114 static const char_type* scan_method_all() { return "All"; }
115 static const char_type* scan_method_matching() { return "Matching"; }
116
117 static const char_type* registration_never() { return "Never"; }
118 static const char_type* registration_on_demand() { return "OnDemand"; }
119 static const char_type* registration_forced() { return "Forced"; }
120
121 static const char_type* text_file_destination() { return "TextFile"; }
122 static const char_type* console_destination() { return "Console"; }
123 static const char_type* syslog_destination() { return "Syslog"; }
124 static const char_type* simple_event_log_destination() { return "SimpleEventLog"; }
125 static const char_type* debugger_destination() { return "Debugger"; }
126
127 static literal_type monday_keyword() { return literal_type("Monday"); }
128 static literal_type short_monday_keyword() { return literal_type("Mon"); }
129 static literal_type tuesday_keyword() { return literal_type("Tuesday"); }
130 static literal_type short_tuesday_keyword() { return literal_type("Tue"); }
131 static literal_type wednesday_keyword() { return literal_type("Wednesday"); }
132 static literal_type short_wednesday_keyword() { return literal_type("Wed"); }
133 static literal_type thursday_keyword() { return literal_type("Thursday"); }
134 static literal_type short_thursday_keyword() { return literal_type("Thu"); }
135 static literal_type friday_keyword() { return literal_type("Friday"); }
136 static literal_type short_friday_keyword() { return literal_type("Fri"); }
137 static literal_type saturday_keyword() { return literal_type("Saturday"); }
138 static literal_type short_saturday_keyword() { return literal_type("Sat"); }
139 static literal_type sunday_keyword() { return literal_type("Sunday"); }
140 static literal_type short_sunday_keyword() { return literal_type("Sun"); }
141
142 static std::ostream& get_console_log_stream() { return std::clog; }
143
144 static int to_number(char_type c)
145 {
146 using namespace std; // to make sure we can use C functions unqualified
147 int n = 0;
148 if (isdigit(c))
149 n = c - '0';
150 else if (c >= 'a' && c <= 'f')
151 n = c - 'a' + 10;
152 else if (c >= 'A' && c <= 'F')
153 n = c - 'A' + 10;
154 return n;
155 }
156
157 //! Skips spaces in the beginning of the input
158 static const char_type* trim_spaces_left(const char_type* begin, const char_type* end);
159 //! Skips spaces in the end of the input
160 static const char_type* trim_spaces_right(const char_type* begin, const char_type* end);
161 //! Scans for the attribute name placeholder in the input
162 static const char_type* scan_attr_placeholder(const char_type* begin, const char_type* end);
163 //! Parses an operand string (possibly quoted) from the input
164 static const char_type* parse_operand(const char_type* begin, const char_type* end, string_type& operand);
165 //! Converts escape sequences to the corresponding characters
166 static void translate_escape_sequences(string_type& str);
167 };
168 #endif
169
170 #ifdef BOOST_LOG_USE_WCHAR_T
171 template< >
172 struct char_constants< wchar_t >
173 {
174 typedef wchar_t char_type;
175 typedef std::basic_string< char_type > string_type;
176 typedef boost::log::basic_string_literal< char_type > literal_type;
177
178 static const char_type char_comment = L'#';
179 static const char_type char_comma = L',';
180 static const char_type char_dot = L'.';
181 static const char_type char_quote = L'"';
182 static const char_type char_percent = L'%';
183 static const char_type char_exclamation = L'!';
184 static const char_type char_and = L'&';
185 static const char_type char_or = L'|';
186 static const char_type char_equal = L'=';
187 static const char_type char_greater = L'>';
188 static const char_type char_less = L'<';
189 static const char_type char_underline = L'_';
190 static const char_type char_backslash = L'\\';
191 static const char_type char_section_bracket_left = L'[';
192 static const char_type char_section_bracket_right = L']';
193 static const char_type char_paren_bracket_left = L'(';
194 static const char_type char_paren_bracket_right = L')';
195
196 static const char_type* not_keyword() { return L"not"; }
197 static const char_type* and_keyword() { return L"and"; }
198 static const char_type* or_keyword() { return L"or"; }
199 static const char_type* equal_keyword() { return L"="; }
200 static const char_type* greater_keyword() { return L">"; }
201 static const char_type* less_keyword() { return L"<"; }
202 static const char_type* not_equal_keyword() { return L"!="; }
203 static const char_type* greater_or_equal_keyword() { return L">="; }
204 static const char_type* less_or_equal_keyword() { return L"<="; }
205 static const char_type* begins_with_keyword() { return L"begins_with"; }
206 static const char_type* ends_with_keyword() { return L"ends_with"; }
207 static const char_type* contains_keyword() { return L"contains"; }
208 static const char_type* matches_keyword() { return L"matches"; }
209
210 static const char_type* message_text_keyword() { return L"_"; }
211
212 static literal_type true_keyword() { return literal_type(L"true"); }
213 static literal_type false_keyword() { return literal_type(L"false"); }
214
215 static const char_type* default_level_attribute_name() { return L"Severity"; }
216
217 static const char_type* core_section_name() { return L"Core"; }
218 static const char_type* sink_section_name_prefix() { return L"Sink:"; }
219
220 static const char_type* core_disable_logging_param_name() { return L"DisableLogging"; }
221 static const char_type* filter_param_name() { return L"Filter"; }
222
223 static const char_type* sink_destination_param_name() { return L"Destination"; }
224 static const char_type* file_name_param_name() { return L"FileName"; }
225 static const char_type* rotation_size_param_name() { return L"RotationSize"; }
226 static const char_type* rotation_interval_param_name() { return L"RotationInterval"; }
227 static const char_type* rotation_time_point_param_name() { return L"RotationTimePoint"; }
228 static const char_type* append_param_name() { return L"Append"; }
229 static const char_type* enable_final_rotation_param_name() { return L"EnableFinalRotation"; }
230 static const char_type* auto_flush_param_name() { return L"AutoFlush"; }
231 static const char_type* asynchronous_param_name() { return L"Asynchronous"; }
232 static const char_type* format_param_name() { return L"Format"; }
233 static const char_type* provider_id_param_name() { return L"ProviderID"; }
234 static const char_type* log_name_param_name() { return L"LogName"; }
235 static const char_type* source_name_param_name() { return L"LogSource"; }
236 static const char_type* registration_param_name() { return L"Registration"; }
237 static const char_type* local_address_param_name() { return L"LocalAddress"; }
238 static const char_type* target_address_param_name() { return L"TargetAddress"; }
239 static const char_type* target_param_name() { return L"Target"; }
240 static const char_type* max_size_param_name() { return L"MaxSize"; }
241 static const char_type* max_files_param_name() { return L"MaxFiles"; }
242 static const char_type* min_free_space_param_name() { return L"MinFreeSpace"; }
243 static const char_type* scan_for_files_param_name() { return L"ScanForFiles"; }
244
245 static const char_type* scan_method_all() { return L"All"; }
246 static const char_type* scan_method_matching() { return L"Matching"; }
247
248 static const char_type* registration_never() { return L"Never"; }
249 static const char_type* registration_on_demand() { return L"OnDemand"; }
250 static const char_type* registration_forced() { return L"Forced"; }
251
252 static const char_type* text_file_destination() { return L"TextFile"; }
253 static const char_type* console_destination() { return L"Console"; }
254 static const char_type* syslog_destination() { return L"Syslog"; }
255 static const char_type* simple_event_log_destination() { return L"SimpleEventLog"; }
256 static const char_type* debugger_destination() { return L"Debugger"; }
257
258 static literal_type monday_keyword() { return literal_type(L"Monday"); }
259 static literal_type short_monday_keyword() { return literal_type(L"Mon"); }
260 static literal_type tuesday_keyword() { return literal_type(L"Tuesday"); }
261 static literal_type short_tuesday_keyword() { return literal_type(L"Tue"); }
262 static literal_type wednesday_keyword() { return literal_type(L"Wednesday"); }
263 static literal_type short_wednesday_keyword() { return literal_type(L"Wed"); }
264 static literal_type thursday_keyword() { return literal_type(L"Thursday"); }
265 static literal_type short_thursday_keyword() { return literal_type(L"Thu"); }
266 static literal_type friday_keyword() { return literal_type(L"Friday"); }
267 static literal_type short_friday_keyword() { return literal_type(L"Fri"); }
268 static literal_type saturday_keyword() { return literal_type(L"Saturday"); }
269 static literal_type short_saturday_keyword() { return literal_type(L"Sat"); }
270 static literal_type sunday_keyword() { return literal_type(L"Sunday"); }
271 static literal_type short_sunday_keyword() { return literal_type(L"Sun"); }
272
273 static std::wostream& get_console_log_stream() { return std::wclog; }
274
275 static int to_number(char_type c)
276 {
277 int n = 0;
278 if (c >= L'0' && c <= L'9')
279 n = c - L'0';
280 else if (c >= L'a' && c <= L'f')
281 n = c - L'a' + 10;
282 else if (c >= L'A' && c <= L'F')
283 n = c - L'A' + 10;
284 return n;
285 }
286
287 static bool iswxdigit(char_type c)
288 {
289 return (c >= L'0' && c <= L'9') || (c >= L'a' && c <= L'f') || (c >= L'A' && c <= L'F');
290 }
291
292 //! Skips spaces in the beginning of the input
293 static const char_type* trim_spaces_left(const char_type* begin, const char_type* end);
294 //! Skips spaces in the end of the input
295 static const char_type* trim_spaces_right(const char_type* begin, const char_type* end);
296 //! Scans for the attribute name placeholder in the input
297 static const char_type* scan_attr_placeholder(const char_type* begin, const char_type* end);
298 //! Parses an operand string (possibly quoted) from the input
299 static const char_type* parse_operand(const char_type* begin, const char_type* end, string_type& operand);
300 //! Converts escape sequences to the corresponding characters
301 static void translate_escape_sequences(string_type& str);
302 };
303 #endif
304
305 } // namespace aux
306
307 BOOST_LOG_CLOSE_NAMESPACE // namespace log
308
309 } // namespace boost
310
311 #include <boost/log/detail/footer.hpp>
312
313 #endif // BOOST_LOG_PARSER_UTILS_HPP_INCLUDED_