summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/log/Statement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/log/Statement.cpp')
-rw-r--r--cpp/src/qpid/log/Statement.cpp53
1 files changed, 16 insertions, 37 deletions
diff --git a/cpp/src/qpid/log/Statement.cpp b/cpp/src/qpid/log/Statement.cpp
index e91756cb9a..86b069fd91 100644
--- a/cpp/src/qpid/log/Statement.cpp
+++ b/cpp/src/qpid/log/Statement.cpp
@@ -144,54 +144,33 @@ void Statement::log(const std::string& message) {
Statement::Initializer::Initializer(Statement& s) : statement(s) {
- // QPID-3891
+ // QPID-3891:
// From the given BOOST_CURRENT_FUNCTION name extract only the
// namespace-qualified-functionName, skipping return and calling args.
// Given:
// <possible return value type> qpid::name::space::Function(args)
// Return:
// "qpid::name::space::Function".
- if (s.function != NULL) {
- bool foundOParen(false);
- const char * opPtr;
- for (opPtr = s.function; *opPtr != '\0'; opPtr++) {
- if (*opPtr == '(') {
- foundOParen = true;
- break;
- }
- }
-
- if (foundOParen) {
- const char * bPtr = opPtr;
- for (bPtr = opPtr; bPtr > s.function; bPtr--) {
- if (bPtr[-1] == ' ') {
- break;
- }
- }
-
- size_t nStoreSize = opPtr - bPtr;
- if (nStoreSize > 0) {
- // Note: the struct into which this name is stored
- // is static and is never deleted.
- char * nStore = new char[nStoreSize + 1];
- std::copy (bPtr, opPtr, nStore);
- nStore[nStoreSize] = '\0';
-
- s.function = nStore;
- } else {
- // Ignore zero length name
- }
- } else {
- // No name found - do nothing
- }
- } else {
- // no function-name pointer to process
+ if (s.function) {
+ const char* end = s.function + strlen(s.function);
+ const char* fEnd = std::find(s.function, end, '(');
+ typedef std::reverse_iterator<const char*> Reverse;
+ const char* fBegin = find(Reverse(fEnd), Reverse(s.function), ' ').base();
+ size_t n = fEnd - fBegin;
+ char* name = new char[n+1];
+ std::copy(fBegin, fEnd, name);
+ name[n] = '\0';
+ s.function = name;
}
-
Statement::categorize(s);
Logger::instance().add(s);
}
+Statement::Initializer::~Initializer() {
+ delete[] const_cast<char*>(statement.function);
+ statement.function = 0;
+}
+
namespace {
const char* names[LevelTraits::COUNT] = {