123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #ifndef BASE_I18N_CHAR_ITERATOR_H_
- #define BASE_I18N_CHAR_ITERATOR_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <string>
- #include "base/gtest_prod_util.h"
- #include "base/i18n/base_i18n_export.h"
- #include "base/macros.h"
- #include "base/strings/string16.h"
- #include "build/build_config.h"
- #if defined(OS_WIN)
- typedef unsigned char uint8_t;
- #endif
- namespace base {
- namespace i18n {
- class BASE_I18N_EXPORT UTF8CharIterator {
- public:
-
- explicit UTF8CharIterator(const std::string* str);
- ~UTF8CharIterator();
-
-
- int32_t array_pos() const { return array_pos_; }
-
-
- int32_t char_pos() const { return char_pos_; }
-
- int32_t get() const { return char_; }
-
- bool end() const { return array_pos_ == len_; }
-
-
- bool Advance();
- private:
-
- const uint8_t* str_;
-
- int32_t len_;
-
- int32_t array_pos_;
-
- int32_t next_pos_;
-
- int32_t char_pos_;
-
- int32_t char_;
- DISALLOW_COPY_AND_ASSIGN(UTF8CharIterator);
- };
- class BASE_I18N_EXPORT UTF16CharIterator {
- public:
-
- explicit UTF16CharIterator(const string16* str);
- UTF16CharIterator(const char16* str, size_t str_len);
- UTF16CharIterator(UTF16CharIterator&& to_move);
- ~UTF16CharIterator();
- UTF16CharIterator& operator=(UTF16CharIterator&& to_move);
-
-
-
- static UTF16CharIterator LowerBound(const string16* str, size_t array_index);
- static UTF16CharIterator LowerBound(const char16* str,
- size_t str_len,
- size_t array_index);
-
-
-
- static UTF16CharIterator UpperBound(const string16* str, size_t array_index);
- static UTF16CharIterator UpperBound(const char16* str,
- size_t str_len,
- size_t array_index);
-
-
- int32_t array_pos() const { return array_pos_; }
-
-
-
- int32_t char_offset() const { return char_offset_; }
-
- int32_t get() const { return char_; }
-
-
-
-
- int32_t NextCodePoint() const;
-
-
-
- int32_t PreviousCodePoint() const;
-
- bool start() const { return array_pos_ == 0; }
-
- bool end() const { return array_pos_ == len_; }
-
-
- bool Advance();
-
-
- bool Rewind();
- private:
- UTF16CharIterator(const string16* str, int32_t initial_pos);
- UTF16CharIterator(const char16* str, size_t str_len, int32_t initial_pos);
-
-
- void ReadChar();
-
- const char16* str_;
-
- int32_t len_;
-
- int32_t array_pos_;
-
- int32_t next_pos_;
-
- int32_t char_offset_;
-
- int32_t char_;
- DISALLOW_COPY_AND_ASSIGN(UTF16CharIterator);
- };
- }
- }
- #endif
|