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;
32class LOG4CXX_EXPORT Transcoder
33{
34 public:
38 static void decodeUTF8(const std::string& src, LogString& dst);
42 static void encodeUTF8(const LogString& src, std::string& dst);
47 static void encodeUTF8(unsigned int sv, ByteBuffer& dst);
52 static void encodeUTF16LE(unsigned int sv, ByteBuffer& dst);
57 static void encodeUTF16BE(unsigned int sv, ByteBuffer& dst);
58
59
68 static unsigned int decode(const std::string& str,
69 std::string::const_iterator& iter);
70
80 static unsigned int getCodePoint(const std::string& str, std::string::const_iterator& pCodePoint);
81
85 static void encode(unsigned int ch, std::string& dst);
86
88 static bool hasReplacementCharacter(const std::string& str);
89
93 static void decode(const std::string& src, LogString& dst);
94
100 static void encode(const LogString& src, std::string& dst);
101
102
103
104#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR || defined(WIN32) || defined(_WIN32)
108 static void decode(const std::wstring& src, LogString& dst);
112 static void encode(const LogString& src, std::wstring& dst);
121 static unsigned int decode(const std::wstring& str,
122 std::wstring::const_iterator& iter);
123
133 static unsigned int getCodePoint(const std::wstring& str, std::wstring::const_iterator& pCodePoint);
134
138 static void encode(unsigned int ch, std::wstring& dst);
139
141 static bool hasReplacementCharacter(const std::wstring& str);
142#endif
143
144#if LOG4CXX_CFSTRING_API
148 static void decode(const CFStringRef& src, LogString& dst);
150 static CFStringRef encode(const LogString& src);
151#endif
152
153 enum { LOSSCHAR = 0xFFFD }; // Unicode replacement character
157 static logchar decode(char ch);
161 static LogString decode(const char* str);
162
167 static std::string encodeCharsetName(const LogString& charsetName);
168
169 private:
170 Transcoder();
171 Transcoder(const Transcoder&);
172 Transcoder& operator=(const Transcoder&);
173};
174}
175}
176
177#if LOG4CXX_CHARSET_UTF8 && LOG4CXX_LOGCHAR_IS_UTF8
187#define LOG4CXX_ENCODE_CHAR(var, src) \
188 const std::string& var = src
189
199#define LOG4CXX_DECODE_CHAR(var, src) \
200 const LOG4CXX_NS::LogString& var = src
201
202#else
212#define LOG4CXX_ENCODE_CHAR(var, src) \
213 std::string var; \
214 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
215
225#define LOG4CXX_DECODE_CHAR(var, src) \
226 LOG4CXX_NS::LogString var; \
227 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
228#endif
229
239#define LOG4CXX_DECODE_CFSTRING(var, src) \
240 LOG4CXX_NS::LogString var; \
241 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
242
252#define LOG4CXX_ENCODE_CFSTRING(var, src) \
253 CFStringRef var = LOG4CXX_NS::helpers::Transcoder::encode(src)
254
255#if LOG4CXX_LOGCHAR_IS_WCHAR
265#define LOG4CXX_ENCODE_WCHAR(var, src) \
266 const std::wstring& var = src
267
277#define LOG4CXX_DECODE_WCHAR(var, src) \
278 const LOG4CXX_NS::LogString& var = src
279
280#else
290#define LOG4CXX_ENCODE_WCHAR(var, src) \
291 std::wstring var; \
292 LOG4CXX_NS::helpers::Transcoder::encode(src, var)
293
303#define LOG4CXX_DECODE_WCHAR(var, src) \
304 LOG4CXX_NS::LogString var; \
305 LOG4CXX_NS::helpers::Transcoder::decode(src, var)
306
307#endif
308
309#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:153
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