Apache Log4cxx  Version 1.8.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;
33class LOG4CXX_EXPORT Transcoder
34{
35 public:
36
37
41 static void decodeUTF8(const std::string& src, LogString& dst);
45 static void encodeUTF8(const LogString& src, std::string& dst);
46#if LOG4CXX_ABI_VERSION <= 15
51 [[ deprecated( "Use the encodeUTF8() without a Pool parameter" ) ]]
52 static char* encodeUTF8(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
53#endif
57 static void encodeUTF8(unsigned int sv, ByteBuffer& dst);
61 static void encodeUTF16LE(unsigned int sv, ByteBuffer& dst);
65 static void encodeUTF16BE(unsigned int sv, ByteBuffer& dst);
66
67
76 static unsigned int decode(const std::string& str,
77 std::string::const_iterator& iter);
78
82 static void encode(unsigned int ch, std::string& dst);
83
87 static void decode(const std::string& src, LogString& dst);
88
94 static void encode(const LogString& src, std::string& dst);
95
96#if LOG4CXX_ABI_VERSION <= 15
105 [[ deprecated( "Use an encode() without a Pool parameter" ) ]]
106 static char* encode(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
107#endif
108
109
110#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR || defined(WIN32) || defined(_WIN32)
114 static void decode(const std::wstring& src, LogString& dst);
118 static void encode(const LogString& src, std::wstring& dst);
119#if LOG4CXX_ABI_VERSION <= 15
121 static wchar_t* wencode(const LogString& src, LOG4CXX_NS::helpers::Pool& p);
122#endif
131 static unsigned int decode(const std::wstring& str,
132 std::wstring::const_iterator& iter);
133
137 static void encode(unsigned int ch, std::wstring& dst);
138
139#endif
140
141
142#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
146 static void decode(const std::basic_string<UniChar>& src, LogString& dst);
150 static void encode(const LogString& src, std::basic_string<UniChar>& dst);
151
160 static unsigned int decode(const std::basic_string<UniChar>& str,
161 std::basic_string<UniChar>::const_iterator& iter);
162
166 static void encode(unsigned int ch, std::basic_string<UniChar>& dst);
167
168#endif
169
170#if LOG4CXX_CFSTRING_API
174 static void decode(const CFStringRef& src, LogString& dst);
176 static CFStringRef encode(const LogString& src);
177#endif
178
179 enum { LOSSCHAR = 0x3F };
180
184 static logchar decode(char ch);
188 static LogString decode(const char* str);
189
194 static std::string encodeCharsetName(const LogString& charsetName);
195
196 private:
197
198 private:
199 Transcoder();
200 Transcoder(const Transcoder&);
201 Transcoder& operator=(const Transcoder&);
202 enum { BUFSIZE = 256 };
203 static size_t encodeUTF8(unsigned int ch, char* dst);
204 static size_t encodeUTF16BE(unsigned int ch, char* dst);
205 static size_t encodeUTF16LE(unsigned int ch, char* dst);
206
207};
208}
209}
210
211#if LOG4CXX_CHARSET_UTF8 && LOG4CXX_LOGCHAR_IS_UTF8
221#define LOG4CXX_ENCODE_CHAR(var, src) \
222 const std::string& var = src
223
233#define LOG4CXX_DECODE_CHAR(var, src) \
234 const LOG4CXX_NS::LogString& var = src
235
236#else
246#define LOG4CXX_ENCODE_CHAR(var, src) \
247 std::string var; \
248 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
249
259#define LOG4CXX_DECODE_CHAR(var, src) \
260 LOG4CXX_NS::LogString var; \
261 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
262#endif
263
273#define LOG4CXX_DECODE_CFSTRING(var, src) \
274 LOG4CXX_NS::LogString var; \
275 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
276
286#define LOG4CXX_ENCODE_CFSTRING(var, src) \
287 CFStringRef var = LOG4CXX_NS::helpers::Transcoder::encode(src)
288
289#if LOG4CXX_LOGCHAR_IS_WCHAR
299#define LOG4CXX_ENCODE_WCHAR(var, src) \
300 const std::wstring& var = src
301
311#define LOG4CXX_DECODE_WCHAR(var, src) \
312 const LOG4CXX_NS::LogString& var = src
313
314#else
324#define LOG4CXX_ENCODE_WCHAR(var, src) \
325 std::wstring var; \
326 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
327
337#define LOG4CXX_DECODE_WCHAR(var, src) \
338 LOG4CXX_NS::LogString var; \
339 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
340
341#endif
342
343#if LOG4CXX_LOGCHAR_IS_UNICHAR
344
354#define LOG4CXX_ENCODE_UNICHAR(var, src) \
355 const std::basic_string<UniChar>& var = src
356
366#define LOG4CXX_DECODE_UNICHAR(var, src) \
367 const LOG4CXX_NS::LogString& var = src
368
369#else
370
380#define LOG4CXX_ENCODE_UNICHAR(var, src) \
381 std::basic_string<UniChar> var; \
382 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
383
393#define LOG4CXX_DECODE_UNICHAR(var, src) \
394 LOG4CXX_NS::LogString var; \
395 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
396
397#endif
398
399#endif //_LOG4CXX_HELPERS_TRANSCODER_H
An area of memory and a cursor into that memory.
Definition bytebuffer.h:41
static void decode(const std::basic_string< UniChar > &src, LogString &dst)
Append the LogString equivalent of src onto dst.
static void encode(const LogString &src, std::basic_string< UniChar > &dst)
Append the equivalent of src onto dst.
static void encodeUTF16LE(unsigned int sv, ByteBuffer &dst)
Append the code point sv to dst as UTF-16LE.
static LogString decode(const char *str)
The LogString equivalent to the characters in the null terminated bytes at str.
@ LOSSCHAR
Definition log4cxx/helpers/transcoder.h:179
static void encodeUTF16BE(unsigned int sv, ByteBuffer &dst)
Append the code point sv to dst as UTF-16BE.
static void decode(const std::wstring &src, LogString &dst)
Append the LogString equivalent of src onto dst.
static wchar_t * wencode(const LogString &src, log4cxx::helpers::Pool &p)
A null-terminated equivalent of src.
static void encode(const LogString &src, std::wstring &dst)
Append the equivalent of src onto dst.
static void encode(const LogString &src, std::string &dst)
Append the UTF8 equivalent of src onto dst.
static void encodeUTF8(const LogString &src, std::string &dst)
Append \src onto dst as a UTF-8 string.
static char * encode(const LogString &src, log4cxx::helpers::Pool &p)
static unsigned int decode(const std::wstring &str, std::wstring::const_iterator &iter)
Increment iter past the next code point in str.
static std::string encodeCharsetName(const LogString &charsetName)
Encodes a charset name in the default encoding without using a CharsetEncoder (which could trigger re...
static unsigned int decode(const std::string &str, std::string::const_iterator &iter)
Increment iter past the next code point in str.
static char * encodeUTF8(const LogString &src, log4cxx::helpers::Pool &p)
Converts the LogString to a UTF-8 string.
static CFStringRef encode(const LogString &src)
A CFStringRef equivalent of src.
static void decodeUTF8(const std::string &src, LogString &dst)
Append the UTF-8 characters in src onto dst.
static void encode(unsigned int ch, std::basic_string< UniChar > &dst)
Append the UniChar equivalent to ch onto dst.
static void encode(unsigned int ch, std::wstring &dst)
Append the wchar_t equivalent to ch onto dst.
static void encode(unsigned int ch, std::string &dst)
Append the UTF8 equivalent to ch onto dst.
static unsigned int decode(const std::basic_string< UniChar > &str, std::basic_string< UniChar >::const_iterator &iter)
Increment iter past the next code point in str.
static void decode(const CFStringRef &src, LogString &dst)
Append the LogString equivalent of src onto dst.
static void decode(const std::string &src, LogString &dst)
Append the LogString equivalent of src onto dst.
static void encodeUTF8(unsigned int sv, ByteBuffer &dst)
Append the code point sv to dst as UTF-8.
static logchar decode(char ch)
The logchar equivalent to ch.
const struct __CFString * CFStringRef
Definition logstring.h:30
std::basic_string< logchar > LogString
Definition logstring.h:60