OLD | NEW |
1 // Copyright (c) 2011 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 #ifndef BASE_I18N_CHAR_ITERATOR_H_ | 5 #ifndef BASE_I18N_CHAR_ITERATOR_H_ |
6 #define BASE_I18N_CHAR_ITERATOR_H_ | 6 #define BASE_I18N_CHAR_ITERATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/i18n/base_i18n_export.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 | 14 |
14 // The CharIterator classes iterate through the characters in UTF8 and | 15 // The CharIterator classes iterate through the characters in UTF8 and |
15 // UTF16 strings. Example usage: | 16 // UTF16 strings. Example usage: |
16 // | 17 // |
17 // UTF8CharIterator iter(&str); | 18 // UTF8CharIterator iter(&str); |
18 // while (!iter.End()) { | 19 // while (!iter.End()) { |
19 // VLOG(1) << iter.get(); | 20 // VLOG(1) << iter.get(); |
20 // iter.Advance(); | 21 // iter.Advance(); |
21 // } | 22 // } |
22 | 23 |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
24 typedef unsigned char uint8_t; | 25 typedef unsigned char uint8_t; |
25 #endif | 26 #endif |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 namespace i18n { | 29 namespace i18n { |
29 | 30 |
30 class UTF8CharIterator { | 31 class BASE_I18N_EXPORT UTF8CharIterator { |
31 public: | 32 public: |
32 // Requires |str| to live as long as the UTF8CharIterator does. | 33 // Requires |str| to live as long as the UTF8CharIterator does. |
33 UTF8CharIterator(const std::string* str); | 34 UTF8CharIterator(const std::string* str); |
34 ~UTF8CharIterator(); | 35 ~UTF8CharIterator(); |
35 | 36 |
36 // Return the starting array index of the current character within the | 37 // Return the starting array index of the current character within the |
37 // string. | 38 // string. |
38 int32 array_pos() const { return array_pos_; } | 39 int32 array_pos() const { return array_pos_; } |
39 | 40 |
40 // Return the logical index of the current character, independent of the | 41 // Return the logical index of the current character, independent of the |
(...skipping 25 matching lines...) Expand all Loading... |
66 | 67 |
67 // Character index. | 68 // Character index. |
68 int32 char_pos_; | 69 int32 char_pos_; |
69 | 70 |
70 // The current character. | 71 // The current character. |
71 int32 char_; | 72 int32 char_; |
72 | 73 |
73 DISALLOW_COPY_AND_ASSIGN(UTF8CharIterator); | 74 DISALLOW_COPY_AND_ASSIGN(UTF8CharIterator); |
74 }; | 75 }; |
75 | 76 |
76 class UTF16CharIterator { | 77 class BASE_I18N_EXPORT UTF16CharIterator { |
77 public: | 78 public: |
78 // Requires |str| to live as long as the UTF16CharIterator does. | 79 // Requires |str| to live as long as the UTF16CharIterator does. |
79 UTF16CharIterator(const string16* str); | 80 UTF16CharIterator(const string16* str); |
80 UTF16CharIterator(const char16* str, size_t str_len); | 81 UTF16CharIterator(const char16* str, size_t str_len); |
81 ~UTF16CharIterator(); | 82 ~UTF16CharIterator(); |
82 | 83 |
83 // Return the starting array index of the current character within the | 84 // Return the starting array index of the current character within the |
84 // string. | 85 // string. |
85 int32 array_pos() const { return array_pos_; } | 86 int32 array_pos() const { return array_pos_; } |
86 | 87 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // The current character. | 122 // The current character. |
122 int32 char_; | 123 int32 char_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(UTF16CharIterator); | 125 DISALLOW_COPY_AND_ASSIGN(UTF16CharIterator); |
125 }; | 126 }; |
126 | 127 |
127 } // namespace i18n | 128 } // namespace i18n |
128 } // namespace base | 129 } // namespace base |
129 | 130 |
130 #endif // BASE_I18N_CHAR_ITERATOR_H_ | 131 #endif // BASE_I18N_CHAR_ITERATOR_H_ |
OLD | NEW |