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

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

Issue 3133028: Add functions to get the length or compute a substring of UTF8 and UTF16... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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
« no previous file with comments | « base/i18n/char_iterator.h ('k') | base/i18n/char_iterator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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
OLDNEW
« no previous file with comments | « base/i18n/char_iterator.h ('k') | base/i18n/char_iterator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698