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