u5e
UnicodeTextC++Library
simple_iteration.cpp
1 /**
2  * \page simple_iteration Example: Iterate over codepoints in utf8 text
3  *
4  * This example covers the basic usage of iterating over utf8 text
5  * codepoint by codepoint.
6  *
7  * \code
8  */// Example on how to iterate
9 
10 #include <experimental/string_view>
11 #include <u5e/utf8_string_view.hpp>
12 #include <stdio.h>
13 
14 using std::experimental::string_view;
15 
16 int main(int argc, char **argv) {
17  // for each argument
18  for (int i = 1; i < argc; i++) {
19 
20  // get a string_view
21  string_view p(argv[i], strlen(argv[i]));
22 
23  // get a utf8_string_view::const_iteator
24  u5e::utf8_string_view::const_iterator it = p.begin();
25 
26  // Iterate until the end
27  while (it != p.end()) {
28 
29  // the value dereferenced is the codepoint, not octets even if
30  // the original text had "wide" chars.
31  printf(" U+%06llx ", (long long unsigned int)*it++);
32 
33  }
34 
35  printf("\n");
36  }
37  return 0;
38 }
39 /**
40  * \endcode
41  */
main u5e namespace
utf8_const_iterator operator++(int junk)
basic_encodedstring< utf8, std::experimental::string_view > utf8_string_view
A basic_encodedstring of utf8 and string_view.
bool operator!=(const utf8_const_iterator &rhs) const
const codepoint operator*()