Apache Log4cxx  Version 1.2.0
Loading...
Searching...
No Matches
log4cxx/helpers/transcoder.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#ifndef _LOG4CXX_HELPERS_TRANSCODER_H
19#define _LOG4CXX_HELPERS_TRANSCODER_H
20
21#include <log4cxx/logstring.h>
22
23
24namespace LOG4CXX_NS
25{
26namespace helpers
27{
28class ByteBuffer;
29class Pool;
36class LOG4CXX_EXPORT Transcoder
37{
38 public:
39
40
44 static void decodeUTF8(const std::string& src, LogString& dst);
48 static void encodeUTF8(const LogString& src, std::string& dst);
52 static char* encodeUTF8(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
56 static void encodeUTF8(unsigned int sv, ByteBuffer& dst);
60 static void encodeUTF16LE(unsigned int sv, ByteBuffer& dst);
64 static void encodeUTF16BE(unsigned int sv, ByteBuffer& dst);
65
66
74 static unsigned int decode(const std::string& in,
75 std::string::const_iterator& iter);
76
82 static void encode(unsigned int ch, std::string& dst);
83
88 static void decode(const std::string& src, LogString& dst);
89
95 static void encode(const LogString& src, std::string& dst);
96
104 static char* encode(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
105
106
107
108#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T || defined(WIN32) || defined(_WIN32)
109 static void decode(const std::wstring& src, LogString& dst);
110 static void encode(const LogString& src, std::wstring& dst);
111 static wchar_t* wencode(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
112
120 static unsigned int decode(const std::wstring& in,
121 std::wstring::const_iterator& iter);
122
128 static void encode(unsigned int ch, std::wstring& dst);
129
130#endif
131
132
133#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
134 static void decode(const std::basic_string<UniChar>& src, LogString& dst);
135 static void encode(const LogString& src, std::basic_string<UniChar>& dst);
136
144 static unsigned int decode(const std::basic_string<UniChar>& in,
145 std::basic_string<UniChar>::const_iterator& iter);
146
152 static void encode(unsigned int ch, std::basic_string<UniChar>& dst);
153
154#endif
155
156#if LOG4CXX_CFSTRING_API
157 static void decode(const CFStringRef& src, LogString& dst);
158 static CFStringRef encode(const LogString& src);
159#endif
160
161 enum { LOSSCHAR = 0x3F };
162
167 static logchar decode(char v);
172 static LogString decode(const char* v);
173
178 static std::string encodeCharsetName(const LogString& charsetName);
179
180 private:
181
182 private:
183 Transcoder();
184 Transcoder(const Transcoder&);
185 Transcoder& operator=(const Transcoder&);
186 enum { BUFSIZE = 256 };
187 static size_t encodeUTF8(unsigned int ch, char* dst);
188 static size_t encodeUTF16BE(unsigned int ch, char* dst);
189 static size_t encodeUTF16LE(unsigned int ch, char* dst);
190
191};
192}
193}
194
195#if LOG4CXX_CHARSET_UTF8 && LOG4CXX_LOGCHAR_IS_UTF8
205#define LOG4CXX_ENCODE_CHAR(var, src) \
206 const std::string& var = src
207
217#define LOG4CXX_DECODE_CHAR(var, src) \
218 const LOG4CXX_NS::LogString& var = src
219
220#else
230#define LOG4CXX_ENCODE_CHAR(var, src) \
231 std::string var; \
232 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
233
243#define LOG4CXX_DECODE_CHAR(var, src) \
244 LOG4CXX_NS::LogString var; \
245 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
246#endif
247
257#define LOG4CXX_DECODE_CFSTRING(var, src) \
258 LOG4CXX_NS::LogString var; \
259 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
260
270#define LOG4CXX_ENCODE_CFSTRING(var, src) \
271 CFStringRef var = LOG4CXX_NS::helpers::Transcoder::encode(src)
272
273#if LOG4CXX_LOGCHAR_IS_WCHAR
283#define LOG4CXX_ENCODE_WCHAR(var, src) \
284 const std::wstring& var = src
285
295#define LOG4CXX_DECODE_WCHAR(var, src) \
296 const LOG4CXX_NS::LogString& var = src
297
298#else
308#define LOG4CXX_ENCODE_WCHAR(var, src) \
309 std::wstring var; \
310 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
311
321#define LOG4CXX_DECODE_WCHAR(var, src) \
322 LOG4CXX_NS::LogString var; \
323 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
324
325#endif
326
327#if LOG4CXX_LOGCHAR_IS_UNICHAR
328
338#define LOG4CXX_ENCODE_UNICHAR(var, src) \
339 const std::basic_string<UniChar>& var = src
340
350#define LOG4CXX_DECODE_UNICHAR(var, src) \
351 const LOG4CXX_NS::LogString& var = src
352
353#else
354
364#define LOG4CXX_ENCODE_UNICHAR(var, src) \
365 std::basic_string<UniChar> var; \
366 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
367
377#define LOG4CXX_DECODE_UNICHAR(var, src) \
378 LOG4CXX_NS::LogString var; \
379 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
380
381#endif
382
383#endif //_LOG4CXX_HELPERS_TRANSCODER_H
A byte buffer.
Definition: bytebuffer.h:34
Simple transcoder for converting between external char and wchar_t strings and internal strings.
Definition: log4cxx/helpers/transcoder.h:37
static void decode(const std::basic_string< UniChar > &src, LogString &dst)
static unsigned int decode(const std::string &in, std::string::const_iterator &iter)
Decodes next character from a UTF-8 string.
static void encode(const LogString &src, std::basic_string< UniChar > &dst)
static void encodeUTF16LE(unsigned int sv, ByteBuffer &dst)
Append UCS-4 code point to a byte buffer as UTF-16LE.
static void encodeUTF16BE(unsigned int sv, ByteBuffer &dst)
Append UCS-4 code point to a byte buffer as UTF-16BE.
static void decode(const std::wstring &src, LogString &dst)
static wchar_t * wencode(const LogString &src, log4cxx::helpers::Pool &p)
static void encode(const LogString &src, std::wstring &dst)
static void encode(const LogString &src, std::string &dst)
Appends a LogString to a string in the current code-page.
static void encodeUTF8(const LogString &src, std::string &dst)
Converts the LogString to a UTF-8 string.
static char * encode(const LogString &src, log4cxx::helpers::Pool &p)
Encodes the specified LogString to the current character set.
static unsigned int decode(const std::wstring &in, std::wstring::const_iterator &iter)
Decodes next character from a wstring.
static std::string encodeCharsetName(const LogString &charsetName)
Encodes a charset name in the default encoding without using a CharsetEncoder (which could trigger re...
static char * encodeUTF8(const LogString &src, log4cxx::helpers::Pool &p)
Converts the LogString to a UTF-8 string.
static CFStringRef encode(const LogString &src)
static void decodeUTF8(const std::string &src, LogString &dst)
Appends this specified string of UTF-8 characters to LogString.
static unsigned int decode(const std::basic_string< UniChar > &in, std::basic_string< UniChar >::const_iterator &iter)
Decodes next character from a UniChar string.
static void encode(unsigned int ch, std::basic_string< UniChar > &dst)
Appends UCS-4 value to a UTF-8 string.
static logchar decode(char v)
Returns a logchar value given a character literal in the ASCII charset.
static void encode(unsigned int ch, std::wstring &dst)
Appends UCS-4 value to a UTF-8 string.
static LogString decode(const char *v)
Returns a LogString given a string literal in the ASCII charset.
static void encode(unsigned int ch, std::string &dst)
Appends UCS-4 value to a UTF-8 string.
static void decode(const CFStringRef &src, LogString &dst)
static void decode(const std::string &src, LogString &dst)
Appends string in the current code-page to a LogString.
static void encodeUTF8(unsigned int sv, ByteBuffer &dst)
Append UCS-4 code point to a byte buffer as UTF-8.
const struct __CFString * CFStringRef
Definition: logstring.h:30
std::basic_string< logchar > LogString
Definition: logstring.h:60