Apache Log4cxx  Version 2.0.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:
39 static void decodeUTF8(const std::string& src, LogString& dst);
43 static void encodeUTF8(const LogString& src, std::string& dst);
48 static void encodeUTF8(unsigned int sv, ByteBuffer& dst);
53 static void encodeUTF16LE(unsigned int sv, ByteBuffer& dst);
58 static void encodeUTF16BE(unsigned int sv, ByteBuffer& dst);
59
60
69 static unsigned int decode(const std::string& str,
70 std::string::const_iterator& iter);
71
81 static unsigned int getCodePoint(const std::string& str, std::string::const_iterator& pCodePoint);
82
86 static void encode(unsigned int ch, std::string& dst);
87
89 static bool hasReplacementCharacter(const std::string& str);
90
94 static void decode(const std::string& src, LogString& dst);
95
101 static void encode(const LogString& src, std::string& dst);
102
103
104
105#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR || defined(WIN32) || defined(_WIN32)
109 static void decode(const std::wstring& src, LogString& dst);
113 static void encode(const LogString& src, std::wstring& dst);
122 static unsigned int decode(const std::wstring& str,
123 std::wstring::const_iterator& iter);
124
134 static unsigned int getCodePoint(const std::wstring& str, std::wstring::const_iterator& pCodePoint);
135
139 static void encode(unsigned int ch, std::wstring& dst);
140
142 static bool hasReplacementCharacter(const std::wstring& str);
143#endif
144
145#if LOG4CXX_CFSTRING_API
149 static void decode(const CFStringRef& src, LogString& dst);
151 static CFStringRef encode(const LogString& src);
152#endif
153
154 enum { LOSSCHAR = 0xFFFD }; // Unicode replacement character
158 static logchar decode(char ch);
162 static LogString decode(const char* str);
163
168 static std::string encodeCharsetName(const LogString& charsetName);
169
170 private:
171 Transcoder();
172 Transcoder(const Transcoder&);
173 Transcoder& operator=(const Transcoder&);
174};
175}
176}
177
178#if LOG4CXX_CHARSET_UTF8 && LOG4CXX_LOGCHAR_IS_UTF8
188#define LOG4CXX_ENCODE_CHAR(var, src) \
189 const std::string& var = src
190
200#define LOG4CXX_DECODE_CHAR(var, src) \
201 const LOG4CXX_NS::LogString& var = src
202
203#else
213#define LOG4CXX_ENCODE_CHAR(var, src) \
214 std::string var; \
215 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
216
226#define LOG4CXX_DECODE_CHAR(var, src) \
227 LOG4CXX_NS::LogString var; \
228 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
229#endif
230
240#define LOG4CXX_DECODE_CFSTRING(var, src) \
241 LOG4CXX_NS::LogString var; \
242 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
243
253#define LOG4CXX_ENCODE_CFSTRING(var, src) \
254 CFStringRef var = LOG4CXX_NS::helpers::Transcoder::encode(src)
255
256#if LOG4CXX_LOGCHAR_IS_WCHAR
266#define LOG4CXX_ENCODE_WCHAR(var, src) \
267 const std::wstring& var = src
268
278#define LOG4CXX_DECODE_WCHAR(var, src) \
279 const LOG4CXX_NS::LogString& var = src
280
281#else
291#define LOG4CXX_ENCODE_WCHAR(var, src) \
292 std::wstring var; \
293 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
294
304#define LOG4CXX_DECODE_WCHAR(var, src) \
305 LOG4CXX_NS::LogString var; \
306 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
307
308#endif
309
310#endif //_LOG4CXX_HELPERS_TRANSCODER_H
An area of memory and a cursor into that memory.
Definition bytebuffer.h:42
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:154
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 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 bool hasReplacementCharacter(const std::wstring &str)
Does str contain the Unicode replacement character.
static void encodeUTF8(const LogString &src, std::string &dst)
Append \src onto dst as a UTF-8 string.
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 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 bool hasReplacementCharacter(const std::string &str)
Does str contain the Unicode replacement character.
static void encode(unsigned int ch, std::wstring &dst)
Append the wchar_t equivalent to ch onto dst.
static unsigned int getCodePoint(const std::string &str, std::string::const_iterator &pCodePoint)
Increment pCodePoint past one str code point.
static void encode(unsigned int ch, std::string &dst)
Append the UTF8 equivalent to ch onto dst.
static unsigned int getCodePoint(const std::wstring &str, std::wstring::const_iterator &pCodePoint)
Increment pCodePoint past one str code point.
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:51