Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utf8iterator.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_UTF8ITERATOR_H_
19 #define ION_BASE_UTF8ITERATOR_H_
20 
21 #include <string>
22 
23 #include "base/integral_types.h"
24 
25 namespace ion {
26 namespace base {
27 
49 class ION_API Utf8Iterator {
50  public:
52  enum State {
53  kInString, // Still iterating over characters.
54  kEndOfString, // Hit the end of the string.
55  kInvalid, // Hit an invalid UTF-8 sequence.
56  };
57 
59  static const uint32 kInvalidCharIndex;
60 
62  explicit Utf8Iterator(const std::string& utf8_string);
63 
67  uint32 Next();
68 
72  State GetState() const { return state_; }
73 
77  size_t ComputeCharCount() const;
78 
79  private:
83  uint8 GetNextByte();
84 
87  const std::string string_;
89  const size_t byte_count_;
91  size_t cur_index_;
93  State state_;
94 };
95 
96 } // namespace base
97 } // namespace ion
98 
99 #endif // ION_BASE_UTF8ITERATOR_H_
static const uint32 kInvalidCharIndex
An invalid Unicode character index.
Definition: utf8iterator.h:59
State
Iterator states.
Definition: utf8iterator.h:52
The Utf8Iterator class iterates over characters in strings encoded with UTF-8, extracting the Unicode...
Definition: utf8iterator.h:49
State GetState() const
Returns the state of the iterator.
Definition: utf8iterator.h:72