diff options
Diffstat (limited to 'property_service/libpropertyinfoserializer/space_tokenizer.h')
-rw-r--r-- | property_service/libpropertyinfoserializer/space_tokenizer.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/property_service/libpropertyinfoserializer/space_tokenizer.h b/property_service/libpropertyinfoserializer/space_tokenizer.h new file mode 100644 index 000000000..fba0c5841 --- /dev/null +++ b/property_service/libpropertyinfoserializer/space_tokenizer.h | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef PROPERTY_INFO_SERIALIZER_SPACE_TOKENIZER_H | ||
18 | #define PROPERTY_INFO_SERIALIZER_SPACE_TOKENIZER_H | ||
19 | |||
20 | namespace android { | ||
21 | namespace properties { | ||
22 | |||
23 | class SpaceTokenizer { | ||
24 | public: | ||
25 | SpaceTokenizer(const std::string& string) | ||
26 | : string_(string), it_(string_.begin()), end_(string_.end()) {} | ||
27 | |||
28 | std::string GetNext() { | ||
29 | auto next = std::string(); | ||
30 | while (it_ != end_ && !isspace(*it_)) { | ||
31 | next.push_back(*it_++); | ||
32 | } | ||
33 | while (it_ != end_ && isspace(*it_)) { | ||
34 | it_++; | ||
35 | } | ||
36 | return next; | ||
37 | } | ||
38 | |||
39 | std::string GetRemaining() { return std::string(it_, end_); } | ||
40 | |||
41 | private: | ||
42 | std::string string_; | ||
43 | std::string::const_iterator it_; | ||
44 | std::string::const_iterator end_; | ||
45 | }; | ||
46 | |||
47 | } // namespace properties | ||
48 | } // namespace android | ||
49 | |||
50 | #endif | ||