Coverage Report

Created: 2025-08-29 06:29

/src/logging-log4cxx/src/main/cpp/strftimedateformat.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/helpers/strftimedateformat.h>
20
21
#include <apr_time.h>
22
#include <log4cxx/helpers/transcoder.h>
23
24
using namespace LOG4CXX_NS;
25
using namespace LOG4CXX_NS::helpers;
26
27
struct StrftimeDateFormat::StrftimeDateFormatPrivate{
28
  StrftimeDateFormatPrivate() :
29
4.81k
    timeZone(TimeZone::getDefault())
30
4.81k
  {}
31
32
  /**
33
  *    Time zone.
34
  */
35
  TimeZonePtr timeZone;
36
  std::string pattern;
37
};
38
39
40
StrftimeDateFormat::StrftimeDateFormat(const LogString& fmt)
41
4.81k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
4.81k
{
43
4.81k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
4.81k
}
log4cxx::helpers::StrftimeDateFormat::StrftimeDateFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
41
1.64k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
1.64k
{
43
1.64k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
1.64k
}
log4cxx::helpers::StrftimeDateFormat::StrftimeDateFormat(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
41
3.16k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
3.16k
{
43
3.16k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
3.16k
}
45
46
StrftimeDateFormat::~StrftimeDateFormat()
47
4.81k
{
48
4.81k
}
49
50
51
void StrftimeDateFormat::format(LogString& s, log4cxx_time_t time, Pool& /* p */ ) const
52
690
{
53
690
  apr_time_exp_t exploded;
54
690
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
690
  if (stat == APR_SUCCESS)
57
690
  {
58
690
    const apr_size_t bufSize = 255;
59
690
    char buf[bufSize];
60
690
    apr_size_t bufLen;
61
690
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
690
    if (stat == APR_SUCCESS)
64
690
    {
65
690
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
690
    }
67
690
  }
68
690
}
log4cxx::helpers::StrftimeDateFormat::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, long, log4cxx::helpers::Pool&) const
Line
Count
Source
52
72
{
53
72
  apr_time_exp_t exploded;
54
72
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
72
  if (stat == APR_SUCCESS)
57
72
  {
58
72
    const apr_size_t bufSize = 255;
59
72
    char buf[bufSize];
60
72
    apr_size_t bufLen;
61
72
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
72
    if (stat == APR_SUCCESS)
64
72
    {
65
72
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
72
    }
67
72
  }
68
72
}
log4cxx::helpers::StrftimeDateFormat::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, long, log4cxx::helpers::Pool&) const
Line
Count
Source
52
618
{
53
618
  apr_time_exp_t exploded;
54
618
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
618
  if (stat == APR_SUCCESS)
57
618
  {
58
618
    const apr_size_t bufSize = 255;
59
618
    char buf[bufSize];
60
618
    apr_size_t bufLen;
61
618
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
618
    if (stat == APR_SUCCESS)
64
618
    {
65
618
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
618
    }
67
618
  }
68
618
}
69
70
void StrftimeDateFormat::setTimeZone(const TimeZonePtr& zone)
71
1.71k
{
72
1.71k
  m_priv->timeZone = zone;
73
1.71k
}
74
75