blob: 9318401876d186f5db4d9087092bf7acc9c025c2 [file] [log] [blame]
Adam Lesinski549e4372017-06-27 18:39:07 -07001/*
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 Lesinski66ea8402017-06-28 11:44:11 -070017#ifndef AAPT_TEXT_UTF8ITERATOR_H
18#define AAPT_TEXT_UTF8ITERATOR_H
Adam Lesinski549e4372017-06-27 18:39:07 -070019
20#include "android-base/macros.h"
21#include "androidfw/StringPiece.h"
22
23namespace aapt {
Adam Lesinski66ea8402017-06-28 11:44:11 -070024namespace text {
Adam Lesinski549e4372017-06-27 18:39:07 -070025
26class Utf8Iterator {
27 public:
28 explicit Utf8Iterator(const android::StringPiece& str);
29
30 bool HasNext() const;
31
Adam Lesinskie967d3f2017-07-24 18:19:36 -070032 // 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 Lesinski549e4372017-06-27 18:39:07 -070036 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 Lesinskie967d3f2017-07-24 18:19:36 -070046 size_t current_pos_;
Adam Lesinski549e4372017-06-27 18:39:07 -070047 size_t next_pos_;
48 char32_t current_codepoint_;
49};
50
Adam Lesinski66ea8402017-06-28 11:44:11 -070051} // namespace text
Adam Lesinski549e4372017-06-27 18:39:07 -070052} // namespace aapt
53
Adam Lesinski66ea8402017-06-28 11:44:11 -070054#endif // AAPT_TEXT_UTF8ITERATOR_H