ui::CodePoints¶
Header: winui/core/Utf8.hpp.
The code points of a UTF-8 string, for a range-for: for (char32_t cp : code_points(text)).
A non-owning view: the string must outlive it. Malformed sequences yield U+FFFD, one per sequence. The iterator's offset() gives the byte position of each code point, which is what every text API in the framework takes.
Example:
const std::string text = "Hello, world";
std::size_t letters = 0;
for (char32_t cp : ui::code_points(text))
{
letters += (cp >= U'a' && cp <= U'z') ? 1 : 0;
}
// offset() is the byte position the text APIs take: cut the string at the first comma.
std::string greeting = text;
const ui::CodePoints points = ui::code_points(text);
for (auto it = points.begin(); it != points.end(); ++it)
{
if (*it == U',')
{
greeting = text.substr(0, it.offset()); // "Hello"
break;
}
}
CodePoints¶
A view over text, which must outlive it.
begin¶
The first code point.
end¶
One past the last code point (byte offset text.size()).
class iterator¶
Forward iterator over the code points; compares by byte offset only.
value_type¶
Dereferencing yields a decoded code point by value.
difference_type¶
Required by std::weakly_incrementable; distances are not meaningful here.
iterator¶
A singular iterator; only assignable.
iterator¶
Positioned at byte pos of text, which must be a code-point boundary.
operator*¶
The code point at the current position (U+FFFD if malformed).
operator++¶
Advances past the current code point.
operator++¶
Post-increment.
offset¶
The byte offset of the current code point.
operator==¶
Same byte offset; only meaningful between iterators over the same text.