Apache log4cxx  Version 0.12.1
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 #if defined(_MSC_VER)
23  #pragma warning (push)
24  #pragma warning ( disable: 4231 4251 4275 4786 )
25 #endif
26 
27 
28 
29 #include <map>
30 #include <vector>
31 #include <log4cxx/helpers/class.h>
34 
35 namespace log4cxx
36 {
37 namespace pattern
38 {
39 
40 typedef PatternConverterPtr (*PatternConstructor)(const std::vector<LogString>& options);
41 typedef std::map<LogString, PatternConstructor> PatternMap;
42 
43 
44 // Contributors: Nelson Minar <(nelson@monkey.org>
45 // Igor E. Poteryaev <jah@mail.ru>
46 // Reinhard Deschler <reinhard.deschler@web.de>
47 
56 class LOG4CXX_EXPORT PatternParser
57 {
61  static const logchar ESCAPE_CHAR;
62 
63  enum
64  {
65  LITERAL_STATE = 0,
66  CONVERTER_STATE = 1,
67  DOT_STATE = 3,
68  MIN_STATE = 4,
69  MAX_STATE = 5
70  };
71 
75  PatternParser();
76 
77  private:
93  static size_t extractConverter(
94  logchar lastChar, const LogString& pattern,
95  LogString::size_type i, LogString& convBuf,
96  LogString& currentLiteral);
97 
105  static size_t extractOptions(const LogString& pattern, LogString::size_type i,
106  std::vector<LogString>& options);
107 
108  public:
116  static void parse(
117  const LogString& pattern,
118  std::vector<PatternConverterPtr>& patternConverters,
119  std::vector<FormattingInfoPtr>& formattingInfos,
120  const PatternMap& rules);
121 
122  private:
134  static PatternConverterPtr createConverter(
135  const LogString& converterId,
136  LogString& currentLiteral,
137  const PatternMap& rules,
138  std::vector<LogString>& options);
139 
153  static size_t finalizeConverter(
154  logchar c, const LogString& pattern, size_t i,
155  LogString& currentLiteral, const FormattingInfoPtr& formattingInfo,
156  const PatternMap& rules,
157  std::vector<PatternConverterPtr>& patternConverters,
158  std::vector<FormattingInfoPtr>& formattingInfos);
159 
160  static bool isUnicodeIdentifierStart(logchar c);
161  static bool isUnicodeIdentifierPart(logchar c);
162 
163 
164 };
165 
166 }
167 }
168 
169 
170 #if defined(_MSC_VER)
171  #pragma warning (pop)
172 #endif
173 
174 
175 #endif
std::shared_ptr< FormattingInfo > FormattingInfoPtr
Definition: formattinginfo.h:31
Most of the work of the PatternLayout class is delegated to the PatternParser class.
Definition: patternparser.h:56
PatternConverterPtr(* PatternConstructor)(const std::vector< LogString > &options)
Definition: patternparser.h:40
std::map< LogString, PatternConstructor > PatternMap
Definition: patternparser.h:41
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66