Coverage Report

Created: 2025-11-16 06:34

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.02k
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
1.02k
      , m_quote(quote)
40
1.02k
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(char)
Line
Count
Source
38
637
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
637
      , m_quote(quote)
40
637
      {}
messagepatternconverter.cpp:(anonymous namespace)::QuotedMessagePatternConverter::QuotedMessagePatternConverter(wchar_t)
Line
Count
Source
38
389
      : LoggingEventPatternConverter(LOG4CXX_STR("Message"), LOG4CXX_STR("quoted"))
39
389
      , m_quote(quote)
40
389
      {}
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
7
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
66
7
  , LOG4CXX_STR("message"))
67
7
{
68
7
}
Unexecuted instantiation: log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
log4cxx::pattern::MessagePatternConverter::MessagePatternConverter()
Line
Count
Source
65
7
  : LoggingEventPatternConverter(LOG4CXX_STR("Message")
66
7
  , LOG4CXX_STR("message"))
67
7
{
68
7
}
69
70
PatternConverterPtr MessagePatternConverter::newInstance(
71
  const std::vector<LogString>& options)
72
7.80k
{
73
7.80k
  if (options.empty() || options.front().empty())
74
6.77k
  {
75
6.77k
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
6.77k
    return def;
77
6.77k
  }
78
1.02k
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
7.80k
}
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
6.87k
{
73
6.87k
  if (options.empty() || options.front().empty())
74
6.23k
  {
75
6.23k
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
6.23k
    return def;
77
6.23k
  }
78
637
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
6.87k
}
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
935
{
73
935
  if (options.empty() || options.front().empty())
74
546
  {
75
546
    static helpers::WideLife<PatternConverterPtr> def = std::make_shared<MessagePatternConverter>();
76
546
    return def;
77
546
  }
78
389
  return std::make_shared<QuotedMessagePatternConverter>(options.front().front());
79
935
}
80
81
void MessagePatternConverter::format
82
  ( const spi::LoggingEventPtr& event
83
  , LogString&                  toAppendTo
84
  , helpers::Pool&           /* p */
85
  ) const
86
207k
{
87
207k
  toAppendTo.append(event->getRenderedMessage());
88
207k
}
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
45.4k
{
87
45.4k
  toAppendTo.append(event->getRenderedMessage());
88
45.4k
}
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
161k
{
87
161k
  toAppendTo.append(event->getRenderedMessage());
88
161k
}
89