#include <marlo/utf8.hpp>
#include <iostream>
int main()
{
std::string s = "ça marche 😎 🚀";
std::size_t i = 0;
std::size_t oldi = 0;
std::uint32_t code = 0;
while (marlo::utf8::next_char(s, i, code)) {
auto bytes = i - oldi; // 1, 2, 3 or 4
std::cout << "U+" << std::hex << code << ", " << std::dec << bytes;
std::cout << (bytes > 1 ? " bytes" : " byte") << " long" << '\n';
oldi = i;
}
bool valid = code != marlo::utf8::bad_char;
std::cout << "that is " << (valid ? "a valid" : "an invalid") << " utf-8 string" << '\n';
if (!valid) {
std::cout << "error starts at index " << oldi << '\n';
}
return 0;
}
-
Notifications
You must be signed in to change notification settings - Fork 0
UTF-8 encoder/decoder for C++17
License
bmarlo/utf-8
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
UTF-8 encoder/decoder for C++17
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published