| 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 #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/string16.h" | 12 #include "base/string16.h" |
| 13 | 13 |
| 14 // The CharIterator classes iterate through the characters in UTF8 and | 14 // The CharIterator classes iterate through the characters in UTF8 and |
| 15 // UTF16 strings. Example usage: | 15 // UTF16 strings. Example usage: |
| 16 // | 16 // |
| 17 // UTF8CharIterator iter(&str); | 17 // UTF8CharIterator iter(&str); |
| 18 // while (!iter.End()) { | 18 // while (!iter.End()) { |
| 19 // VLOG(1) << iter.get(); | 19 // VLOG(1) << iter.get(); |
| 20 // iter.Advance(); | 20 // iter.Advance(); |
| 21 // } | 21 // } |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 typedef unsigned char uint8_t; | 24 typedef unsigned char uint8_t; |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 namespace i18n { |
| 28 | 29 |
| 29 class UTF8CharIterator { | 30 class UTF8CharIterator { |
| 30 public: | 31 public: |
| 31 // Requires |str| to live as long as the UTF8CharIterator does. | 32 // Requires |str| to live as long as the UTF8CharIterator does. |
| 32 UTF8CharIterator(const std::string* str); | 33 UTF8CharIterator(const std::string* str); |
| 33 ~UTF8CharIterator() {} | 34 ~UTF8CharIterator(); |
| 34 | 35 |
| 35 // Return the starting array index of the current character within the | 36 // Return the starting array index of the current character within the |
| 36 // string. | 37 // string. |
| 37 int32 array_pos() const { return array_pos_; } | 38 int32 array_pos() const { return array_pos_; } |
| 38 | 39 |
| 39 // Return the logical index of the current character, independent of the | 40 // Return the logical index of the current character, independent of the |
| 40 // number of bytes each character takes. | 41 // number of bytes each character takes. |
| 41 int32 char_pos() const { return char_pos_; } | 42 int32 char_pos() const { return char_pos_; } |
| 42 | 43 |
| 43 // Return the current char. | 44 // Return the current char. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 70 int32 char_; | 71 int32 char_; |
| 71 | 72 |
| 72 DISALLOW_COPY_AND_ASSIGN(UTF8CharIterator); | 73 DISALLOW_COPY_AND_ASSIGN(UTF8CharIterator); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 class UTF16CharIterator { | 76 class UTF16CharIterator { |
| 76 public: | 77 public: |
| 77 // Requires |str| to live as long as the UTF16CharIterator does. | 78 // Requires |str| to live as long as the UTF16CharIterator does. |
| 78 UTF16CharIterator(const string16* str); | 79 UTF16CharIterator(const string16* str); |
| 79 UTF16CharIterator(const char16* str, size_t str_len); | 80 UTF16CharIterator(const char16* str, size_t str_len); |
| 80 ~UTF16CharIterator() {} | 81 ~UTF16CharIterator(); |
| 81 | 82 |
| 82 // Return the starting array index of the current character within the | 83 // Return the starting array index of the current character within the |
| 83 // string. | 84 // string. |
| 84 int32 array_pos() const { return array_pos_; } | 85 int32 array_pos() const { return array_pos_; } |
| 85 | 86 |
| 86 // Return the logical index of the current character, independent of the | 87 // Return the logical index of the current character, independent of the |
| 87 // number of codewords each character takes. | 88 // number of codewords each character takes. |
| 88 int32 char_pos() const { return char_pos_; } | 89 int32 char_pos() const { return char_pos_; } |
| 89 | 90 |
| 90 // Return the current char. | 91 // Return the current char. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 116 | 117 |
| 117 // Character index. | 118 // Character index. |
| 118 int32 char_pos_; | 119 int32 char_pos_; |
| 119 | 120 |
| 120 // The current character. | 121 // The current character. |
| 121 int32 char_; | 122 int32 char_; |
| 122 | 123 |
| 123 DISALLOW_COPY_AND_ASSIGN(UTF16CharIterator); | 124 DISALLOW_COPY_AND_ASSIGN(UTF16CharIterator); |
| 124 }; | 125 }; |
| 125 | 126 |
| 127 } // namespace i18n |
| 126 } // namespace base | 128 } // namespace base |
| 127 | 129 |
| 128 #endif // BASE_I18N_CHAR_ITERATOR_H_ | 130 #endif // BASE_I18N_CHAR_ITERATOR_H_ |
| OLD | NEW |