OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/i18n/char_iterator.h" | 5 #include "base/i18n/char_iterator.h" |
6 | 6 |
7 #include "unicode/utf8.h" | 7 #include "unicode/utf8.h" |
8 #include "unicode/utf16.h" | 8 #include "unicode/utf16.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
| 11 namespace i18n { |
11 | 12 |
12 UTF8CharIterator::UTF8CharIterator(const std::string* str) | 13 UTF8CharIterator::UTF8CharIterator(const std::string* str) |
13 : str_(reinterpret_cast<const uint8_t*>(str->data())), | 14 : str_(reinterpret_cast<const uint8_t*>(str->data())), |
14 len_(str->size()), | 15 len_(str->size()), |
15 array_pos_(0), | 16 array_pos_(0), |
16 next_pos_(0), | 17 next_pos_(0), |
17 char_pos_(0), | 18 char_pos_(0), |
18 char_(0) { | 19 char_(0) { |
19 if (len_) | 20 if (len_) |
20 U8_NEXT(str_, next_pos_, len_, char_); | 21 U8_NEXT(str_, next_pos_, len_, char_); |
21 } | 22 } |
22 | 23 |
| 24 UTF8CharIterator::~UTF8CharIterator() { |
| 25 } |
| 26 |
23 bool UTF8CharIterator::Advance() { | 27 bool UTF8CharIterator::Advance() { |
24 if (array_pos_ >= len_) | 28 if (array_pos_ >= len_) |
25 return false; | 29 return false; |
26 | 30 |
27 array_pos_ = next_pos_; | 31 array_pos_ = next_pos_; |
28 char_pos_++; | 32 char_pos_++; |
29 if (next_pos_ < len_) | 33 if (next_pos_ < len_) |
30 U8_NEXT(str_, next_pos_, len_, char_); | 34 U8_NEXT(str_, next_pos_, len_, char_); |
31 | 35 |
32 return true; | 36 return true; |
(...skipping 14 matching lines...) Expand all Loading... |
47 : str_(str), | 51 : str_(str), |
48 len_(str_len), | 52 len_(str_len), |
49 array_pos_(0), | 53 array_pos_(0), |
50 next_pos_(0), | 54 next_pos_(0), |
51 char_pos_(0), | 55 char_pos_(0), |
52 char_(0) { | 56 char_(0) { |
53 if (len_) | 57 if (len_) |
54 ReadChar(); | 58 ReadChar(); |
55 } | 59 } |
56 | 60 |
| 61 UTF16CharIterator::~UTF16CharIterator() { |
| 62 } |
| 63 |
57 bool UTF16CharIterator::Advance() { | 64 bool UTF16CharIterator::Advance() { |
58 if (array_pos_ >= len_) | 65 if (array_pos_ >= len_) |
59 return false; | 66 return false; |
60 | 67 |
61 array_pos_ = next_pos_; | 68 array_pos_ = next_pos_; |
62 char_pos_++; | 69 char_pos_++; |
63 if (next_pos_ < len_) | 70 if (next_pos_ < len_) |
64 ReadChar(); | 71 ReadChar(); |
65 | 72 |
66 return true; | 73 return true; |
67 } | 74 } |
68 | 75 |
69 void UTF16CharIterator::ReadChar() { | 76 void UTF16CharIterator::ReadChar() { |
70 // This is actually a huge macro, so is worth having in a separate function. | 77 // This is actually a huge macro, so is worth having in a separate function. |
71 U16_NEXT(str_, next_pos_, len_, char_); | 78 U16_NEXT(str_, next_pos_, len_, char_); |
72 } | 79 } |
73 | 80 |
| 81 } // namespace i18n |
74 } // namespace base | 82 } // namespace base |
OLD | NEW |