Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 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 | |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 17 | #ifndef AAPT_TEXT_UTF8ITERATOR_H |
| 18 | #define AAPT_TEXT_UTF8ITERATOR_H |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 19 | |
| 20 | #include "android-base/macros.h" |
| 21 | #include "androidfw/StringPiece.h" |
| 22 | |
| 23 | namespace aapt { |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 24 | namespace text { |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 25 | |
| 26 | class Utf8Iterator { |
| 27 | public: |
| 28 | explicit Utf8Iterator(const android::StringPiece& str); |
| 29 | |
| 30 | bool HasNext() const; |
| 31 | |
Adam Lesinski | e967d3f | 2017-07-24 18:19:36 -0700 | [diff] [blame] | 32 | // Returns the current position of the iterator in bytes of the source UTF8 string. |
| 33 | // This position is the start of the codepoint returned by the next call to Next(). |
| 34 | size_t Position() const; |
| 35 | |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 36 | void Skip(int amount); |
| 37 | |
| 38 | char32_t Next(); |
| 39 | |
| 40 | private: |
| 41 | DISALLOW_COPY_AND_ASSIGN(Utf8Iterator); |
| 42 | |
| 43 | void DoNext(); |
| 44 | |
| 45 | android::StringPiece str_; |
Adam Lesinski | e967d3f | 2017-07-24 18:19:36 -0700 | [diff] [blame] | 46 | size_t current_pos_; |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 47 | size_t next_pos_; |
| 48 | char32_t current_codepoint_; |
| 49 | }; |
| 50 | |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 51 | } // namespace text |
Adam Lesinski | 549e437 | 2017-06-27 18:39:07 -0700 | [diff] [blame] | 52 | } // namespace aapt |
| 53 | |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 54 | #endif // AAPT_TEXT_UTF8ITERATOR_H |