Coverage Report

Created: 2026-01-09 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/messagepatternconverter.cpp
Line
Count
Source
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
#include <log4cxx/logstring.h>
19
#include <log4cxx/pattern/messagepatternconverter.h>
20
#include <log4cxx/spi/loggingevent.h>
21
#include <log4cxx/spi/location/locationinfo.h>
22
23
24
using namespace LOG4CXX_NS;
25
using namespace LOG4CXX_NS::pattern;
26
27
IMPLEMENT_LOG4CXX_OBJECT(MessagePatternConverter)
28
29
namespace {
30
/**
31
 * Formats the message of an logging event for a quoted context
32
  */
33
class QuotedMessagePatternConverter : public LoggingEventPatternConverter
34
{
35
  logchar m_quote;
36
  public:
37
    QuotedMessagePatternConverter(logchar quote)
38
1.20k
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
1.20k
      , m_quote(quote)
40
1.20k
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(char)
Line
Count
Source
38
558
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
558
      , m_quote(quote)
40
558
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(wchar_t)
Line
Count
Source
38
650
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
650
      , m_quote(quote)
40
650
      {}
41
42
    using LoggingEventPatternConverter::format;
43
44
    // Duplicate any quote character in the event message
45
    void format
46
      ( const spi::LoggingEventPtr& event
47
      , LogString&                  toAppendTo
48
      , helpers::Pool&              p
49
      ) const override
50
0
    {
51
0
      auto& input = event->getRenderedMessage();
52
0
      size_t endIndex, startIndex = 0;
53
0
      while ((endIndex = input.find(m_quote, startIndex)) != input.npos)
54
0
      {
55
0
        toAppendTo.append(input.substr(startIndex, endIndex - startIndex + 1));
56
0
        toAppendTo += m_quote;
57
0
        startIndex = endIndex + 1;
58
0
      }
59
0
      toAppendTo.append(input.substr(startIndex));
60
0
    }
Unexecuted instantiation: messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, log4cxx::helpers::Pool&) const
Unexecuted instantiation: messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, log4cxx::helpers::Pool&) const
61
};
62
}
63
64
MessagePatternConverter::MessagePatternConverter()
65
9
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
66
9
  , LOG4CXX_STR("message"))
67
9
{
68
9
}
Unexecuted instantiation: log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
Line
Count
Source
65
9
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
66
9
  , LOG4CXX_STR("message"))
67
9
{
68
9
}
69
70
PatternConverterPtr MessagePatternConverter::newInstance(
71
  const std::vector<LogString>& options)
72
8.26k
{
73
8.26k
  if (options.empty() || options.front().empty())
74
7.05k
  {
75
7.05k
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
7.05k
    return def;
77
7.05k
  }
78
1.20k
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
8.26k
}
log4cxx::pattern::MessagePatternConverter::newInstance(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)
Line
Count
Source
72
7.03k
{
73
7.03k
  if (options.empty() || options.front().empty())
74
6.48k
  {
75
6.48k
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
6.48k
    return def;
77
6.48k
  }
78
558
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
7.03k
}
log4cxx::pattern::MessagePatternConverter::newInstance(std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > > const&)
Line
Count
Source
72
1.22k
{
73
1.22k
  if (options.empty() || options.front().empty())
74
578
  {
75
578
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
578
    return def;
77
578
  }
78
650
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
1.22k
}
80
81
void MessagePatternConverter::format
82
  ( const spi::LoggingEventPtr& event
83
  , LogString&                  toAppendTo
84
  , helpers::Pool&           /* p */
85
  ) const
86
86.0k
{
87
86.0k
  toAppendTo.append(event->getRenderedMessage());
88
86.0k
}
log4cxx::pattern::MessagePatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, log4cxx::helpers::Pool&) const
Line
Count
Source
86
47.5k
{
87
47.5k
  toAppendTo.append(event->getRenderedMessage());
88
47.5k
}
log4cxx::pattern::MessagePatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, log4cxx::helpers::Pool&) const
Line
Count
Source
86
38.5k
{
87
38.5k
  toAppendTo.append(event->getRenderedMessage());
88
38.5k
}
89