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 "unicode/utf8.h"
8 #include "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() {
27 bool UTF8CharIterator::Advance() {
28 if (array_pos_
>= len_
)
31 array_pos_
= next_pos_
;
34 U8_NEXT(str_
, next_pos_
, len_
, char_
);
39 UTF16CharIterator::UTF16CharIterator(const string16
* str
)
40 : str_(reinterpret_cast<const char16
*>(str
->data())),
50 UTF16CharIterator::UTF16CharIterator(const char16
* str
, size_t str_len
)
61 UTF16CharIterator::~UTF16CharIterator() {
64 bool UTF16CharIterator::Advance() {
65 if (array_pos_
>= len_
)
68 array_pos_
= next_pos_
;
76 void UTF16CharIterator::ReadChar() {
77 // This is actually a huge macro, so is worth having in a separate function.
78 U16_NEXT(str_
, next_pos_
, len_
, char_
);