Apache Log4cxx  Version 1.3.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 #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 
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:
110  static void parse(
111  const LogString& pattern,
112  std::vector<PatternConverterPtr>& patternConverters,
113  std::vector<FormattingInfoPtr>& formattingInfos,
114  const PatternMap& rules);
115 
116  private:
128  static PatternConverterPtr createConverter(
129  const LogString& converterId,
130  LogString& currentLiteral,
131  const PatternMap& rules,
132  std::vector<LogString>& options);
133 
147  static size_t finalizeConverter(
148  logchar c, const LogString& pattern, size_t i,
149  LogString& currentLiteral, const FormattingInfoPtr& formattingInfo,
150  const PatternMap& rules,
151  std::vector<PatternConverterPtr>& patternConverters,
152  std::vector<FormattingInfoPtr>& formattingInfos);
153 
154  static bool isUnicodeIdentifierStart(logchar c);
155  static bool isUnicodeIdentifierPart(logchar c);
156 
157 
158 };
159 
160 }
161 }
162 
163 
164 #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.
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
std::basic_string< logchar > LogString
Definition: logstring.h:60