OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #include "base/i18n/char_iterator.h" |
| 6 |
| 7 #include "unicode/utf8.h" |
| 8 #include "unicode/utf16.h" |
| 9 |
| 10 namespace base { |
| 11 |
| 12 UTF8CharIterator::UTF8CharIterator(const std::string* str) |
| 13 : str_(reinterpret_cast<const uint8_t*>(str->data())), |
| 14 len_(str->size()), |
| 15 array_pos_(0), |
| 16 next_pos_(0), |
| 17 char_pos_(0), |
| 18 char_(0) { |
| 19 if (len_) |
| 20 U8_NEXT(str_, next_pos_, len_, char_); |
| 21 } |
| 22 |
| 23 bool UTF8CharIterator::Advance() { |
| 24 if (array_pos_ >= len_) |
| 25 return false; |
| 26 |
| 27 array_pos_ = next_pos_; |
| 28 char_pos_++; |
| 29 if (next_pos_ < len_) |
| 30 U8_NEXT(str_, next_pos_, len_, char_); |
| 31 |
| 32 return true; |
| 33 } |
| 34 |
| 35 UTF16CharIterator::UTF16CharIterator(const string16* str) |
| 36 : str_(reinterpret_cast<const char16*>(str->data())), |
| 37 len_(str->size()), |
| 38 array_pos_(0), |
| 39 next_pos_(0), |
| 40 char_pos_(0), |
| 41 char_(0) { |
| 42 if (len_) |
| 43 U16_NEXT(str_, next_pos_, len_, char_); |
| 44 } |
| 45 |
| 46 bool UTF16CharIterator::Advance() { |
| 47 if (array_pos_ >= len_) |
| 48 return false; |
| 49 |
| 50 array_pos_ = next_pos_; |
| 51 char_pos_++; |
| 52 if (next_pos_ < len_) |
| 53 U16_NEXT(str_, next_pos_, len_, char_); |
| 54 |
| 55 return true; |
| 56 } |
| 57 |
| 58 } // namespace base |
OLD | NEW |