• 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 namespace SysTuning {
18 namespace base {
PartingString(std::string str,char delimiter)19 PartingString::PartingString(std::string str, char delimiter) : str_(std::move(str)), delimiter_(delimiter)
20 {
21     begin_ = str_.begin();
22     end_ = str_.end();
23     cur_ = nullptr;
24 }
25 
Next()26 bool PartingString::Next()
27 {
28     while (begin_ != end_) {
29         if (*begin_ == delimiter_) {
30             begin_++;
31             continue;
32         }
33 
34         cur_ = begin_.base();
35         do {
36             if (*begin_ == delimiter_) {
37                 *(begin_++) = '\0';
38                 break;
39             }
40             if (*begin_ == '\0') {
41                 begin_ = end_;
42                 break;
43             }
44         } while (begin_++ != end_);
45 
46         if (*cur_) {
47             return true;
48         }
49 
50         begin_++;
51     }
52 
53     cur_ = nullptr;
54     return false;
55 }
56 } // namespace base
57 } // namespace SysTuning
58