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
30namespace boost {
31
32BOOST_LOG_OPEN_NAMESPACE
33
34namespace aux {
35
36//! Some constants and algorithms needed for parsing
37template< typename > struct char_constants;
38
39#ifdef BOOST_LOG_USE_CHAR
40template< >
41struct 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* auto_newline_mode_param_name() { return "AutoNewline"; }
101 static const char_type* asynchronous_param_name() { return "Asynchronous"; }
102 static const char_type* format_param_name() { return "Format"; }
103 static const char_type* provider_id_param_name() { return "ProviderID"; }
104 static const char_type* log_name_param_name() { return "LogName"; }
105 static const char_type* source_name_param_name() { return "LogSource"; }
106 static const char_type* registration_param_name() { return "Registration"; }
107 static const char_type* local_address_param_name() { return "LocalAddress"; }
108 static const char_type* target_address_param_name() { return "TargetAddress"; }
109 static const char_type* target_param_name() { return "Target"; }
110 static const char_type* max_size_param_name() { return "MaxSize"; }
111 static const char_type* max_files_param_name() { return "MaxFiles"; }
112 static const char_type* min_free_space_param_name() { return "MinFreeSpace"; }
113 static const char_type* scan_for_files_param_name() { return "ScanForFiles"; }
114
115 static const char_type* scan_method_all() { return "All"; }
116 static const char_type* scan_method_matching() { return "Matching"; }
117
118 static const char_type* auto_newline_mode_disabled() { return "Disabled"; }
119 static const char_type* auto_newline_mode_always_insert() { return "AlwaysInsert"; }
120 static const char_type* auto_newline_mode_insert_if_missing() { return "InsertIfMissing"; }
121
122 static const char_type* registration_never() { return "Never"; }
123 static const char_type* registration_on_demand() { return "OnDemand"; }
124 static const char_type* registration_forced() { return "Forced"; }
125
126 static const char_type* text_file_destination() { return "TextFile"; }
127 static const char_type* console_destination() { return "Console"; }
128 static const char_type* syslog_destination() { return "Syslog"; }
129 static const char_type* simple_event_log_destination() { return "SimpleEventLog"; }
130 static const char_type* debugger_destination() { return "Debugger"; }
131
132 static literal_type monday_keyword() { return literal_type("Monday"); }
133 static literal_type short_monday_keyword() { return literal_type("Mon"); }
134 static literal_type tuesday_keyword() { return literal_type("Tuesday"); }
135 static literal_type short_tuesday_keyword() { return literal_type("Tue"); }
136 static literal_type wednesday_keyword() { return literal_type("Wednesday"); }
137 static literal_type short_wednesday_keyword() { return literal_type("Wed"); }
138 static literal_type thursday_keyword() { return literal_type("Thursday"); }
139 static literal_type short_thursday_keyword() { return literal_type("Thu"); }
140 static literal_type friday_keyword() { return literal_type("Friday"); }
141 static literal_type short_friday_keyword() { return literal_type("Fri"); }
142 static literal_type saturday_keyword() { return literal_type("Saturday"); }
143 static literal_type short_saturday_keyword() { return literal_type("Sat"); }
144 static literal_type sunday_keyword() { return literal_type("Sunday"); }
145 static literal_type short_sunday_keyword() { return literal_type("Sun"); }
146
147 static std::ostream& get_console_log_stream() { return std::clog; }
148
149 static int to_number(char_type c)
150 {
151 using namespace std; // to make sure we can use C functions unqualified
152 int n = 0;
153 if (isdigit(c))
154 n = c - '0';
155 else if (c >= 'a' && c <= 'f')
156 n = c - 'a' + 10;
157 else if (c >= 'A' && c <= 'F')
158 n = c - 'A' + 10;
159 return n;
160 }
161
162 //! Skips spaces in the beginning of the input
163 static const char_type* trim_spaces_left(const char_type* begin, const char_type* end);
164 //! Skips spaces in the end of the input
165 static const char_type* trim_spaces_right(const char_type* begin, const char_type* end);
166 //! Scans for the attribute name placeholder in the input
167 static const char_type* scan_attr_placeholder(const char_type* begin, const char_type* end);
168 //! Parses an operand string (possibly quoted) from the input
169 static const char_type* parse_operand(const char_type* begin, const char_type* end, string_type& operand);
170 //! Converts escape sequences to the corresponding characters
171 static void translate_escape_sequences(string_type& str);
172};
173#endif
174
175#ifdef BOOST_LOG_USE_WCHAR_T
176template< >
177struct char_constants< wchar_t >
178{
179 typedef wchar_t char_type;
180 typedef std::basic_string< char_type > string_type;
181 typedef boost::log::basic_string_literal< char_type > literal_type;
182
183 static const char_type char_comment = L'#';
184 static const char_type char_comma = L',';
185 static const char_type char_dot = L'.';
186 static const char_type char_quote = L'"';
187 static const char_type char_percent = L'%';
188 static const char_type char_exclamation = L'!';
189 static const char_type char_and = L'&';
190 static const char_type char_or = L'|';
191 static const char_type char_equal = L'=';
192 static const char_type char_greater = L'>';
193 static const char_type char_less = L'<';
194 static const char_type char_underline = L'_';
195 static const char_type char_backslash = L'\\';
196 static const char_type char_section_bracket_left = L'[';
197 static const char_type char_section_bracket_right = L']';
198 static const char_type char_paren_bracket_left = L'(';
199 static const char_type char_paren_bracket_right = L')';
200
201 static const char_type* not_keyword() { return L"not"; }
202 static const char_type* and_keyword() { return L"and"; }
203 static const char_type* or_keyword() { return L"or"; }
204 static const char_type* equal_keyword() { return L"="; }
205 static const char_type* greater_keyword() { return L">"; }
206 static const char_type* less_keyword() { return L"<"; }
207 static const char_type* not_equal_keyword() { return L"!="; }
208 static const char_type* greater_or_equal_keyword() { return L">="; }
209 static const char_type* less_or_equal_keyword() { return L"<="; }
210 static const char_type* begins_with_keyword() { return L"begins_with"; }
211 static const char_type* ends_with_keyword() { return L"ends_with"; }
212 static const char_type* contains_keyword() { return L"contains"; }
213 static const char_type* matches_keyword() { return L"matches"; }
214
215 static const char_type* message_text_keyword() { return L"_"; }
216
217 static literal_type true_keyword() { return literal_type(L"true"); }
218 static literal_type false_keyword() { return literal_type(L"false"); }
219
220 static const char_type* default_level_attribute_name() { return L"Severity"; }
221
222 static const char_type* core_section_name() { return L"Core"; }
223 static const char_type* sink_section_name_prefix() { return L"Sink:"; }
224
225 static const char_type* core_disable_logging_param_name() { return L"DisableLogging"; }
226 static const char_type* filter_param_name() { return L"Filter"; }
227
228 static const char_type* sink_destination_param_name() { return L"Destination"; }
229 static const char_type* file_name_param_name() { return L"FileName"; }
230 static const char_type* rotation_size_param_name() { return L"RotationSize"; }
231 static const char_type* rotation_interval_param_name() { return L"RotationInterval"; }
232 static const char_type* rotation_time_point_param_name() { return L"RotationTimePoint"; }
233 static const char_type* append_param_name() { return L"Append"; }
234 static const char_type* enable_final_rotation_param_name() { return L"EnableFinalRotation"; }
235 static const char_type* auto_flush_param_name() { return L"AutoFlush"; }
236 static const char_type* auto_newline_mode_param_name() { return L"AutoNewline"; }
237 static const char_type* asynchronous_param_name() { return L"Asynchronous"; }
238 static const char_type* format_param_name() { return L"Format"; }
239 static const char_type* provider_id_param_name() { return L"ProviderID"; }
240 static const char_type* log_name_param_name() { return L"LogName"; }
241 static const char_type* source_name_param_name() { return L"LogSource"; }
242 static const char_type* registration_param_name() { return L"Registration"; }
243 static const char_type* local_address_param_name() { return L"LocalAddress"; }
244 static const char_type* target_address_param_name() { return L"TargetAddress"; }
245 static const char_type* target_param_name() { return L"Target"; }
246 static const char_type* max_size_param_name() { return L"MaxSize"; }
247 static const char_type* max_files_param_name() { return L"MaxFiles"; }
248 static const char_type* min_free_space_param_name() { return L"MinFreeSpace"; }
249 static const char_type* scan_for_files_param_name() { return L"ScanForFiles"; }
250
251 static const char_type* scan_method_all() { return L"All"; }
252 static const char_type* scan_method_matching() { return L"Matching"; }
253
254 static const char_type* auto_newline_mode_disabled() { return L"Disabled"; }
255 static const char_type* auto_newline_mode_always_insert() { return L"AlwaysInsert"; }
256 static const char_type* auto_newline_mode_insert_if_missing() { return L"InsertIfMissing"; }
257
258 static const char_type* registration_never() { return L"Never"; }
259 static const char_type* registration_on_demand() { return L"OnDemand"; }
260 static const char_type* registration_forced() { return L"Forced"; }
261
262 static const char_type* text_file_destination() { return L"TextFile"; }
263 static const char_type* console_destination() { return L"Console"; }
264 static const char_type* syslog_destination() { return L"Syslog"; }
265 static const char_type* simple_event_log_destination() { return L"SimpleEventLog"; }
266 static const char_type* debugger_destination() { return L"Debugger"; }
267
268 static literal_type monday_keyword() { return literal_type(L"Monday"); }
269 static literal_type short_monday_keyword() { return literal_type(L"Mon"); }
270 static literal_type tuesday_keyword() { return literal_type(L"Tuesday"); }
271 static literal_type short_tuesday_keyword() { return literal_type(L"Tue"); }
272 static literal_type wednesday_keyword() { return literal_type(L"Wednesday"); }
273 static literal_type short_wednesday_keyword() { return literal_type(L"Wed"); }
274 static literal_type thursday_keyword() { return literal_type(L"Thursday"); }
275 static literal_type short_thursday_keyword() { return literal_type(L"Thu"); }
276 static literal_type friday_keyword() { return literal_type(L"Friday"); }
277 static literal_type short_friday_keyword() { return literal_type(L"Fri"); }
278 static literal_type saturday_keyword() { return literal_type(L"Saturday"); }
279 static literal_type short_saturday_keyword() { return literal_type(L"Sat"); }
280 static literal_type sunday_keyword() { return literal_type(L"Sunday"); }
281 static literal_type short_sunday_keyword() { return literal_type(L"Sun"); }
282
283 static std::wostream& get_console_log_stream() { return std::wclog; }
284
285 static int to_number(char_type c)
286 {
287 int n = 0;
288 if (c >= L'0' && c <= L'9')
289 n = c - L'0';
290 else if (c >= L'a' && c <= L'f')
291 n = c - L'a' + 10;
292 else if (c >= L'A' && c <= L'F')
293 n = c - L'A' + 10;
294 return n;
295 }
296
297 static bool iswxdigit(char_type c)
298 {
299 return (c >= L'0' && c <= L'9') || (c >= L'a' && c <= L'f') || (c >= L'A' && c <= L'F');
300 }
301
302 //! Skips spaces in the beginning of the input
303 static const char_type* trim_spaces_left(const char_type* begin, const char_type* end);
304 //! Skips spaces in the end of the input
305 static const char_type* trim_spaces_right(const char_type* begin, const char_type* end);
306 //! Scans for the attribute name placeholder in the input
307 static const char_type* scan_attr_placeholder(const char_type* begin, const char_type* end);
308 //! Parses an operand string (possibly quoted) from the input
309 static const char_type* parse_operand(const char_type* begin, const char_type* end, string_type& operand);
310 //! Converts escape sequences to the corresponding characters
311 static void translate_escape_sequences(string_type& str);
312};
313#endif
314
315} // namespace aux
316
317BOOST_LOG_CLOSE_NAMESPACE // namespace log
318
319} // namespace boost
320
321#include <boost/log/detail/footer.hpp>
322
323#endif // BOOST_LOG_PARSER_UTILS_HPP_INCLUDED_
324

source code of boost/libs/log/src/setup/parser_utils.hpp