Coverage Report

Created: 2026-09-04 06:38

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.55k
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
1.55k
      , m_quote(quote)
40
1.55k
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(char)
Line
Count
Source
38
634
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
634
      , m_quote(quote)
40
634
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(wchar_t)
Line
Count
Source
38
918
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
918
      , m_quote(quote)
40
918
      {}
41
42
    using LoggingEventPatternConverter::format;
43
44
    // Duplicate any quote character in the event message
45
    void format( LOG4CXX_FORMAT_EVENT_FORMAL_PARAMETERS ) const override
46
0
    {
47
0
      auto& input = event->getRenderedMessage();
48
0
      size_t endIndex, startIndex = 0;
49
0
      while ((endIndex = input.find(m_quote, startIndex)) != input.npos)
50
0
      {
51
0
        toAppendTo.append(input.substr(startIndex, endIndex - startIndex + 1));
52
0
        toAppendTo += m_quote;
53
0
        startIndex = endIndex + 1;
54
0
      }
55
0
      toAppendTo.append(input, startIndex, input.npos);
56
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
57
};
58
}
59
60
MessagePatternConverter::MessagePatternConverter()
61
28.9k
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
62
28.9k
  , LOG4CXX_STR("message"))
63
28.9k
{
64
28.9k
}
Unexecuted instantiation: log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
Line
Count
Source
61
28.9k
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
62
28.9k
  , LOG4CXX_STR("message"))
63
28.9k
{
64
28.9k
}
65
66
PatternConverterPtr MessagePatternConverter::newInstance(
67
  const std::vector<LogString>& options)
68
30.4k
{
69
30.4k
  if (options.empty() || options.front().empty())
70
28.9k
  {
71
28.9k
    return std::make_shared<MessagePatternConverter>();
72
28.9k
  }
73
1.55k
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
74
30.4k
}
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
68
27.3k
{
69
27.3k
  if (options.empty() || options.front().empty())
70
26.7k
  {
71
26.7k
    return std::make_shared<MessagePatternConverter>();
72
26.7k
  }
73
634
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
74
27.3k
}
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
68
3.12k
{
69
3.12k
  if (options.empty() || options.front().empty())
70
2.20k
  {
71
2.20k
    return std::make_shared<MessagePatternConverter>();
72
2.20k
  }
73
918
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
74
3.12k
}
75
76
void MessagePatternConverter::format( LOG4CXX_FORMAT_EVENT_FORMAL_PARAMETERS ) const
77
139k
{
78
139k
  auto& msg = event->getRenderedMessage();
79
139k
  auto& info = getFormattingInfo();
80
139k
  if (info.getMaxLength() < msg.length())
81
0
    toAppendTo.append(&msg[msg.length() - info.getMaxLength()], info.getMaxLength());
82
139k
  else
83
139k
    toAppendTo.append(msg);
84
139k
}
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
77
49.5k
{
78
49.5k
  auto& msg = event->getRenderedMessage();
79
49.5k
  auto& info = getFormattingInfo();
80
49.5k
  if (info.getMaxLength() < msg.length())
81
0
    toAppendTo.append(&msg[msg.length() - info.getMaxLength()], info.getMaxLength());
82
49.5k
  else
83
49.5k
    toAppendTo.append(msg);
84
49.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
77
90.1k
{
78
90.1k
  auto& msg = event->getRenderedMessage();
79
90.1k
  auto& info = getFormattingInfo();
80
90.1k
  if (info.getMaxLength() < msg.length())
81
0
    toAppendTo.append(&msg[msg.length() - info.getMaxLength()], info.getMaxLength());
82
90.1k
  else
83
90.1k
    toAppendTo.append(msg);
84
90.1k
}
85