Coverage Report

Created: 2025-07-18 06:17

/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
5.00k
    timeZone(TimeZone::getDefault())
30
5.00k
  {}
31
32
  /**
33
  *    Time zone.
34
  */
35
  TimeZonePtr timeZone;
36
  std::string pattern;
37
};
38
39
40
StrftimeDateFormat::StrftimeDateFormat(const LogString& fmt)
41
5.00k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
5.00k
{
43
5.00k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
5.00k
}
log4cxx::helpers::StrftimeDateFormat::StrftimeDateFormat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
41
1.46k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
1.46k
{
43
1.46k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
1.46k
}
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.54k
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
3.54k
{
43
3.54k
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
3.54k
}
45
46
StrftimeDateFormat::~StrftimeDateFormat()
47
5.00k
{
48
5.00k
}
49
50
51
void StrftimeDateFormat::format(LogString& s, log4cxx_time_t time, Pool& /* p */ ) const
52
698
{
53
698
  apr_time_exp_t exploded;
54
698
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
698
  if (stat == APR_SUCCESS)
57
698
  {
58
698
    const apr_size_t bufSize = 255;
59
698
    char buf[bufSize];
60
698
    apr_size_t bufLen;
61
698
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
698
    if (stat == APR_SUCCESS)
64
698
    {
65
698
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
698
    }
67
698
  }
68
698
}
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
70
{
53
70
  apr_time_exp_t exploded;
54
70
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
70
  if (stat == APR_SUCCESS)
57
70
  {
58
70
    const apr_size_t bufSize = 255;
59
70
    char buf[bufSize];
60
70
    apr_size_t bufLen;
61
70
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
70
    if (stat == APR_SUCCESS)
64
70
    {
65
70
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
70
    }
67
70
  }
68
70
}
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
628
{
53
628
  apr_time_exp_t exploded;
54
628
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
628
  if (stat == APR_SUCCESS)
57
628
  {
58
628
    const apr_size_t bufSize = 255;
59
628
    char buf[bufSize];
60
628
    apr_size_t bufLen;
61
628
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
628
    if (stat == APR_SUCCESS)
64
628
    {
65
628
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
628
    }
67
628
  }
68
628
}
69
70
void StrftimeDateFormat::setTimeZone(const TimeZonePtr& zone)
71
1.91k
{
72
1.91k
  m_priv->timeZone = zone;
73
1.91k
}
74
75