/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/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 | 1 |   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 | 1 |   : m_priv(std::make_unique<StringTokenizerPrivate>(str, delim1)) | 
| 39 | 1 | { | 
| 40 | 1 | } | 
| 41 |  |  | 
| 42 |  | StringTokenizer::~StringTokenizer() | 
| 43 | 1 | { | 
| 44 | 1 | } | 
| 45 |  |  | 
| 46 |  | bool StringTokenizer::hasMoreTokens() const | 
| 47 | 3 | { | 
| 48 | 3 |   return (m_priv->pos != LogString::npos | 
| 49 | 2 |       && m_priv->src.find_first_not_of(m_priv->delim, m_priv->pos) != LogString::npos); | 
| 50 | 3 | } | 
| 51 |  |  | 
| 52 |  | LogString StringTokenizer::nextToken() | 
| 53 | 2 | { | 
| 54 | 2 |   if (m_priv->pos != LogString::npos) | 
| 55 | 2 |   { | 
| 56 | 2 |     size_t nextPos = m_priv->src.find_first_not_of(m_priv->delim, m_priv->pos); | 
| 57 |  |  | 
| 58 | 2 |     if (nextPos != LogString::npos) | 
| 59 | 2 |     { | 
| 60 | 2 |       m_priv->pos = m_priv->src.find_first_of(m_priv->delim, nextPos); | 
| 61 |  |  | 
| 62 | 2 |       if (m_priv->pos == LogString::npos) | 
| 63 | 1 |       { | 
| 64 | 1 |         return m_priv->src.substr(nextPos); | 
| 65 | 1 |       } | 
| 66 |  |  | 
| 67 | 1 |       return m_priv->src.substr(nextPos, m_priv->pos - nextPos); | 
| 68 | 2 |     } | 
| 69 | 2 |   } | 
| 70 |  |  | 
| 71 | 0 |   throw NoSuchElementException(); | 
| 72 |  | #if LOG4CXX_RETURN_AFTER_THROW | 
| 73 |  |   return LogString(); | 
| 74 |  | #endif | 
| 75 | 2 | } |