Coverage Report

Created: 2025-07-01 06:08

/src/logging-log4cxx/src/main/cpp/stringtokenizer.cpp
Line
Count
Source (jump to first uncovered line)
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/stringtokenizer.h>
20
#include <log4cxx/helpers/exception.h>
21
#if !defined(LOG4CXX)
22
  #define LOG4CXX 1
23
#endif
24
#include <log4cxx/private/log4cxx_private.h>
25
26
using namespace LOG4CXX_NS;
27
using namespace LOG4CXX_NS::helpers;
28
29
struct StringTokenizer::StringTokenizerPrivate{
30
0
  StringTokenizerPrivate(const LogString& str, const LogString& delim1) : src(str), delim(delim1), pos(0){}
31
  LogString src;
32
  LogString delim;
33
  size_t pos;
34
};
35
36
37
StringTokenizer::StringTokenizer(const LogString& str, const LogString& delim1)
38
0
  : m_priv(std::make_unique<StringTokenizerPrivate>(str, delim1))
39
0
{
40
0
}
41
42
StringTokenizer::~StringTokenizer()
43
0
{
44
0
}
45
46
bool StringTokenizer::hasMoreTokens() const
47
0
{
48
0
  return (m_priv->pos != LogString::npos
49
0
      && m_priv->src.find_first_not_of(m_priv->delim, m_priv->pos) != LogString::npos);
50
0
}
51
52
LogString StringTokenizer::nextToken()
53
0
{
54
0
  if (m_priv->pos != LogString::npos)
55
0
  {
56
0
    size_t nextPos = m_priv->src.find_first_not_of(m_priv->delim, m_priv->pos);
57
58
0
    if (nextPos != LogString::npos)
59
0
    {
60
0
      m_priv->pos = m_priv->src.find_first_of(m_priv->delim, nextPos);
61
62
0
      if (m_priv->pos == LogString::npos)
63
0
      {
64
0
        return m_priv->src.substr(nextPos);
65
0
      }
66
67
0
      return m_priv->src.substr(nextPos, m_priv->pos - nextPos);
68
0
    }
69
0
  }
70
71
0
  throw NoSuchElementException();
72
#if LOG4CXX_RETURN_AFTER_THROW
73
  return LogString();
74
#endif
75
0
}