/src/logging-log4cxx/src/main/include/log4cxx/helpers/charsetdecoder.h
Line | Count | Source |
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 | | #ifndef _LOG4CXX_HELPERS_CHARSETDECODER_H |
19 | | #define _LOG4CXX_HELPERS_CHARSETDECODER_H |
20 | | |
21 | | #include <log4cxx/helpers/object.h> |
22 | | |
23 | | namespace LOG4CXX_NS |
24 | | { |
25 | | namespace helpers |
26 | | { |
27 | | class CharsetDecoder; |
28 | | LOG4CXX_PTR_DEF(CharsetDecoder); |
29 | | class ByteBuffer; |
30 | | |
31 | | |
32 | | /** |
33 | | * An abstract engine to transform a sequences of bytes in a specific charset |
34 | | * into a LogString. |
35 | | */ |
36 | | class LOG4CXX_EXPORT CharsetDecoder : public Object |
37 | | { |
38 | | public: |
39 | | DECLARE_ABSTRACT_LOG4CXX_OBJECT(CharsetDecoder) |
40 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
41 | 0 | LOG4CXX_CAST_ENTRY(CharsetDecoder) |
42 | 0 | END_LOG4CXX_CAST_MAP() |
43 | | protected: |
44 | | /** |
45 | | * Protected constructor. |
46 | | */ |
47 | | CharsetDecoder(); |
48 | | public: |
49 | | /** |
50 | | * Destructor. |
51 | | */ |
52 | | virtual ~CharsetDecoder(); |
53 | | |
54 | | /** |
55 | | * Get decoder for default charset. |
56 | | */ |
57 | | static CharsetDecoderPtr getDefaultDecoder(); |
58 | | /** |
59 | | * Get decoder for specified character set. |
60 | | * @param charset the following values should be recognized: |
61 | | * "US-ASCII", "ISO-8859-1", "UTF-8", |
62 | | * "UTF-16BE", "UTF-16LE". |
63 | | * @return decoder |
64 | | * @throws IllegalArgumentException if charset is not recognized. |
65 | | */ |
66 | | static CharsetDecoderPtr getDecoder(const LogString& charset); |
67 | | |
68 | | /** |
69 | | * Get decoder for UTF-8. |
70 | | */ |
71 | | static CharsetDecoderPtr getUTF8Decoder(); |
72 | | /** |
73 | | * Get decoder for ISO-8859-1. |
74 | | */ |
75 | | static CharsetDecoderPtr getISOLatinDecoder(); |
76 | | |
77 | | |
78 | | |
79 | | /** |
80 | | * Decodes as many bytes as possible from \c in, |
81 | | * appending the result onto \c out. |
82 | | * @param in a null terminated string. |
83 | | * @param out the string onto which characters are appended. |
84 | | * @return APR_SUCCESS if not encoding errors were found. |
85 | | */ |
86 | | virtual log4cxx_status_t decode(ByteBuffer& in, LogString& out) = 0; |
87 | | |
88 | | |
89 | | /** |
90 | | * Decodes up to \c maxByteCount bytes from \c in, |
91 | | * appending the result onto \c out. |
92 | | * @param in a null terminated string. |
93 | | * @param maxByteCount the limit on the size of \c in. |
94 | | * @param out the string onto which characters are appended. |
95 | | * @return APR_SUCCESS if not encoding errors were found. |
96 | | */ |
97 | | log4cxx_status_t decode(const char* in, size_t maxByteCount, LogString& out); |
98 | | |
99 | | /** |
100 | | * Determins if status value indicates an invalid byte sequence. |
101 | | */ |
102 | | inline static bool isError(log4cxx_status_t stat) |
103 | 4.84M | { |
104 | 4.84M | return (stat != 0); |
105 | 4.84M | } |
106 | | |
107 | | private: |
108 | | /** |
109 | | * Private copy constructor. |
110 | | */ |
111 | | CharsetDecoder(const CharsetDecoder&); |
112 | | /** |
113 | | * Private assignment operator. |
114 | | */ |
115 | | CharsetDecoder& operator=(const CharsetDecoder&); |
116 | | /** |
117 | | * Creates a new decoder for the default charset. |
118 | | */ |
119 | | static CharsetDecoder* createDefaultDecoder(); |
120 | | }; |
121 | | |
122 | | } // namespace helpers |
123 | | } //namespace log4cxx |
124 | | |
125 | | #endif //_LOG4CXX_HELPERS_CHARSETENCODER_H |