You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/12/21 03:52:42 UTC
svn commit: r606089 [3/6] - in /logging/log4cxx/trunk: ./ src/examples/cpp/
src/main/cpp/ src/main/include/log4cxx/ src/main/include/log4cxx/db/
src/main/include/log4cxx/filter/ src/main/include/log4cxx/helpers/
src/main/include/log4cxx/net/ src/main/i...
Modified: logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp Thu Dec 20 18:52:29 2007
@@ -1,208 +1,219 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <log4cxx/helpers/messagebuffer.h>
-#include <log4cxx/helpers/transcoder.h>
-
-using namespace log4cxx::helpers;
-
-CharMessageBuffer::CharMessageBuffer() : stream(0) {}
-
-CharMessageBuffer::~CharMessageBuffer() {
- delete stream;
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const std::basic_string<char>& msg) {
- if (stream == 0) {
- buf.append(msg);
- } else {
- *stream << msg;
- }
- return *this;
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const char* msg) {
- const char* actualMsg = msg;
- if (actualMsg == 0) {
- actualMsg = "null";
- }
- if (stream == 0) {
- buf.append(actualMsg);
- } else {
- *stream << actualMsg;
- }
- return *this;
-}
-CharMessageBuffer& CharMessageBuffer::operator<<(char* msg) {
- return operator<<((const char*) msg);
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const char msg) {
- if (stream == 0) {
- buf.append(1, msg);
- } else {
- buf.assign(1, msg);
- *stream << buf;
- }
- return *this;
-}
-
-CharMessageBuffer::operator std::basic_ostream<char>&() {
- if (stream == 0) {
- stream = new std::basic_ostringstream<char>();
- if (!buf.empty()) {
- *stream << buf;
- }
- }
- return *stream;
-}
-
-const std::basic_string<char>& CharMessageBuffer::str(std::basic_ostream<char>&) {
- buf = stream->str();
- return buf;
-}
-
-const std::basic_string<char>& CharMessageBuffer::str(CharMessageBuffer&) {
- return buf;
-}
-
-bool CharMessageBuffer::hasStream() const {
- return (stream != 0);
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <log4cxx/helpers/messagebuffer.h>
+#include <log4cxx/helpers/transcoder.h>
+
+using namespace log4cxx::helpers;
+
+CharMessageBuffer::CharMessageBuffer() : stream(0) {}
+
+CharMessageBuffer::~CharMessageBuffer() {
+ delete stream;
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const std::basic_string<char>& msg) {
+ if (stream == 0) {
+ buf.append(msg);
+ } else {
+ *stream << msg;
+ }
+ return *this;
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const char* msg) {
+ const char* actualMsg = msg;
+ if (actualMsg == 0) {
+ actualMsg = "null";
+ }
+ if (stream == 0) {
+ buf.append(actualMsg);
+ } else {
+ *stream << actualMsg;
+ }
+ return *this;
+}
+CharMessageBuffer& CharMessageBuffer::operator<<(char* msg) {
+ return operator<<((const char*) msg);
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const char msg) {
+ if (stream == 0) {
+ buf.append(1, msg);
+ } else {
+ buf.assign(1, msg);
+ *stream << buf;
+ }
+ return *this;
+}
+
+CharMessageBuffer::operator std::basic_ostream<char>&() {
+ if (stream == 0) {
+ stream = new std::basic_ostringstream<char>();
+ if (!buf.empty()) {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<char>& CharMessageBuffer::str(std::basic_ostream<char>&) {
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<char>& CharMessageBuffer::str(CharMessageBuffer&) {
+ return buf;
+}
+
+bool CharMessageBuffer::hasStream() const {
+ return (stream != 0);
+}
+
std::ostream& CharMessageBuffer::operator<<(ios_base_manip manip) {
std::ostream& s = *this;
(*manip)(s);
return s;
}
-
-std::ostream& CharMessageBuffer::operator<<(bool val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(short val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(int val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(unsigned int val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(long val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(unsigned long val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(float val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(double val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(long double val) { return ((std::ostream&) *this).operator<<(val); }
-std::ostream& CharMessageBuffer::operator<<(void* val) { return ((std::ostream&) *this).operator<<(val); }
-
-
-#if LOG4CXX_HAS_WCHAR_T
-WideMessageBuffer::WideMessageBuffer() : stream(0) {}
-
-WideMessageBuffer::~WideMessageBuffer() {
- delete stream;
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const std::basic_string<wchar_t>& msg) {
- if (stream == 0) {
- buf.append(msg);
- } else {
- *stream << msg;
- }
- return *this;
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t* msg) {
- const wchar_t* actualMsg = msg;
- if (actualMsg == 0) {
- actualMsg = L"null";
- }
- if (stream == 0) {
- buf.append(actualMsg);
- } else {
- *stream << actualMsg;
- }
- return *this;
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(wchar_t* msg) {
- return operator<<((const wchar_t*) msg);
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t msg) {
- if (stream == 0) {
- buf.append(1, msg);
- } else {
- buf.assign(1, msg);
- *stream << buf;
- }
- return *this;
-}
-
-WideMessageBuffer::operator std::basic_ostream<wchar_t>&() {
- if (stream == 0) {
- stream = new std::basic_ostringstream<wchar_t>();
- if (!buf.empty()) {
- *stream << buf;
- }
- }
- return *stream;
-}
-
-const std::basic_string<wchar_t>& WideMessageBuffer::str(std::basic_ostream<wchar_t>&) {
- buf = stream->str();
- return buf;
-}
-
-const std::basic_string<wchar_t>& WideMessageBuffer::str(WideMessageBuffer&) {
- return buf;
-}
-
-bool WideMessageBuffer::hasStream() const {
- return (stream != 0);
-}
-
+
+std::ostream& CharMessageBuffer::operator<<(bool val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(short val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(int val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(unsigned int val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(long val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(unsigned long val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(float val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(double val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(long double val) { return ((std::ostream&) *this).operator<<(val); }
+std::ostream& CharMessageBuffer::operator<<(void* val) { return ((std::ostream&) *this).operator<<(val); }
+
+
+#if LOG4CXX_WCHAR_T_API
+WideMessageBuffer::WideMessageBuffer() : stream(0) {}
+
+WideMessageBuffer::~WideMessageBuffer() {
+ delete stream;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const std::basic_string<wchar_t>& msg) {
+ if (stream == 0) {
+ buf.append(msg);
+ } else {
+ *stream << msg;
+ }
+ return *this;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t* msg) {
+ const wchar_t* actualMsg = msg;
+ if (actualMsg == 0) {
+ actualMsg = L"null";
+ }
+ if (stream == 0) {
+ buf.append(actualMsg);
+ } else {
+ *stream << actualMsg;
+ }
+ return *this;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(wchar_t* msg) {
+ return operator<<((const wchar_t*) msg);
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t msg) {
+ if (stream == 0) {
+ buf.append(1, msg);
+ } else {
+ buf.assign(1, msg);
+ *stream << buf;
+ }
+ return *this;
+}
+
+WideMessageBuffer::operator std::basic_ostream<wchar_t>&() {
+ if (stream == 0) {
+ stream = new std::basic_ostringstream<wchar_t>();
+ if (!buf.empty()) {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<wchar_t>& WideMessageBuffer::str(std::basic_ostream<wchar_t>&) {
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<wchar_t>& WideMessageBuffer::str(WideMessageBuffer&) {
+ return buf;
+}
+
+bool WideMessageBuffer::hasStream() const {
+ return (stream != 0);
+}
+
std::wostream& WideMessageBuffer::operator<<(ios_base_manip manip) {
std::wostream& s = *this;
(*manip)(s);
return s;
}
-
-std::wostream& WideMessageBuffer::operator<<(bool val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(short val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(int val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(unsigned int val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(long val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(unsigned long val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(float val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(double val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(long double val) { return ((std::wostream&) *this).operator<<(val); }
-std::wostream& WideMessageBuffer::operator<<(void* val) { return ((std::wostream&) *this).operator<<(val); }
-
-
-MessageBuffer::MessageBuffer() : wbuf(0){
-}
-
-MessageBuffer::~MessageBuffer() {
- delete wbuf;
-}
-
-bool MessageBuffer::hasStream() const {
- return cbuf.hasStream() || (wbuf != 0 && wbuf->hasStream());
-}
-
+
+std::wostream& WideMessageBuffer::operator<<(bool val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(short val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(int val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(unsigned int val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(long val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(unsigned long val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(float val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(double val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(long double val) { return ((std::wostream&) *this).operator<<(val); }
+std::wostream& WideMessageBuffer::operator<<(void* val) { return ((std::wostream&) *this).operator<<(val); }
+
+
+MessageBuffer::MessageBuffer() : wbuf(0)
+#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+ , ubuf(0)
+#endif
+{
+}
+
+MessageBuffer::~MessageBuffer() {
+ delete wbuf;
+#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+ delete ubuf;
+#endif
+}
+
+bool MessageBuffer::hasStream() const {
+ bool retval = cbuf.hasStream() || (wbuf != 0 && wbuf->hasStream());
+#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+ retval = retval || (ubuf != 0 && ubuf->hasStream());
+#endif
+ return retval;
+}
+
std::ostream& MessageBuffer::operator<<(ios_base_manip manip) {
std::ostream& s = *this;
(*manip)(s);
return s;
}
-
+
MessageBuffer::operator std::ostream&() {
return (std::ostream&) cbuf;
}
@@ -214,9 +225,9 @@
CharMessageBuffer& MessageBuffer::operator<<(const char* msg) {
return cbuf.operator<<(msg);
}
-CharMessageBuffer& MessageBuffer::operator<<(char* msg) {
- return cbuf.operator<<((const char*) msg);
-}
+CharMessageBuffer& MessageBuffer::operator<<(char* msg) {
+ return cbuf.operator<<((const char*) msg);
+}
CharMessageBuffer& MessageBuffer::operator<<(const char msg) {
return cbuf.operator<<(msg);
@@ -238,17 +249,17 @@
WideMessageBuffer& MessageBuffer::operator<<(const wchar_t* msg) {
wbuf = new WideMessageBuffer();
return (*wbuf) << msg;
-}
-WideMessageBuffer& MessageBuffer::operator<<(wchar_t* msg) {
- wbuf = new WideMessageBuffer();
- return (*wbuf) << (const wchar_t*) msg;
-}
+}
+WideMessageBuffer& MessageBuffer::operator<<(wchar_t* msg) {
+ wbuf = new WideMessageBuffer();
+ return (*wbuf) << (const wchar_t*) msg;
+}
WideMessageBuffer& MessageBuffer::operator<<(const wchar_t msg) {
wbuf = new WideMessageBuffer();
return (*wbuf) << msg;
}
-
+
const std::wstring& MessageBuffer::str(WideMessageBuffer& buf) {
return wbuf->str(buf);
}
@@ -256,17 +267,164 @@
const std::wstring& MessageBuffer::str(std::wostream& os) {
return wbuf->str(os);
}
-
-std::ostream& MessageBuffer::operator<<(bool val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(short val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(int val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(unsigned int val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(long val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(unsigned long val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(float val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(double val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(long double val) { return cbuf.operator<<(val); }
-std::ostream& MessageBuffer::operator<<(void* val) { return cbuf.operator<<(val); }
-
-
-#endif
+
+std::ostream& MessageBuffer::operator<<(bool val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(short val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(int val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(unsigned int val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(long val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(unsigned long val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(float val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(double val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(long double val) { return cbuf.operator<<(val); }
+std::ostream& MessageBuffer::operator<<(void* val) { return cbuf.operator<<(val); }
+
+
+#endif
+
+
+#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
+UniCharMessageBuffer& MessageBuffer::operator<<(const std::basic_string<log4cxx::UniChar>& msg) {
+ ubuf = new UniCharMessageBuffer();
+ return (*ubuf) << msg;
+}
+
+UniCharMessageBuffer& MessageBuffer::operator<<(const log4cxx::UniChar* msg) {
+ ubuf = new UniCharMessageBuffer();
+ return (*ubuf) << msg;
+}
+UniCharMessageBuffer& MessageBuffer::operator<<(log4cxx::UniChar* msg) {
+ ubuf = new UniCharMessageBuffer();
+ return (*ubuf) << (const log4cxx::UniChar*) msg;
+}
+
+UniCharMessageBuffer& MessageBuffer::operator<<(const log4cxx::UniChar msg) {
+ ubuf = new UniCharMessageBuffer();
+ return (*ubuf) << msg;
+}
+
+const std::basic_string<log4cxx::UniChar>& MessageBuffer::str(UniCharMessageBuffer& buf) {
+ return ubuf->str(buf);
+}
+
+const std::basic_string<log4cxx::UniChar>& MessageBuffer::str(std::basic_ostream<log4cxx::UniChar>& os) {
+ return ubuf->str(os);
+}
+
+
+UniCharMessageBuffer::UniCharMessageBuffer() : stream(0) {}
+
+UniCharMessageBuffer::~UniCharMessageBuffer() {
+ delete stream;
+}
+
+
+UniCharMessageBuffer& UniCharMessageBuffer::operator<<(const std::basic_string<log4cxx::UniChar>& msg) {
+ if (stream == 0) {
+ buf.append(msg);
+ } else {
+ *stream << buf;
+ }
+ return *this;
+}
+
+UniCharMessageBuffer& UniCharMessageBuffer::operator<<(const log4cxx::UniChar* msg) {
+ const log4cxx::UniChar* actualMsg = msg;
+ static log4cxx::UniChar nullLiteral[] = { 0x6E, 0x75, 0x6C, 0x6C, 0};
+ if (actualMsg == 0) {
+ actualMsg = nullLiteral;
+ }
+ if (stream == 0) {
+ buf.append(actualMsg);
+ } else {
+ *stream << actualMsg;
+ }
+ return *this;
+}
+
+UniCharMessageBuffer& UniCharMessageBuffer::operator<<(log4cxx::UniChar* msg) {
+ return operator<<((const log4cxx::UniChar*) msg);
+}
+
+UniCharMessageBuffer& UniCharMessageBuffer::operator<<(const log4cxx::UniChar msg) {
+ if (stream == 0) {
+ buf.append(1, msg);
+ } else {
+ *stream << msg;
+ }
+ return *this;
+}
+
+UniCharMessageBuffer::operator UniCharMessageBuffer::uostream&() {
+ if (stream == 0) {
+ stream = new std::basic_ostringstream<UniChar>();
+ if (!buf.empty()) {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<log4cxx::UniChar>& UniCharMessageBuffer::str(UniCharMessageBuffer::uostream&) {
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<log4cxx::UniChar>& UniCharMessageBuffer::str(UniCharMessageBuffer&) {
+ return buf;
+}
+
+bool UniCharMessageBuffer::hasStream() const {
+ return (stream != 0);
+}
+
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(ios_base_manip manip) {
+ UniCharMessageBuffer::uostream& s = *this;
+ (*manip)(s);
+ return s;
+}
+
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(bool val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(short val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(int val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(unsigned int val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(long val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(unsigned long val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(float val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(double val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(long double val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+UniCharMessageBuffer::uostream& UniCharMessageBuffer::operator<<(void* val) { return ((UniCharMessageBuffer::uostream&) *this).operator<<(val); }
+
+
+
+#endif
+
+#if LOG4CXX_CFSTRING_API
+#include <CoreFoundation/CFString.h>
+#include <vector>
+
+UniCharMessageBuffer& UniCharMessageBuffer::operator<<(const CFStringRef& msg) {
+ const log4cxx::UniChar* chars = CFStringGetCharactersPtr(msg);
+ if (chars != 0) {
+ return operator<<(chars);
+ } else {
+ size_t length = CFStringGetLength(msg);
+ std::vector<log4cxx::UniChar> tmp(length);
+ CFStringGetCharacters(msg, CFRangeMake(0, length), &tmp[0]);
+ if (stream) {
+ std::basic_string<UniChar> s(&tmp[0], tmp.size());
+ *stream << s;
+ } else {
+ buf.append(&tmp[0], tmp.size());
+ }
+ }
+ return *this;
+}
+
+
+UniCharMessageBuffer& MessageBuffer::operator<<(const CFStringRef& msg) {
+ ubuf = new UniCharMessageBuffer();
+ return (*ubuf) << msg;
+}
+#endif
+
Modified: logging/log4cxx/trunk/src/main/cpp/nameabbreviator.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/nameabbreviator.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/nameabbreviator.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/nameabbreviator.cpp Thu Dec 20 18:52:29 2007
@@ -93,7 +93,7 @@
LogString::size_type end = buf.length() - 1;
for (LogString::size_type i = count; i > 0; i--) {
- end = buf.rfind(LOG4CXX_STR('.'), end - 1);
+ end = buf.rfind(0x2E /* '.' */, end - 1);
if ((end == LogString::npos) || (end < nameStart)) {
return;
@@ -151,14 +151,14 @@
* @return starting index of next element.
*/
LogString::size_type abbreviate(LogString& buf, LogString::size_type startPos) const {
- LogString::size_type nextDot = buf.find(LOG4CXX_STR('.'), startPos);
+ LogString::size_type nextDot = buf.find(0x2E /* '.' */, startPos);
if (nextDot != LogString::npos) {
if ((nextDot - startPos) > charCount) {
buf.erase(buf.begin() + (startPos + charCount), buf.begin() + nextDot);
nextDot = startPos + charCount;
- if (ellipsis != LOG4CXX_STR('\0')) {
+ if (ellipsis != 0x00) {
buf.insert(nextDot, 1, ellipsis);
nextDot++;
}
@@ -196,7 +196,7 @@
PatternAbbreviator(const std::vector<PatternAbbreviatorFragment>& fragments1) :
fragments(fragments1) {
if (fragments1.size() == 0) {
- throw IllegalArgumentException("fragments parameter must contain at least one element");
+ throw IllegalArgumentException(LOG4CXX_STR("fragments parameter must contain at least one element"));
}
}
@@ -249,8 +249,8 @@
LogString::size_type i = 0;
while (
- (i < trimmed.length()) && (trimmed[i] >= LOG4CXX_STR('0'))
- && (trimmed[i] <= LOG4CXX_STR('9'))) {
+ (i < trimmed.length()) && (trimmed[i] >= 0x30 /* '0' */)
+ && (trimmed[i] <= 0x39 /* '9' */)) {
i++;
}
@@ -269,13 +269,13 @@
while (pos < trimmed.length()) {
LogString::size_type ellipsisPos = pos;
- if (trimmed[pos] == LOG4CXX_STR('*')) {
+ if (trimmed[pos] == 0x2A /* '*' */) {
charCount = INT_MAX;
ellipsisPos++;
} else {
- if ((trimmed[pos] >= LOG4CXX_STR('0'))
- && (trimmed[pos] <= LOG4CXX_STR('9'))) {
- charCount = trimmed[pos] - LOG4CXX_STR('0');
+ if ((trimmed[pos] >= 0x30 /* '0' */)
+ && (trimmed[pos] <= 0x39 /* '9' */)) {
+ charCount = trimmed[pos] - 0x30 /* '0' */;
ellipsisPos++;
} else {
charCount = 0;
@@ -287,13 +287,13 @@
if (ellipsisPos < trimmed.length()) {
ellipsis = trimmed[ellipsisPos];
- if (ellipsis == LOG4CXX_STR('.')) {
+ if (ellipsis == 0x2E /* '.' */) {
ellipsis = 0;
}
}
fragments.push_back(PatternAbbreviatorFragment(charCount, ellipsis));
- pos = trimmed.find(LOG4CXX_STR('.'), pos);
+ pos = trimmed.find(0x2E /* '.' */, pos);
if (pos == LogString::npos) {
break;
Modified: logging/log4cxx/trunk/src/main/cpp/ndc.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/ndc.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/ndc.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/ndc.cpp Thu Dec 20 18:52:29 2007
@@ -48,12 +48,6 @@
return *this;
}
-#if LOG4CXX_HAS_WCHAR_T
-NDC::NDC(const std::wstring& message)
-{
- push(message);
-}
-#endif
NDC::NDC(const std::string& message)
{
@@ -99,7 +93,19 @@
stack.pop();
return value;
}
- return LOG4CXX_STR("");
+ return LogString();
+}
+
+bool NDC::pop(std::string& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ stack.pop();
+ return true;
+ }
+ return false;
}
LogString NDC::peek()
@@ -109,10 +115,21 @@
{
return stack.top().message;
}
- return LOG4CXX_STR("");
+ return LogString();
}
-void NDC::pushLogString(const LogString& message)
+bool NDC::peek(std::string& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ return true;
+ }
+ return false;
+}
+
+void NDC::pushLS(const LogString& message)
{
Stack& stack = ThreadSpecificData::getCurrentThreadStack();
@@ -130,24 +147,129 @@
void NDC::push(const std::string& message)
{
LOG4CXX_DECODE_CHAR(msg, message);
- pushLogString(msg);
+ pushLS(msg);
+}
+
+void NDC::remove()
+{
+ clear();
+}
+
+bool NDC::empty() {
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ return stack.empty();
+}
+
+#if LOG4CXX_WCHAR_T_API
+NDC::NDC(const std::wstring& message)
+{
+ push(message);
}
-#if LOG4CXX_HAS_WCHAR_T
void NDC::push(const std::wstring& message)
{
LOG4CXX_DECODE_WCHAR(msg, message);
- pushLogString(msg);
+ pushLS(msg);
}
+
+bool NDC::pop(std::wstring& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ stack.pop();
+ return true;
+ }
+ return false;
+}
+
+bool NDC::peek(std::wstring& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ return true;
+ }
+ return false;
+}
+
#endif
-void NDC::remove()
+
+#if LOG4CXX_UNICHAR_API
+NDC::NDC(const std::basic_string<UniChar>& message)
{
- clear();
+ push(message);
}
-bool NDC::empty() {
- Stack& stack = ThreadSpecificData::getCurrentThreadStack();
- return stack.empty();
+void NDC::push(const std::basic_string<UniChar>& message)
+{
+ LOG4CXX_DECODE_UNICHAR(msg, message);
+ pushLS(msg);
+}
+
+bool NDC::pop(std::basic_string<UniChar>& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ stack.pop();
+ return true;
+ }
+ return false;
+}
+
+bool NDC::peek(std::basic_string<UniChar>& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ Transcoder::encode(stack.top().message, dst);
+ return true;
+ }
+ return false;
+}
+
+#endif
+
+
+#if LOG4CXX_CFSTRING_API
+NDC::NDC(const CFStringRef& message)
+{
+ push(message);
+}
+
+void NDC::push(const CFStringRef& message)
+{
+ LOG4CXX_DECODE_CFSTRING(msg, message);
+ pushLS(msg);
}
+
+bool NDC::pop(CFStringRef& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ dst = Transcoder::encode(stack.top().message);
+ stack.pop();
+ return true;
+ }
+ return false;
+}
+
+bool NDC::peek(CFStringRef& dst)
+{
+ Stack& stack = ThreadSpecificData::getCurrentThreadStack();
+ if(!stack.empty())
+ {
+ dst = Transcoder::encode(stack.top().message);
+ return true;
+ }
+ return false;
+}
+
+#endif
Modified: logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp Thu Dec 20 18:52:29 2007
@@ -164,7 +164,7 @@
addRegistryInfo();
-#if LOG4CXX_HAS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API
LOG4CXX_ENCODE_WCHAR(wsource, source);
LOG4CXX_ENCODE_WCHAR(wserver, server);
hEventLog = ::RegisterEventSourceW(
@@ -197,7 +197,7 @@
LogString oss;
layout->format(oss, event, p);
-#if LOG4CXX_HAS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API
LOG4CXX_ENCODE_WCHAR(s, oss);
const wchar_t* msgs[1];
msgs[0] = s.c_str() ;
@@ -237,7 +237,7 @@
const LogString& subkey, DWORD *disposition)
{
::HKEY hkey = 0;
-#if LOG4CXX_HAS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API
LOG4CXX_ENCODE_WCHAR(wstr, subkey);
RegCreateKeyExW((::HKEY) HKEY_LOCAL_MACHINE, wstr.c_str(), 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL,
@@ -272,7 +272,7 @@
::HKEY hkey = 0;
LogString subkey(LOG4CXX_STR("SYSTEM\\CurrentControlSet\\Services\\EventLog\\"));
subkey.append(log);
- subkey.append(1, LOG4CXX_STR('\\'));
+ subkey.append(1, 0x5C /* '\\' */);
subkey.append(source);
hkey = (::HKEY) regGetKey(subkey, &disposition);
@@ -343,7 +343,7 @@
Pool p;
enum { MSGSIZE = 5000 };
-#if LOG4CXX_HAS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API
wchar_t* lpMsgBuf = (wchar_t*) p.palloc(MSGSIZE * sizeof(wchar_t));
DWORD dw = GetLastError();
Modified: logging/log4cxx/trunk/src/main/cpp/objectptr.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/objectptr.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/objectptr.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/objectptr.cpp Thu Dec 20 18:52:29 2007
@@ -23,7 +23,7 @@
void ObjectPtrBase::checkNull(const int& null) {
if (null != 0) {
- throw IllegalArgumentException("Attempt to set pointer to a non-zero numeric value.");
+ throw IllegalArgumentException(LOG4CXX_STR("Attempt to set pointer to a non-zero numeric value."));
}
}
Modified: logging/log4cxx/trunk/src/main/cpp/obsoleterollingfileappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/obsoleterollingfileappender.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/obsoleterollingfileappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/obsoleterollingfileappender.cpp Thu Dec 20 18:52:29 2007
@@ -34,7 +34,7 @@
{
public:
ClassRollingFileAppender() : helpers::Class() {}
- virtual const log4cxx::logchar* getName() const {
+ virtual LogString getName() const {
return LOG4CXX_STR("org.apache.log4j.RollingFileAppender");
}
virtual ObjectPtr newInstance() const {
Modified: logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/odbcappender.cpp Thu Dec 20 18:52:29 2007
@@ -143,7 +143,7 @@
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
closeConnection(con);
#else
- throw SQLException("log4cxx build without ODBC support");
+ throw SQLException(LOG4CXX_STR("log4cxx build without ODBC support"));
#endif
}
Modified: logging/log4cxx/trunk/src/main/cpp/optionconverter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/optionconverter.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/optionconverter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/optionconverter.cpp Thu Dec 20 18:52:29 2007
@@ -51,42 +51,28 @@
while(i != s.end())
{
c = *i++;
- if (c == LOG4CXX_STR('\\'))
+ if (c == 0x5C /* '\\' */)
{
c = *i++;
switch (c)
{
- case LOG4CXX_STR('n'):
- c = LOG4CXX_STR('\n');
+ case 0x6E: //'n'
+ c = 0x0A;
break;
- case LOG4CXX_STR('r'):
- c = LOG4CXX_STR('\r');
+ case 0x72: //'r'
+ c = 0x0D;
break;
- case LOG4CXX_STR('t'):
- c = LOG4CXX_STR('\t');
+ case 0x74: //'t'
+ c = 0x09;
break;
- case LOG4CXX_STR('f'):
- c = LOG4CXX_STR('\f');
+ case 0x66: //'f'
+ c = 0x0C;
break;
-
- case LOG4CXX_STR('\b'):
- c = LOG4CXX_STR('\b');
- break;
-
- case LOG4CXX_STR('\"'):
- c = LOG4CXX_STR('\"');
- break;
-
- case LOG4CXX_STR('\''):
- c = LOG4CXX_STR('\'');
- break;
-
- case LOG4CXX_STR('\\'):
- c = LOG4CXX_STR('\\');
+ default:
break;
}
}
@@ -138,11 +124,11 @@
if (index != LogString::npos && index > 0) {
long multiplier = 1;
index--;
- if (s[index] == LOG4CXX_STR('k') || s[index] == LOG4CXX_STR('K')) {
+ if (s[index] == 0x6B /* 'k' */ || s[index] == 0x4B /* 'K' */) {
multiplier = 1024;
- } else if(s[index] == LOG4CXX_STR('m') || s[index] == LOG4CXX_STR('M')) {
+ } else if(s[index] == 0x6D /* 'm' */ || s[index] == 0x4D /* 'M' */) {
multiplier = 1024*1024;
- } else if(s[index] == LOG4CXX_STR('g') || s[index] == LOG4CXX_STR('G')) {
+ } else if(s[index] == 0x67 /* 'g'*/ || s[index] == 0x47 /* 'G' */) {
multiplier = 1024*1024*1024;
}
return toInt(s.substr(0, index), 1) * multiplier;
@@ -173,8 +159,9 @@
LogString OptionConverter::substVars(const LogString& val, Properties& props)
{
LogString sbuf;
- static const LogString delimStart(LOG4CXX_STR("${"));
- const logchar delimStop = LOG4CXX_STR('}');
+ const logchar delimStartArray[] = { 0x24, 0x7B, 0 };
+ const LogString delimStart(delimStartArray);
+ const logchar delimStop = 0x7D; // '}';
const size_t DELIM_START_LEN = 2;
const size_t DELIM_STOP_LEN = 1;
@@ -203,12 +190,12 @@
k = val.find(delimStop, j);
if(k == -1)
{
- std::string msg(1, '\"');
- Transcoder::encode(val, msg);
- msg.append("\" has no closing brace. Opening brace at position ");
+ LogString msg(1, 0x22 /* '\"' */);
+ msg.append(val);
+ msg.append(LOG4CXX_STR("\" has no closing brace. Opening brace at position "));
Pool p;
StringHelper::toString(j, p, msg);
- msg.append(1, '.');
+ msg.append(1, 0x2E /* '.' */);
throw IllegalArgumentException(msg);
}
else
@@ -216,7 +203,7 @@
j += DELIM_START_LEN;
LogString key = val.substr(j, k - j);
// first try in System properties
- LogString replacement = getSystemProperty(key, LOG4CXX_STR(""));
+ LogString replacement = getSystemProperty(key, LogString());
// then try props parameter
if(replacement.empty())
{
@@ -253,7 +240,7 @@
return def;
}
-const LevelPtr& OptionConverter::toLevel(const LogString& value,
+LevelPtr OptionConverter::toLevel(const LogString& value,
const LevelPtr& defaultValue)
{
size_t hashIndex = value.find(LOG4CXX_STR("#"));
@@ -349,7 +336,7 @@
}
catch (Exception& e)
{
- LogLog::error(((LogString) LOG4CXX_STR("Could not instantiate class [")) +
+ LogLog::error(LOG4CXX_STR("Could not instantiate class [") +
className + LOG4CXX_STR("]."), e);
}
}
@@ -374,15 +361,13 @@
if(!clazz.empty())
{
- LogLog::debug(
- ((LogString) LOG4CXX_STR("Preferred configurator class: ")) + clazz);
+ LogLog::debug(LOG4CXX_STR("Preferred configurator class: ") + clazz);
configurator = instantiateByClassName(clazz,
Configurator::getStaticClass(),
0);
if(configurator == 0)
{
- LogLog::error(
- ((LogString) LOG4CXX_STR("Could not instantiate configurator ["))
+ LogLog::error(LOG4CXX_STR("Could not instantiate configurator [")
+ clazz + LOG4CXX_STR("]."));
return;
}
Modified: logging/log4cxx/trunk/src/main/cpp/outputdebugstringappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/outputdebugstringappender.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/outputdebugstringappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/outputdebugstringappender.cpp Thu Dec 20 18:52:29 2007
@@ -34,7 +34,7 @@
{
LogString buf;
layout->format(buf, event, p);
-#if LOG4CXX_HAS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API
LOG4CXX_ENCODE_WCHAR(wstr, buf);
::OutputDebugStringW(wstr.c_str());
#else
Modified: logging/log4cxx/trunk/src/main/cpp/outputstreamwriter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/outputstreamwriter.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/outputstreamwriter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/outputstreamwriter.cpp Thu Dec 20 18:52:29 2007
@@ -30,7 +30,7 @@
OutputStreamWriter::OutputStreamWriter(OutputStreamPtr& out1)
: out(out1), enc(CharsetEncoder::getDefaultEncoder()) {
if (out1 == 0) {
- throw NullPointerException("out parameter may not be null.");
+ throw NullPointerException(LOG4CXX_STR("out parameter may not be null."));
}
}
@@ -38,10 +38,10 @@
CharsetEncoderPtr &enc1)
: out(out1), enc(enc1) {
if (out1 == 0) {
- throw NullPointerException("out parameter may not be null.");
+ throw NullPointerException(LOG4CXX_STR("out parameter may not be null."));
}
if (enc1 == 0) {
- throw NullPointerException("enc parameter may not be null.");
+ throw NullPointerException(LOG4CXX_STR("enc parameter may not be null."));
}
}
Modified: logging/log4cxx/trunk/src/main/cpp/patternparser.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/patternparser.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/patternparser.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/patternparser.cpp Thu Dec 20 18:52:29 2007
@@ -24,7 +24,7 @@
using namespace log4cxx::pattern;
using namespace log4cxx::helpers;
-const logchar PatternParser::ESCAPE_CHAR = LOG4CXX_STR('%');
+const logchar PatternParser::ESCAPE_CHAR = 0x25; // '%'
/**
@@ -38,9 +38,9 @@
// greatly simplified version checks if
// character is USACII alpha or number
//
- return (ch >= LOG4CXX_STR('A') && ch <= LOG4CXX_STR('Z')) ||
- (ch >= LOG4CXX_STR('a') && ch <= LOG4CXX_STR('z')) ||
- (ch >= LOG4CXX_STR('0') && ch <= LOG4CXX_STR('9'));
+ return (ch >= 0x41 /* 'A' */ && ch <= 0x5A /* 'Z' */) ||
+ (ch >= 0x61 /* 'a' */ && ch <= 0x7A /* 'z' */) ||
+ (ch >= 0x30 /* '0' */ && ch <= 0x39 /* '9' */);
}
bool PatternParser::isUnicodeIdentifierPart(logchar ch) {
@@ -48,10 +48,8 @@
// greatly simplified version checks if
// character is USACII alpha or number
//
- return (ch >= LOG4CXX_STR('A') && ch <= LOG4CXX_STR('Z')) ||
- (ch >= LOG4CXX_STR('a') && ch <= LOG4CXX_STR('z')) ||
- (ch >= LOG4CXX_STR('0') && ch <= LOG4CXX_STR('9')) ||
- (ch == LOG4CXX_STR('_'));
+ return isUnicodeIdentifierStart(ch)
+ || (ch == 0x5F /* '_' */);
}
int PatternParser::extractConverter(
@@ -89,8 +87,8 @@
int PatternParser::extractOptions(const LogString& pattern, LogString::size_type i,
std::vector<LogString>& options) {
- while ((i < pattern.length()) && (pattern[i] == LOG4CXX_STR('{'))) {
- int end = pattern.find(LOG4CXX_STR('}'), i);
+ while ((i < pattern.length()) && (pattern[i] == 0x7B /* '{' */)) {
+ int end = pattern.find(0x7D /* '}' */, i);
if (end == -1) {
break;
@@ -133,15 +131,10 @@
if (c == ESCAPE_CHAR) {
// peek at the next char.
- switch (pattern[i]) {
- case ESCAPE_CHAR:
+ if(pattern[i] == ESCAPE_CHAR) {
currentLiteral.append(1, c);
i++; // move pointer
-
- break;
-
- default:
-
+ } else {
if (!currentLiteral.empty()) {
patternConverters.push_back(
LiteralPatternConverter::newInstance(currentLiteral));
@@ -163,7 +156,7 @@
currentLiteral.append(1, c);
switch (c) {
- case '-':
+ case 0x2D: // '-'
formattingInfo =
new FormattingInfo(
true, formattingInfo->getMinLength(),
@@ -171,17 +164,17 @@
break;
- case '.':
+ case 0x2E: // '.'
state = DOT_STATE;
break;
default:
- if ((c >= LOG4CXX_STR('0')) && (c <= LOG4CXX_STR('9'))) {
+ if ((c >= 0x30 /* '0' */) && (c <= 0x39 /* '9' */)) {
formattingInfo =
new FormattingInfo(
- formattingInfo->isLeftAligned(), c - LOG4CXX_STR('0'),
+ formattingInfo->isLeftAligned(), c - 0x30 /* '0' */,
formattingInfo->getMaxLength());
state = MIN_STATE;
} else {
@@ -203,13 +196,13 @@
case MIN_STATE:
currentLiteral.append(1, c);
- if ((c >= LOG4CXX_STR('0')) && (c <= LOG4CXX_STR('9'))) {
+ if ((c >= 0x30 /* '0' */) && (c <= 0x39 /* '9' */)) {
formattingInfo =
new FormattingInfo(
formattingInfo->isLeftAligned(),
- (formattingInfo->getMinLength() * 10) + (c - LOG4CXX_STR('0')),
+ (formattingInfo->getMinLength() * 10) + (c - 0x30 /* '0' */),
formattingInfo->getMaxLength());
- } else if (c == LOG4CXX_STR('.')) {
+ } else if (c == 0x2E /* '.' */) {
state = DOT_STATE;
} else {
i = finalizeConverter(
@@ -227,11 +220,11 @@
case DOT_STATE:
currentLiteral.append(1, c);
- if ((c >= LOG4CXX_STR('0')) && (c <= LOG4CXX_STR('9'))) {
+ if ((c >= 0x30 /* '0' */) && (c <= 0x39 /* '9' */)) {
formattingInfo =
new FormattingInfo(
formattingInfo->isLeftAligned(), formattingInfo->getMinLength(),
- c - LOG4CXX_STR('0'));
+ c - 0x30 /* '0' */);
state = MAX_STATE;
} else {
LogLog::error(LOG4CXX_STR("Error in pattern, was expecting digit."));
@@ -244,11 +237,11 @@
case MAX_STATE:
currentLiteral.append(1, c);
- if ((c >= LOG4CXX_STR('0')) && (c <= LOG4CXX_STR('9'))) {
+ if ((c >= 0x30 /* '0' */) && (c <= 0x39 /* '9' */)) {
formattingInfo =
new FormattingInfo(
formattingInfo->isLeftAligned(), formattingInfo->getMinLength(),
- (formattingInfo->getMaxLength() * 10) + (c - LOG4CXX_STR('0')));
+ (formattingInfo->getMaxLength() * 10) + (c - 0x30 /* '0' */));
} else {
i = finalizeConverter(
c, pattern, i, currentLiteral, formattingInfo,
Modified: logging/log4cxx/trunk/src/main/cpp/properties.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/properties.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/properties.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/properties.cpp Thu Dec 20 18:52:29 2007
@@ -46,16 +46,16 @@
case BEGIN:
switch(c)
{
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR('\t'):
- case LOG4CXX_STR('\n'):
- case LOG4CXX_STR('\r'):
+ case 0x20: // ' '
+ case 0x08: // '\t'
+ case 0x0A: // '\n'
+ case 0x0D: // '\r'
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('#'):
- case LOG4CXX_STR('!'):
+ case 0x23: // '#'
+ case 0x21: // '!'
lexemType = COMMENT;
if (!get(in, c))
finished = true;
@@ -70,25 +70,25 @@
case KEY:
switch(c)
{
- case LOG4CXX_STR('\\'):
+ case 0x5C: // '\\'
lexemType = KEY_ESCAPE;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\t'):
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR(':'):
- case LOG4CXX_STR('='):
+ case 0x08: // '\t'
+ case 0x20: // ' '
+ case 0x3A: // ':'
+ case 0x3D: // '='
lexemType = DELIMITER;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\n'):
- case LOG4CXX_STR('\r'):
+ case 0x0A:
+ case 0x0D:
// key associated with an empty string element
- properties.setProperty(key, LOG4CXX_STR(""));
+ properties.setProperty(key, LogString());
key.erase(key.begin(), key.end());
lexemType = BEGIN;
if (!get(in, c))
@@ -106,24 +106,24 @@
case KEY_ESCAPE:
switch(c)
{
- case LOG4CXX_STR('\t'):
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR(':'):
- case LOG4CXX_STR('='):
- case LOG4CXX_STR('\\'):
+ case 0x08: // '\t'
+ case 0x20: // ' '
+ case 0x3A: // ':'
+ case 0x3D: // '='
+ case 0x5C: // '\\'
key.append(1, c);
lexemType = KEY;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\n'):
+ case 0x0A: // '\n'
lexemType = KEY_CONTINUE;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\r'):
+ case 0x0D: // '\r'
lexemType = KEY_CONTINUE2;
if (!get(in, c))
finished = true;
@@ -134,8 +134,8 @@
case KEY_CONTINUE:
switch(c)
{
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR('\t'):
+ case 0x20: // ' '
+ case 0x08: // '\t'
if (!get(in, c))
finished = true;
break;
@@ -149,7 +149,7 @@
case KEY_CONTINUE2:
switch(c)
{
- case LOG4CXX_STR('\n'):
+ case 0x0A: // '\n'
if (!get(in, c))
finished = true;
lexemType = KEY_CONTINUE;
@@ -164,10 +164,10 @@
case DELIMITER:
switch(c)
{
- case LOG4CXX_STR('\t'):
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR(':'):
- case LOG4CXX_STR('='):
+ case 0x08: // '\t'
+ case 0x20: // ' '
+ case 0x3A: // ':'
+ case 0x3D: // '='
if (!get(in, c))
finished = true;
break;
@@ -181,14 +181,14 @@
case ELEMENT:
switch(c)
{
- case LOG4CXX_STR('\\'):
+ case 0x5C: // '\\'
lexemType = ELEMENT_ESCAPE;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\n'):
- case LOG4CXX_STR('\r'):
+ case 0x0A: // '\n'
+ case 0x0D: // '\r'
// key associated with an empty string element
properties.setProperty(key, element);
key.erase(key.begin(), key.end());
@@ -209,14 +209,14 @@
case ELEMENT_ESCAPE:
switch(c)
{
- case LOG4CXX_STR('t'):
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR('n'):
- case LOG4CXX_STR('r'):
- case LOG4CXX_STR('\''):
- case LOG4CXX_STR('\\'):
- case LOG4CXX_STR('\"'):
- case LOG4CXX_STR(':'):
+ case 0x08: // '\t'
+ case 0x20: // ' '
+ case 0x6E: // 'n'
+ case 0x72: // 'r'
+ case 0x27: // '\''
+ case 0x5C: // '\\'
+ case 0x22: // '\"'
+ case 0x3A: // ':'
default:
element.append(1, c);
lexemType = ELEMENT;
@@ -224,13 +224,13 @@
finished = true;
break;
- case LOG4CXX_STR('\n'):
+ case 0x0A: // '\n'
lexemType = ELEMENT_CONTINUE;
if (!get(in, c))
finished = true;
break;
- case LOG4CXX_STR('\r'):
+ case 0x0D: // '\r'
lexemType = ELEMENT_CONTINUE2;
if (!get(in, c))
finished = true;
@@ -241,8 +241,8 @@
case ELEMENT_CONTINUE:
switch(c)
{
- case LOG4CXX_STR(' '):
- case LOG4CXX_STR('\t'):
+ case 0x20: // ' '
+ case 0x08: // '\t'
if (!get(in, c))
finished = true;
break;
@@ -256,7 +256,7 @@
case ELEMENT_CONTINUE2:
switch(c)
{
- case LOG4CXX_STR('\n'):
+ case 0x20: // '\n'
if (!get(in, c))
finished = true;
lexemType = ELEMENT_CONTINUE;
@@ -269,7 +269,7 @@
break;
case COMMENT:
- if (c == LOG4CXX_STR('\n') || c == LOG4CXX_STR('\r'))
+ if (c == 0x0A || c == 0x0D)
{
lexemType = BEGIN;
}
@@ -328,7 +328,7 @@
{
LogString oldValue(properties[key]);
properties[key] = value;
- //tcout << LOG4CXX_STR("setting property key=") << key << LOG4CXX_STR(", value=") << value << std::endl;
+ //tcout << ASCII_STR("setting property key=") << key << ASCII_STR(", value=") << value << std::endl;
return oldValue;
}
Modified: logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp Thu Dec 20 18:52:29 2007
@@ -54,21 +54,21 @@
LogString& toAppendTo,
Pool& /* p */) const {
if (option.length() == 0) {
- toAppendTo.append(1, LOG4CXX_STR('{'));
+ toAppendTo.append(1, 0x7B /* '{' */);
std::set<LogString> keySet(event->getMDCKeySet());
for(std::set<LogString>::const_iterator iter = keySet.begin();
iter != keySet.end();
iter++) {
- toAppendTo.append(1, LOG4CXX_STR('{'));
+ toAppendTo.append(1, 0x7B /* '{' */);
toAppendTo.append(*iter);
- toAppendTo.append(1, LOG4CXX_STR(','));
+ toAppendTo.append(1, 0x2C /* ',' */);
event->getMDC(*iter, toAppendTo);
- toAppendTo.append(1, LOG4CXX_STR('}'));
+ toAppendTo.append(1, 0x7D /* '}' */);
}
- toAppendTo.append(1, LOG4CXX_STR('}'));
+ toAppendTo.append(1, 0x7D /* '}' */);
} else {
event->getMDC(option, toAppendTo);
Modified: logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/propertyconfigurator.cpp Thu Dec 20 18:52:29 2007
@@ -353,7 +353,7 @@
continue;
}
- LogLog::debug(((LogString) LOG4CXX_STR("Parsing appender named ") LOG4CXX_EOL)
+ LogLog::debug(LOG4CXX_STR("Parsing appender named ")
+ appenderName + LOG4CXX_STR("\"."));
appender = parseAppender(props, appenderName);
Modified: logging/log4cxx/trunk/src/main/cpp/propertysetter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/propertysetter.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/propertysetter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/propertysetter.cpp Thu Dec 20 18:52:29 2007
@@ -61,7 +61,7 @@
if (key.find(prefix) == 0)
{
// ignore key if it contains dots after the prefix
- if (key.find(LOG4CXX_STR('.'), len + 1) != LogString::npos)
+ if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
{
continue;
}
Modified: logging/log4cxx/trunk/src/main/cpp/relativetimedateformat.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/relativetimedateformat.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/relativetimedateformat.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/relativetimedateformat.cpp Thu Dec 20 18:52:29 2007
@@ -34,5 +34,5 @@
log4cxx_time_t date,
Pool& p) const {
log4cxx_int64_t interval = (date - startTime) / APR_INT64_C(1000);
- s.append(StringHelper::toString(interval, p));
+ StringHelper::toString(interval, p, s);
}
Modified: logging/log4cxx/trunk/src/main/cpp/relativetimepatternconverter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/relativetimepatternconverter.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/relativetimepatternconverter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/relativetimepatternconverter.cpp Thu Dec 20 18:52:29 2007
@@ -45,7 +45,6 @@
LogString& toAppendTo,
Pool& p) const {
log4cxx_time_t delta = (event->getTimeStamp() - LoggingEvent::getStartTime())/1000;
- LogString formatted(StringHelper::toString(delta, p));
- toAppendTo.append(formatted);
+ StringHelper::toString(delta, p, toAppendTo);
}
Modified: logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp Thu Dec 20 18:52:29 2007
@@ -90,7 +90,8 @@
}
}
- File activeFile(getFile());
+ File activeFile;
+ activeFile.setName(getFile());
if (getAppend()) {
fileLength = activeFile.length(p);
@@ -167,7 +168,7 @@
if (success) {
if (rollover1->getAppend()) {
- fileLength = File(rollover1->getActiveFileName()).length(p);
+ fileLength = File().setName(rollover1->getActiveFileName()).length(p);
} else {
fileLength = 0;
}
@@ -209,7 +210,7 @@
if (success) {
if (rollover1->getAppend()) {
- fileLength = File(rollover1->getActiveFileName()).length(p);
+ fileLength = File().setName(rollover1->getActiveFileName()).length(p);
} else {
fileLength = 0;
}
Modified: logging/log4cxx/trunk/src/main/cpp/simpledateformat.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/simpledateformat.cpp?rev=606089&r1=606088&r2=606089&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/simpledateformat.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/simpledateformat.cpp Thu Dec 20 18:52:29 2007
@@ -27,6 +27,7 @@
#define LOG4CXX 1
#endif
#include <log4cxx/private/log4cxx_private.h>
+#include <log4cxx/helpers/pool.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -38,21 +39,6 @@
#endif
-/*
- * implementation works on localechar sequences to avoid too many calls
- * to Transformer::decode() when the date is formatted.
- */
-#if LOG4CXX_HAS_STD_WLOCALE && LOG4CXX_HAS_WCHAR_T
- typedef wchar_t localechar;
- #define LOG4CXX_LOCALE_STR(str) L ## str
-#else
- typedef char localechar;
- #define LOG4CXX_LOCALE_STR(str) str
-#endif
-
-typedef std::basic_string < localechar > LocaleString;
-
-
namespace log4cxx
{
namespace helpers
@@ -60,70 +46,24 @@
namespace SimpleDateFormatImpl
{
-#if LOG4CXX_HAS_STD_LOCALE
- /**
- * Renders a time structure according to a specific format.
- *
- * @param locale The locale to use for the formatting.
- * @param buffer The buffer which retrieves the result.
- * @param time The time structure to render.
- * @param spec The format for rendering the structure.
- */
- void renderFacet( const std::locale & locale, std::basic_ostream < localechar > & buffer,
- const tm * time, const localechar spec )
- {
- #if defined(_USEFAC)
- _USEFAC( locale, std::time_put < localechar > ).put( buffer, buffer, time, spec );
- #else
- std::use_facet < std::time_put < localechar > > ( locale ).put( buffer, buffer, buffer.fill(), time, spec );
- #endif
- }
-#endif
-
- /**
- * Renders an APR time structure according to a specific format.
- *
- * @param result The LogString which retrieves the result.
- * @param tm The APR time structure to render.
- * @param format The format for rendering the structure.
- */
- void renderFacet( LocaleString & res, apr_time_exp_t * tm, const char * format )
- {
- enum
- {
- BUFSIZE = 256
- };
- char buf[BUFSIZE];
- memset(buf, 0, BUFSIZE);
- apr_size_t retsize = 0;
- apr_status_t stat = apr_strftime( buf, & retsize, BUFSIZE, format, tm );
- if ( stat != APR_SUCCESS )
- {
- buf[0] = '?';
- retsize = 1;
- }
- LogString result;
- Transcoder::decode( buf, retsize, result );
- Transcoder::encode( result, res );
- }
-
- }
-
/**
* Abstract inner class representing one format token
* (one or more instances of a character).
*/
class PatternToken {
public:
- PatternToken();
+ PatternToken() {
+ }
- virtual ~PatternToken();
+ virtual ~PatternToken() {
+ }
/**
* Sets the time zone.
* @param zone new time zone.
*/
- virtual void setTimeZone(const TimeZonePtr& zone);
+ virtual void setTimeZone(const TimeZonePtr& zone) {
+ }
/**
* Appends the formatted content to the string.
@@ -131,10 +71,82 @@
* @param date exploded date/time.
* @param p memory pool.
*/
- virtual void format(LocaleString& s,
+ virtual void format(LogString& s,
const apr_time_exp_t& date,
log4cxx::helpers::Pool& p) const = 0;
-
+
+ protected:
+ typedef static void (*incrementFunction)(tm& time, apr_time_exp_t& apr_time);
+
+ static void incrementMonth(tm& time, apr_time_exp_t& aprtime) {
+ time.tm_mon++;
+ aprtime.tm_mon++;
+ }
+
+ static void incrementDay(tm& time, apr_time_exp_t& aprtime) {
+ time.tm_wday++;
+ aprtime.tm_wday++;
+ }
+
+ static void incrementHalfDay(tm& time, apr_time_exp_t& aprtime) {
+ time.tm_hour += 12;
+ aprtime.tm_hour += 12;
+ }
+
+ static void renderFacet(const std::locale* locale,
+ incrementFunction inc,
+ char spec,
+ unsigned int wspec,
+ const char* aprspec,
+ std::vector<LogString>& values) {
+ std::vector<LogString>::iterator valueIter = values.begin();
+ tm time;
+ memset(&time, 0, sizeof(time));
+ apr_time_exp_t aprtime;
+ memset(&aprtime, 0, sizeof(aprtime));
+#if LOG4CXX_HAS_STD_LOCALE
+ if (locale != NULL) {
+#if LOG4CXX_WCHAR_T_API
+ if (std::has_facet< std::time_put<wchar_t> >(*locale)) {
+ const std::time_put<wchar_t>& facet = std::use_facet< std::time_put<wchar_t> >(*locale);
+ size_t start = 0;
+ std::wostringstream os;
+ for(; valueIter != values.end(); valueIter++) {
+ facet.put(os, os, os.fill(), &time, (wchar_t) wspec);
+ Transcoder::decode(os.str().substr(start), *valueIter);
+ start = os.str().length();
+ (*inc)(time, aprtime);
+ }
+ } else
+#endif
+ if (std::has_facet< std::time_put<char> >(*locale)) {
+ const std::time_put<char>& facet = std::use_facet< std::time_put<char> >(*locale);
+ size_t start = 0;
+ std::ostringstream os;
+ for(; valueIter != values.end(); valueIter++) {
+ facet.put(os, os, os.fill(), &time, spec);
+ Transcoder::decode(os.str().substr(start), *valueIter);
+ start = os.str().length();
+ (*inc)(time, aprtime);
+ }
+ }
+ }
+#endif
+ const size_t BUFSIZE = 256;
+ char buf[BUFSIZE];
+ memset(buf, 0, BUFSIZE);
+ apr_size_t retsize = 0;
+ for(; valueIter != values.end(); valueIter++) {
+ apr_status_t stat = apr_strftime(buf, &retsize, BUFSIZE, aprspec, &aprtime);
+ (*inc)(time, aprtime);
+ if (stat == APR_SUCCESS) {
+ Transcoder::decode(std::string(buf, retsize), *valueIter);
+ } else {
+ valueIter->append(1, 0x3F);
+ }
+ }
+ }
+
private:
/**
* Private copy constructor.
@@ -147,39 +159,21 @@
PatternToken& operator=(const PatternToken&);
};
- }
-}
-
-using namespace log4cxx::helpers::SimpleDateFormatImpl;
-using namespace log4cxx::helpers;
-
-PatternToken::PatternToken()
-{
-}
-
-PatternToken::~PatternToken()
-{
-}
-
-void PatternToken::setTimeZone( const TimeZonePtr & /* zone */ )
-{
-}
-
class LiteralToken : public PatternToken
{
public:
- LiteralToken( localechar ch1, int count1 ) : ch( ch1 ), count( count1 )
+ LiteralToken( logchar ch1, int count1 ) : ch( ch1 ), count( count1 )
{
}
- void format( LocaleString& s, const apr_time_exp_t & , Pool & /* p */ ) const
+ void format( LogString& s, const apr_time_exp_t & , Pool & /* p */ ) const
{
s.append( count, ch );
}
private:
- localechar ch;
+ logchar ch;
int count;
};
@@ -192,9 +186,10 @@
{
}
- void format( LocaleString& s, const apr_time_exp_t & /* tm */, Pool & /* p */ ) const
+ void format(LogString& s, const apr_time_exp_t & /* tm */, Pool & /* p */ ) const
{
- s.append( LOG4CXX_LOCALE_STR( "AD" ) );
+ s.append(1, 0x41 /* 'A' */);
+ s.append(1, 0x44 /* 'D' */);
}
};
@@ -209,14 +204,15 @@
virtual int getField( const apr_time_exp_t & tm ) const = 0;
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & p ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & p ) const
{
size_t initialLength = s.length();
+
StringHelper::toString( getField( tm ), p, s );
size_t finalLength = s.length();
if ( initialLength + width > finalLength )
{
- s.insert( initialLength, ( initialLength + width ) - finalLength, LOG4CXX_LOCALE_STR( '0' ) );
+ s.insert( initialLength, ( initialLength + width ) - finalLength, 0x30 /* '0' */);
}
}
@@ -260,51 +256,17 @@
class AbbreviatedMonthNameToken : public PatternToken
{
public:
- AbbreviatedMonthNameToken( int
-#if LOG4CXX_HAS_STD_LOCALE
- width
-#endif
- , const std::locale *
-#if LOG4CXX_HAS_STD_LOCALE
- locale
-#endif
- ) : names( 12 )
- {
-#if LOG4CXX_HAS_STD_LOCALE
- if ( locale != NULL )
- {
- tm time;
- memset( & time, 0, sizeof( time ));
- std::basic_ostringstream < localechar > buffer;
- size_t start = 0;
- for ( int imon = 0; imon < 12; imon++ )
- {
- time.tm_mon = imon;
- renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'b' ) );
- LocaleString monthnames( buffer.str() );
- names[imon] = monthnames.substr( start );
- start = monthnames.length();
- }
- return;
- }
-#endif
- apr_time_exp_t time;
- memset( & time, 0, sizeof( time ));
- for ( int imon = 0; imon < 12; imon++ )
- {
- time.tm_mon = imon;
- renderFacet( names[imon], & time, "%b" );
- }
+ AbbreviatedMonthNameToken(int, const std::locale *locale) : names( 12 ) {
+ renderFacet(locale, PatternToken::incrementMonth, 'b', 0x62, "%b", names);
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
+ void format(LogString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
{
s.append( names[tm.tm_mon] );
}
private:
- std::vector < LocaleString > names;
-
+ std::vector < LogString > names;
};
@@ -312,50 +274,18 @@
class FullMonthNameToken : public PatternToken
{
public:
- FullMonthNameToken( int
-#if LOG4CXX_HAS_STD_LOCALE
- width
-#endif
- , const std::locale *
-#if LOG4CXX_HAS_STD_LOCALE
- locale
-#endif
- ) : names( 12 )
+ FullMonthNameToken( int width, const std::locale *locale) : names( 12 )
{
-#if LOG4CXX_HAS_STD_LOCALE
- if ( locale != NULL )
- {
- tm time;
- memset( & time, 0, sizeof( time ));
- std::basic_ostringstream < localechar > buffer;
- size_t start = 0;
- for ( int imon = 0; imon < 12; imon++ )
- {
- time.tm_mon = imon;
- renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'B' ) );
- LocaleString monthnames( buffer.str() );
- names[imon] = monthnames.substr( start );
- start = monthnames.length();
- }
- return;
- }
-#endif
- apr_time_exp_t time;
- memset( & time, 0, sizeof( time ));
- for ( int imon = 0; imon < 12; imon++ )
- {
- time.tm_mon = imon;
- renderFacet( names[imon], & time, "%B" );
- }
+ renderFacet(locale, PatternToken::incrementMonth, 'B', 0x42, "%B", names);
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
{
s.append( names[tm.tm_mon] );
}
private:
- std::vector < LocaleString > names;
+ std::vector < LogString > names;
};
@@ -438,50 +368,17 @@
class AbbreviatedDayNameToken : public PatternToken
{
public:
- AbbreviatedDayNameToken( int
-#if LOG4CXX_HAS_STD_LOCALE
- width
-#endif
- , const std::locale *
-#if LOG4CXX_HAS_STD_LOCALE
- locale
-#endif
- ) : names( 7 )
- {
-#if LOG4CXX_HAS_STD_LOCALE
- if ( locale != NULL )
- {
- tm time;
- memset( & time, 0, sizeof( time ));
- std::basic_ostringstream < localechar > buffer;
- size_t start = 0;
- for ( int iday = 0; iday < 7; iday++ )
- {
- time.tm_wday = iday;
- renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'a' ) );
- LocaleString daynames( buffer.str() );
- names[iday] = daynames.substr( start );
- start = daynames.length();
- }
- return;
- }
-#endif
- apr_time_exp_t time;
- memset( & time, 0, sizeof( time ));
- for ( int iday = 0; iday < 7; iday++ )
- {
- time.tm_wday = iday;
- renderFacet( names[iday], & time, "%a" );
- }
+ AbbreviatedDayNameToken( int width, const std::locale *locale) : names( 7 ) {
+ renderFacet(locale, PatternToken::incrementDay, 'a', 0x61, "%a", names);
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
{
s.append( names[tm.tm_wday] );
}
private:
- std::vector < LocaleString > names;
+ std::vector < LogString > names;
};
@@ -490,50 +387,17 @@
class FullDayNameToken : public PatternToken
{
public:
- FullDayNameToken( int
-#if LOG4CXX_HAS_STD_LOCALE
- width
-#endif
- , const std::locale *
-#if LOG4CXX_HAS_STD_LOCALE
- locale
-#endif
- ) : names( 7 )
- {
-#if LOG4CXX_HAS_STD_LOCALE
- if ( locale != NULL )
- {
- tm time;
- memset( & time, 0, sizeof( time ));
- std::basic_ostringstream < localechar > buffer;
- size_t start = 0;
- for ( int iday = 0; iday < 7; iday++ )
- {
- time.tm_wday = iday;
- renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'A' ) );
- LocaleString daynames( buffer.str() );
- names[iday] = daynames.substr( start );
- start = daynames.length();
- }
- return;
- }
-#endif
- apr_time_exp_t time;
- memset( & time, 0, sizeof( time ));
- for ( int iday = 0; iday < 7; iday++ )
- {
- time.tm_wday = iday;
- renderFacet( names[iday], & time, "%A" );
- }
+ FullDayNameToken( int width, const std::locale *locale) : names( 7 ) {
+ renderFacet(locale, PatternToken::incrementDay, 'A', 0x41, "%A", names);
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
{
s.append( names[tm.tm_wday] );
}
private:
- std::vector < LocaleString > names;
+ std::vector < LogString > names;
};
@@ -623,50 +487,17 @@
class AMPMToken : public PatternToken
{
public:
- AMPMToken( int
-#if LOG4CXX_HAS_STD_LOCALE
- width
-#endif
- , const std::locale *
-#if LOG4CXX_HAS_STD_LOCALE
- locale
-#endif
- ) : names( 2 )
- {
-#if LOG4CXX_HAS_STD_LOCALE
- if ( locale != NULL )
- {
- tm time;
- memset( & time, 0, sizeof( time ));
- std::basic_ostringstream < localechar > buffer;
- size_t start = 0;
- for ( int i = 0; i < 2; i++ )
- {
- time.tm_hour = i * 12;
- renderFacet( * locale, buffer, & time, LOG4CXX_LOCALE_STR( 'p' ) );
- LocaleString ampm = buffer.str();
- names[i] = ampm.substr( start );
- start = ampm.length();
- }
- return;
- }
-#endif
- apr_time_exp_t time;
- memset( & time, 0, sizeof( time ));
- for ( int i = 0; i < 2; i++ )
- {
- time.tm_hour = i * 12;
- renderFacet( names[i], & time, "%p" );
- }
+ AMPMToken( int width, const std::locale *locale) : names( 2 ) {
+ renderFacet(locale, PatternToken::incrementHalfDay, 'p', 0x70, "%p", names);
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & /* p */ ) const
{
s.append( names[tm.tm_hour / 12] );
}
private:
- std::vector < LocaleString > names;
+ std::vector < LogString > names;
};
@@ -678,11 +509,8 @@
{
}
- void format( LocaleString& s, const apr_time_exp_t & , Pool & /* p */ ) const
- {
- LocaleString tzID;
- Transcoder::encode( timeZone->getID(), tzID );
- s.append( tzID );
+ void format( LogString& s, const apr_time_exp_t & , Pool & /* p */ ) const {
+ s.append(timeZone->getID());
}
void setTimeZone( const TimeZonePtr & zone )
@@ -703,23 +531,23 @@
{
}
- void format( LocaleString& s, const apr_time_exp_t & tm, Pool & p ) const
+ void format( LogString& s, const apr_time_exp_t & tm, Pool & p ) const
{
if ( tm.tm_gmtoff == 0 )
{
- s.append( 1, LOG4CXX_LOCALE_STR( 'Z' ) );
+ s.append( 1, 0x5A /* 'Z' */ );
}
else
{
apr_int32_t off = tm.tm_gmtoff;
size_t basePos = s.length();
- s.append( LOG4CXX_LOCALE_STR( "+0000" ) );
+ s.append( LOG4CXX_STR( "+0000" ) );
if ( off < 0 )
{
- s[basePos] = LOG4CXX_LOCALE_STR( '-' );
+ s[basePos] = 0x2D; // '-'
off = -off;
}
- LocaleString hours;
+ LogString hours;
StringHelper::toString( off / 3600, p, hours );
size_t hourPos = basePos + 2;
//
@@ -729,7 +557,7 @@
{
s[hourPos--] = hours[i];
}
- LocaleString min;
+ LogString min;
StringHelper::toString( ( off % 3600 ) / 60, p, min );
size_t minPos = basePos + 4;
//
@@ -746,29 +574,28 @@
-namespace log4cxx
-{
- namespace helpers
- {
- namespace SimpleDateFormatImpl
- {
+ }
+}
+}
- void addToken( const localechar spec, const int repeat, const std::locale * locale,
+using namespace log4cxx::helpers::SimpleDateFormatImpl;
+
+void SimpleDateFormat::addToken(const logchar spec, const int repeat, const std::locale * locale,
std::vector < PatternToken * > & pattern )
{
PatternToken * token = NULL;
switch ( spec )
{
- case LOG4CXX_LOCALE_STR( 'G' ):
+ case 0x47: // 'G'
token = ( new EraToken( repeat, locale ) );
break;
- case LOG4CXX_LOCALE_STR( 'y' ):
+ case 0x79: // 'y'
token = ( new YearToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'M' ):
+ case 0x4D: // 'M'
if ( repeat <= 2 )
{
token = ( new MonthToken( repeat ) );
@@ -783,27 +610,27 @@
}
break;
- case LOG4CXX_LOCALE_STR( 'w' ):
+ case 0x77: // 'w'
token = ( new WeekInYearToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'W' ):
+ case 0x57: // 'W'
token = ( new WeekInMonthToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'D' ):
+ case 0x44: // 'D'
token = ( new DayInYearToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'd' ):
+ case 0x64: // 'd'
token = ( new DayInMonthToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'F' ):
+ case 0x46: // 'F'
token = ( new DayOfWeekInMonthToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'E' ):
+ case 0x45: // 'E'
if ( repeat <= 3 )
{
token = ( new AbbreviatedDayNameToken( repeat, locale ) );
@@ -814,43 +641,43 @@
}
break;
- case LOG4CXX_LOCALE_STR( 'a' ):
+ case 0x61: // 'a'
token = ( new AMPMToken( repeat, locale ) );
break;
- case LOG4CXX_LOCALE_STR( 'H' ):
+ case 0x48: // 'H'
token = ( new MilitaryHourToken( repeat, 0 ) );
break;
- case LOG4CXX_LOCALE_STR( 'k' ):
+ case 0x6B: // 'k'
token = ( new MilitaryHourToken( repeat, 1 ) );
break;
- case LOG4CXX_LOCALE_STR( 'K' ):
+ case 0x4B: // 'K'
token = ( new HourToken( repeat, 0 ) );
break;
- case LOG4CXX_LOCALE_STR( 'h' ):
+ case 0x68: // 'h'
token = ( new HourToken( repeat, 1 ) );
break;
- case LOG4CXX_LOCALE_STR( 'm' ):
+ case 0x6D: // 'm'
token = ( new MinuteToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 's' ):
+ case 0x73: // 's'
token = ( new SecondToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'S' ):
+ case 0x53: // 'S'
token = ( new MillisecondToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'z' ):
+ case 0x7A: // 'z'
token = ( new GeneralTimeZoneToken( repeat ) );
break;
- case LOG4CXX_LOCALE_STR( 'Z' ):
+ case 0x5A: // 'Z'
token = ( new RFC822TimeZoneToken( repeat ) );
break;
@@ -859,16 +686,17 @@
}
assert( token != NULL );
pattern.push_back( token );
- }
+}
+
- void parsePattern( const LogString & fmt, const std::locale * locale,
+void SimpleDateFormat::parsePattern( const LogString & fmt, const std::locale * locale,
std::vector < PatternToken * > & pattern )
- {
+{
if ( !fmt.empty() )
{
LogString::const_iterator iter = fmt.begin();
int repeat = 1;
- localechar prevChar = * iter;
+ logchar prevChar = * iter;
for ( iter++; iter != fmt.end(); iter++ )
{
if ( * iter == prevChar )
@@ -884,14 +712,9 @@
}
addToken( prevChar, repeat, locale, pattern );
}
- }
- }
- }
}
-
-
SimpleDateFormat::SimpleDateFormat( const LogString & fmt ) : timeZone( TimeZone::getDefault() )
{
#if LOG4CXX_HAS_STD_LOCALE
@@ -931,12 +754,10 @@
apr_status_t stat = timeZone->explode( & exploded, time );
if ( stat == APR_SUCCESS )
{
- LocaleString formatted;
for ( PatternTokenList::const_iterator iter = pattern.begin(); iter != pattern.end(); iter++ )
{
- ( * iter )->format( formatted, exploded, p );
+ ( * iter )->format( s, exploded, p );
}
- log4cxx::helpers::Transcoder::decode( formatted, s );
}
}