reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofUTF8Iterator Class Reference

Iterate through each Unicode codepoint in a UTF8-encoded std::string. More...

#include <ofUtils.h>

Public Member Functions

 ofUTF8Iterator (const std::string &str)
 Create a ofUTF8Iterator for a given UTF8-encoded string.
 
utf8::iterator< std::string::const_iterator > begin () const
 
utf8::iterator< std::string::const_iterator > end () const
 
utf8::iterator< std::string::const_reverse_iterator > rbegin () const
 
utf8::iterator< std::string::const_reverse_iterator > rend () const
 

Detailed Description

Iterate through each Unicode codepoint in a UTF8-encoded std::string.

For UTF8-encoded strings each Unicode codepoint is comprised of between one and four bytes. Thus to access individual Unicode codepoints, we must step through a std::string in a UTF8-aware way.

The easiest way to use it is with a C++11 range style for loop like:

for(uint32_t codePoint: ofUTF8Iterator(str)){
// ...
}
Iterate through each Unicode codepoint in a UTF8-encoded std::string.
Definition ofUtils.h:1114

which will iterate through all the utf8 codepoints in the string.

If the passed UTF8-encoded std::string is invalid, the iterator yield 0 elements e.g.:

std::string invalidUTF8String = "...";
ofLog() << (ofUTF8Iterator(invalidUTF8String).begin() == ofUTF8Iterator(invalidUTF8String).end()); // Returns true.
A C++ stream-style logging interface.
Definition ofLog.h:299
utf8::iterator< std::string::const_iterator > begin() const
Definition ofUtils.cpp:723
utf8::iterator< std::string::const_iterator > end() const
Definition ofUtils.cpp:732

Constructor & Destructor Documentation

◆ ofUTF8Iterator()

ofUTF8Iterator::ofUTF8Iterator ( const std::string &  str)

Create a ofUTF8Iterator for a given UTF8-encoded string.

Parameters
strA UTF8-encoded string to iterate through.

Member Function Documentation

◆ begin()

utf8::iterator< std::string::const_iterator > ofUTF8Iterator::begin ( ) const
Returns
A forward iterator that points to the first codepoint in the UTF8 string.

◆ end()

utf8::iterator< std::string::const_iterator > ofUTF8Iterator::end ( ) const
Returns
An forward iterator that points to the end of the UTF8 string.

◆ rbegin()

utf8::iterator< std::string::const_reverse_iterator > ofUTF8Iterator::rbegin ( ) const
Returns
An reverse iterator that points to the last codepoint in the UTF8 string.

◆ rend()

utf8::iterator< std::string::const_reverse_iterator > ofUTF8Iterator::rend ( ) const
Returns
An reverse iterator that points to the reverse end of the UTF8 string.

The documentation for this class was generated from the following files:
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/utils/ofUtils.h
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/utils/ofUtils.cpp