• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 AAPT_TEXT_UTF8ITERATOR_H
18 #define AAPT_TEXT_UTF8ITERATOR_H
19 
20 #include "android-base/macros.h"
21 #include "androidfw/StringPiece.h"
22 
23 namespace aapt {
24 namespace text {
25 
26 class Utf8Iterator {
27  public:
28   explicit Utf8Iterator(const android::StringPiece& str);
29 
30   bool HasNext() const;
31 
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 
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_;
46   size_t current_pos_;
47   size_t next_pos_;
48   char32_t current_codepoint_;
49 };
50 
51 }  // namespace text
52 }  // namespace aapt
53 
54 #endif  // AAPT_TEXT_UTF8ITERATOR_H
55