Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: base/i18n/char_iterator.cc

Issue 6355005: base/i18n: Add namespace i18n to CharIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unittests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
12
13 // UTF8CharIterator -----------------------------------------------------------
brettw 2011/01/18 18:36:10 I probably wouldn't bother adding these lines in t
tfarina 2011/01/18 18:42:04 Removed.
11 14
12 UTF8CharIterator::UTF8CharIterator(const std::string* str) 15 UTF8CharIterator::UTF8CharIterator(const std::string* str)
13 : str_(reinterpret_cast<const uint8_t*>(str->data())), 16 : str_(reinterpret_cast<const uint8_t*>(str->data())),
14 len_(str->size()), 17 len_(str->size()),
15 array_pos_(0), 18 array_pos_(0),
16 next_pos_(0), 19 next_pos_(0),
17 char_pos_(0), 20 char_pos_(0),
18 char_(0) { 21 char_(0) {
19 if (len_) 22 if (len_)
20 U8_NEXT(str_, next_pos_, len_, char_); 23 U8_NEXT(str_, next_pos_, len_, char_);
21 } 24 }
22 25
26 UTF8CharIterator::~UTF8CharIterator() {
27 }
28
23 bool UTF8CharIterator::Advance() { 29 bool UTF8CharIterator::Advance() {
24 if (array_pos_ >= len_) 30 if (array_pos_ >= len_)
25 return false; 31 return false;
26 32
27 array_pos_ = next_pos_; 33 array_pos_ = next_pos_;
28 char_pos_++; 34 char_pos_++;
29 if (next_pos_ < len_) 35 if (next_pos_ < len_)
30 U8_NEXT(str_, next_pos_, len_, char_); 36 U8_NEXT(str_, next_pos_, len_, char_);
31 37
32 return true; 38 return true;
33 } 39 }
34 40
41 // UTF16CharIterator ----------------------------------------------------------
42
35 UTF16CharIterator::UTF16CharIterator(const string16* str) 43 UTF16CharIterator::UTF16CharIterator(const string16* str)
36 : str_(reinterpret_cast<const char16*>(str->data())), 44 : str_(reinterpret_cast<const char16*>(str->data())),
37 len_(str->size()), 45 len_(str->size()),
38 array_pos_(0), 46 array_pos_(0),
39 next_pos_(0), 47 next_pos_(0),
40 char_pos_(0), 48 char_pos_(0),
41 char_(0) { 49 char_(0) {
42 if (len_) 50 if (len_)
43 ReadChar(); 51 ReadChar();
44 } 52 }
45 53
46 UTF16CharIterator::UTF16CharIterator(const char16* str, size_t str_len) 54 UTF16CharIterator::UTF16CharIterator(const char16* str, size_t str_len)
47 : str_(str), 55 : str_(str),
48 len_(str_len), 56 len_(str_len),
49 array_pos_(0), 57 array_pos_(0),
50 next_pos_(0), 58 next_pos_(0),
51 char_pos_(0), 59 char_pos_(0),
52 char_(0) { 60 char_(0) {
53 if (len_) 61 if (len_)
54 ReadChar(); 62 ReadChar();
55 } 63 }
56 64
65 UTF16CharIterator::~UTF16CharIterator() {
66 }
67
57 bool UTF16CharIterator::Advance() { 68 bool UTF16CharIterator::Advance() {
58 if (array_pos_ >= len_) 69 if (array_pos_ >= len_)
59 return false; 70 return false;
60 71
61 array_pos_ = next_pos_; 72 array_pos_ = next_pos_;
62 char_pos_++; 73 char_pos_++;
63 if (next_pos_ < len_) 74 if (next_pos_ < len_)
64 ReadChar(); 75 ReadChar();
65 76
66 return true; 77 return true;
67 } 78 }
68 79
69 void UTF16CharIterator::ReadChar() { 80 void UTF16CharIterator::ReadChar() {
70 // This is actually a huge macro, so is worth having in a separate function. 81 // This is actually a huge macro, so is worth having in a separate function.
71 U16_NEXT(str_, next_pos_, len_, char_); 82 U16_NEXT(str_, next_pos_, len_, char_);
72 } 83 }
73 84
85 } // namespace i18n
74 } // namespace base 86 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698