Apache Log4cxx  Version 1.7.0
patternparser.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 
19 #ifndef _LOG4CXX_HELPER_PATTERN_CONVERTER_H
20 #define _LOG4CXX_HELPER_PATTERN_CONVERTER_H
21 
22 #include <map>
23 #include <vector>
24 #include <functional>
25 #include <log4cxx/helpers/class.h>
28 
29 namespace LOG4CXX_NS
30 {
31 namespace pattern
32 {
33 
34 typedef std::function<PatternConverterPtr(const std::vector<LogString>& options)> PatternConstructor;
35 typedef std::map<LogString, PatternConstructor> PatternMap;
36 LOG4CXX_LIST_DEF(PatternConverterList, PatternConverterPtr);
37 
38 // Contributors: Nelson Minar <(nelson@monkey.org>
39 // Igor E. Poteryaev <jah@mail.ru>
40 // Reinhard Deschler <reinhard.deschler@web.de>
41 
50 class LOG4CXX_EXPORT PatternParser
51 {
55  static const logchar ESCAPE_CHAR;
56 
57  enum
58  {
59  LITERAL_STATE = 0,
60  CONVERTER_STATE = 1,
61  DOT_STATE = 3,
62  MIN_STATE = 4,
63  MAX_STATE = 5
64  };
65 
69  PatternParser();
70 
71  private:
87  static size_t extractConverter(
88  logchar lastChar, const LogString& pattern,
89  LogString::size_type i, LogString& convBuf,
90  LogString& currentLiteral);
91 
99  static size_t extractOptions(const LogString& pattern, LogString::size_type i,
100  std::vector<LogString>& options);
101 
102  public:
103 #if LOG4CXX_ABI_VERSION <= 15
112  [[ deprecated( "Parsing into two vectors is longer supported" ) ]]
113  static void parse(
114  const LogString& pattern,
115  std::vector<PatternConverterPtr>& patternConverters,
116  std::vector<FormattingInfoPtr>& formattingInfos,
117  const PatternMap& rules);
118 #endif
124  static PatternConverterList parse
125  ( const LogString& pattern
126  , const PatternMap& rules
127  );
128 
129  private:
141  static PatternConverterPtr createConverter(
142  const LogString& converterId,
143  LogString& currentLiteral,
144  const PatternMap& rules,
145  std::vector<LogString>& options);
146 
160  static size_t finalizeConverter(
161  logchar c, const LogString& pattern, size_t i,
162  LogString& currentLiteral, const FormattingInfoPtr& formattingInfo,
163  const PatternMap& rules,
164  PatternConverterList& patternConverter
165  );
166 
167  static bool isUnicodeIdentifierStart(logchar c);
168  static bool isUnicodeIdentifierPart(logchar c);
169 
170 
171 };
172 
173 }
174 }
175 
176 
177 #endif
Most of the work of the PatternLayout class is delegated to the PatternParser class.
Definition: patternparser.h:51
static void parse(const LogString &pattern, std::vector< PatternConverterPtr > &patternConverters, std::vector< FormattingInfoPtr > &formattingInfos, const PatternMap &rules)
Parse a format specifier.
static PatternConverterList parse(const LogString &pattern, const PatternMap &rules)
Convert pattern to converters using rules.
std::function< PatternConverterPtr(const std::vector< LogString > &options)> PatternConstructor
Definition: patternparser.h:34
std::map< LogString, PatternConstructor > PatternMap
Definition: patternparser.h:35
std::shared_ptr< FormattingInfo > FormattingInfoPtr
Definition: formattinginfo.h:31
LOG4CXX_LIST_DEF(PatternConverterList, PatternConverterPtr)
std::basic_string< logchar > LogString
Definition: logstring.h:60