1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/i18n/char_iterator.h"
7 #include "third_party/icu/source/common/unicode/utf8.h"
8 #include "third_party/icu/source/common/unicode/utf16.h"
13 UTF8CharIterator::UTF8CharIterator(const std::string* str)
14 : str_(reinterpret_cast<const uint8_t*>(str->data())),
21 U8_NEXT(str_, next_pos_, len_, char_);
24 UTF8CharIterator::~UTF8CharIterator() = default;
26 bool UTF8CharIterator::Advance() {
27 if (array_pos_ >= len_)
30 array_pos_ = next_pos_;
33 U8_NEXT(str_, next_pos_, len_, char_);
38 UTF16CharIterator::UTF16CharIterator(const string16* str)
39 : str_(reinterpret_cast<const char16*>(str->data())),
49 UTF16CharIterator::UTF16CharIterator(const char16* str, size_t str_len)
60 UTF16CharIterator::~UTF16CharIterator() = default;
62 bool UTF16CharIterator::Advance() {
63 if (array_pos_ >= len_)
66 array_pos_ = next_pos_;
74 void UTF16CharIterator::ReadChar() {
75 // This is actually a huge macro, so is worth having in a separate function.
76 U16_NEXT(str_, next_pos_, len_, char_);