• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "parting_string.h"
17 #include <utility>
18 
19 namespace SysTuning {
20 namespace base {
PartingString(std::string str,char delimiter)21 PartingString::PartingString(std::string str, char delimiter) : str_(std::move(str)), delimiter_(delimiter)
22 {
23     begin_ = str_.begin();
24     end_ = str_.end();
25     cur_ = nullptr;
26 }
27 
Next()28 bool PartingString::Next()
29 {
30     while (begin_ != end_) {
31         if (*begin_ == delimiter_) {
32             begin_++;
33             continue;
34         }
35 
36         cur_ = begin_.base();
37         do {
38             if (*begin_ == delimiter_) {
39                 *(begin_++) = '\0';
40                 break;
41             }
42             if (*begin_ == '\0') {
43                 begin_ = end_;
44                 break;
45             }
46         } while (begin_++ != end_);
47 
48         if (*cur_) {
49             return true;
50         }
51 
52         begin_++;
53     }
54 
55     cur_ = nullptr;
56     return false;
57 }
58 } // namespace base
59 } // namespace SysTuning
60