{"id":13418941,"url":"https://github.com/nemtrif/utfcpp","last_synced_at":"2025-05-13T20:10:10.007Z","repository":{"id":36464731,"uuid":"40769974","full_name":"nemtrif/utfcpp","owner":"nemtrif","description":"UTF-8 with C++ in a Portable Way","archived":false,"fork":false,"pushed_at":"2025-01-11T16:10:42.000Z","size":177,"stargazers_count":1685,"open_issues_count":0,"forks_count":211,"subscribers_count":52,"default_branch":"master","last_synced_at":"2025-04-28T10:57:34.123Z","etag":null,"topics":["cpp","cpp98","header-only","internationalization","portable","text","unicode","utf-16","utf-8"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nemtrif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-15T16:11:54.000Z","updated_at":"2025-04-28T08:38:43.000Z","dependencies_parsed_at":"2023-10-01T19:17:52.077Z","dependency_job_id":"98777bf5-bc54-4bdb-8925-178b167af419","html_url":"https://github.com/nemtrif/utfcpp","commit_stats":{"total_commits":95,"total_committers":25,"mean_commits":3.8,"dds":0.3157894736842105,"last_synced_commit":"6be08bbea14ffa0a5c594257fb6285a054395cd7"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtrif%2Futfcpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtrif%2Futfcpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtrif%2Futfcpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nemtrif%2Futfcpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nemtrif","download_url":"https://codeload.github.com/nemtrif/utfcpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020606,"owners_count":22000753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp98","header-only","internationalization","portable","text","unicode","utf-16","utf-8"],"created_at":"2024-07-30T22:01:09.144Z","updated_at":"2025-05-13T20:10:09.967Z","avatar_url":"https://github.com/nemtrif.png","language":"C++","funding_links":[],"categories":["C++","TODO scan for Android support in followings"],"sub_categories":[],"readme":"\n\u003c!-- TOC --\u003e\u003ca name=\"utf8-cpp-utf-8-with-c-in-a-portable-way\"\u003e\u003c/a\u003e\n# UTF8-CPP: UTF-8 with C++ in a Portable Way\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"introduction\"\u003e\u003c/a\u003e\n## Introduction\n\nC++ developers still miss an easy and portable way of handling Unicode encoded strings. The original C++ standard (known as C++98 or C++03) is Unicode agnostic. Some progress has been made in the later editions of the standard, but it is still hard to work with Unicode using only the standard facilities.\n\nI came up with a small, C++98 compatible generic library in order to handle UTF-8 encoded strings. For anybody used to work with STL algorithms and iterators, it should be easy and natural to use. The code is freely available for any purpose - check out the [license](./LICENSE). The library has been used a lot since the first release in 2006 both in commercial and open-source projects and proved to be stable and useful.\n\n## Table of Contents\n\n- [UTF8-CPP: UTF-8 with C++ in a Portable Way](#utf8-cpp-utf-8-with-c-in-a-portable-way)\n   * [Introduction](#introduction)\n   * [Installation](#installation)\n   * [Examples of use](#examples-of-use)\n      + [Introductory Sample](#introductory-sample)\n      + [Checking if a file contains valid UTF-8 text](#checking-if-a-file-contains-valid-utf-8-text)\n      + [Ensure that a string contains valid UTF-8 text](#ensure-that-a-string-contains-valid-utf-8-text)\n   * [Points of interest](#points-of-interest)\n         - [Design goals and decisions](#design-goals-and-decisions)\n         - [Alternatives](#alternatives)\n   * [Reference](#reference)\n      + [Functions From utf8 Namespace](#functions-from-utf8-namespace)\n         - [utf8::append](#utf8append)\n            * [octet_iterator append(utfchar32_t cp, octet_iterator result)](#octet_iterator-appendutfchar32_t-cp-octet_iterator-result)\n            * [void append(utfchar32_t cp, std::string\u0026 s);](#void-appendutfchar32_t-cp-stdstring-s)\n         - [utf8::append16](#utf8append16)\n            * [word_iterator append16(utfchar32_t cp, word_iterator result)](#word_iterator-append16utfchar32_t-cp-word_iterator-result)\n            * [void append(utfchar32_t cp, std::u16string\u0026 s)](#void-appendutfchar32_t-cp-stdu16string-s)\n         - [utf8::next](#utf8next)\n         - [utf8::next16](#utf8next16)\n         - [utf8::peek_next](#utf8peek_next)\n         - [utf8::prior](#utf8prior)\n         - [utf8::advance](#utf8advance)\n         - [utf8::distance](#utf8distance)\n         - [utf8::utf16to8](#utf8utf16to8)\n            * [octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)](#octet_iterator-utf16to8-u16bit_iterator-start-u16bit_iterator-end-octet_iterator-result)\n            * [std::string utf16to8(const std::u16string\u0026 s)](#stdstring-utf16to8const-stdu16string-s)\n            * [std::string utf16to8(std::u16string_view s)](#stdstring-utf16to8stdu16string_view-s)\n         - [utf8::utf16tou8](#utf8utf16tou8)\n            * [std::u8string utf16tou8(const std::u16string\u0026 s)](#stdu8string-utf16tou8const-stdu16string-s)\n            * [std::u8string utf16tou8(const std::u16string_view\u0026 s)](#stdu8string-utf16tou8const-stdu16string_view-s)\n         - [utf8::utf8to16](#utf8utf8to16)\n            * [u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)](#u16bit_iterator-utf8to16-octet_iterator-start-octet_iterator-end-u16bit_iterator-result)\n            * [std::u16string utf8to16(const std::string\u0026 s)](#stdu16string-utf8to16const-stdstring-s)\n            * [std::u16string utf8to16(std::string_view s)](#stdu16string-utf8to16stdstring_view-s)\n            * [std::u16string utf8to16(std::u8string\u0026 s)](#stdu16string-utf8to16stdu8string-s)\n            * [std::u16string utf8to16(std::u8string_view\u0026 s)](#stdu16string-utf8to16stdu8string_view-s)\n         - [utf8::utf32to8](#utf8utf32to8)\n            * [octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)](#octet_iterator-utf32to8-u32bit_iterator-start-u32bit_iterator-end-octet_iterator-result)\n            * [std::string utf32to8(const std::u32string\u0026 s)](#stdstring-utf32to8const-stdu32string-s)\n            * [std::u8string utf32to8(const std::u32string\u0026 s)](#stdu8string-utf32to8const-stdu32string-s)\n            * [std::u8string utf32to8(const std::u32string_view\u0026 s)](#stdu8string-utf32to8const-stdu32string_view-s)\n            * [std::string utf32to8(const std::u32string\u0026 s)](#stdstring-utf32to8const-stdu32string-s-1)\n            * [std::string utf32to8(std::u32string_view s)](#stdstring-utf32to8stdu32string_view-s)\n         - [utf8::utf8to32](#utf8utf8to32)\n            * [u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)](#u32bit_iterator-utf8to32-octet_iterator-start-octet_iterator-end-u32bit_iterator-result)\n            * [std::u32string utf8to32(const std::u8string\u0026 s)](#stdu32string-utf8to32const-stdu8string-s)\n            * [std::u32string utf8to32(const std::u8string_view\u0026 s)](#stdu32string-utf8to32const-stdu8string_view-s)\n            * [std::u32string utf8to32(const std::string\u0026 s)](#stdu32string-utf8to32const-stdstring-s)\n            * [std::u32string utf8to32(std::string_view s)](#stdu32string-utf8to32stdstring_view-s)\n         - [utf8::find_invalid](#utf8find_invalid)\n            * [octet_iterator find_invalid(octet_iterator start, octet_iterator end)](#octet_iterator-find_invalidoctet_iterator-start-octet_iterator-end)\n            * [const char* find_invalid(const char* str)](#const-char-find_invalidconst-char-str)\n            * [std::size_t find_invalid(const std::string\u0026 s)](#stdsize_t-find_invalidconst-stdstring-s)\n            * [std::size_t find_invalid(std::string_view s)](#stdsize_t-find_invalidstdstring_view-s)\n         - [utf8::is_valid](#utf8is_valid)\n            * [bool is_valid(octet_iterator start, octet_iterator end)](#bool-is_validoctet_iterator-start-octet_iterator-end)\n            * [bool is_valid(const char* str)](#bool-is_validconst-char-str)\n            * [bool is_valid(const std::string\u0026 s)](#bool-is_validconst-stdstring-s)\n            * [bool is_valid(std::string_view s)](#bool-is_validstdstring_view-s)\n         - [utf8::replace_invalid](#utf8replace_invalid)\n            * [output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement)](#output_iterator-replace_invalidoctet_iterator-start-octet_iterator-end-output_iterator-out-utfchar32_t-replacement)\n            * [std::string replace_invalid(const std::string\u0026 s, utfchar32_t replacement)](#stdstring-replace_invalidconst-stdstring-s-utfchar32_t-replacement)\n            * [std::string replace_invalid(std::string_view s, char32_t replacement)](#stdstring-replace_invalidstdstring_view-s-char32_t-replacement)\n         - [utf8::starts_with_bom](#utf8starts_with_bom)\n            * [bool starts_with_bom (octet_iterator it, octet_iterator end)](#bool-starts_with_bom-octet_iterator-it-octet_iterator-end)\n            * [bool starts_with_bom(const std::string\u0026 s)](#bool-starts_with_bomconst-stdstring-s)\n            * [bool starts_with_bom(std::string_view s)](#bool-starts_with_bomstdstring_view-s)\n      + [Types From utf8 Namespace](#types-from-utf8-namespace)\n         - [utf8::exception](#utf8exception)\n         - [utf8::invalid_code_point](#utf8invalid_code_point)\n         - [utf8::invalid_utf8](#utf8invalid_utf8)\n         - [utf8::invalid_utf16](#utf8invalid_utf16)\n         - [utf8::not_enough_room](#utf8not_enough_room)\n         - [utf8::iterator](#utf8iterator)\n            * [Member functions](#member-functions)\n      + [Functions From utf8::unchecked Namespace](#functions-from-utf8unchecked-namespace)\n         - [utf8::unchecked::append](#utf8uncheckedappend)\n         - [utf8::unchecked::append16](#utf8uncheckedappend16)\n         - [utf8::unchecked::next](#utf8uncheckednext)\n         - [utf8::next16](#utf8next16-1)\n         - [utf8::unchecked::peek_next](#utf8uncheckedpeek_next)\n         - [utf8::unchecked::prior](#utf8uncheckedprior)\n         - [utf8::unchecked::advance](#utf8uncheckedadvance)\n         - [utf8::unchecked::distance](#utf8uncheckeddistance)\n         - [utf8::unchecked::utf16to8](#utf8uncheckedutf16to8)\n         - [utf8::unchecked::utf8to16](#utf8uncheckedutf8to16)\n         - [utf8::unchecked::utf32to8](#utf8uncheckedutf32to8)\n         - [utf8::unchecked::utf8to32](#utf8uncheckedutf8to32)\n         - [utf8::unchecked::replace_invalid](#utf8uncheckedreplace_invalid)\n      + [Types From utf8::unchecked Namespace](#types-from-utf8unchecked-namespace)\n         - [utf8::iterator](#utf8iterator-1)\n            * [Member functions](#member-functions-1)\n\n\u003c!-- TOC end --\u003e\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\n\nThis is a header-only library and the supported way of deploying it is:\n- Download a release from https://github.com/nemtrif/utfcpp/releases into a temporary directory\n- Unzip the release\n- Copy the content of utfcpp/source file into the directory where you keep include files for your project\n\n\nThe CMakeList.txt file was originally made for testing purposes only, but unfortunately over time I accepted contributions that added install target. *This is not a supported way of installing the utfcpp library* and I am considering removing the CMakeList.txt in a future release.\n\n\u003c!-- TOC --\u003e\u003ca name=\"examples-of-use\"\u003e\u003c/a\u003e\n## Examples of use\n\n\u003c!-- TOC --\u003e\u003ca name=\"introductory-sample\"\u003e\u003c/a\u003e\n### Introductory Sample\n\nTo illustrate the use of the library, let's start with a small but complete program that opens a file containing UTF-8 encoded text, reads it line by line, checks each line for invalid UTF-8 byte sequences, and converts it to UTF-16 encoding and back to UTF-8:\n\n```cpp\n#include \u003cfstream\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cvector\u003e\n#include \"utf8.h\"\nusing namespace std;\nint main(int argc, char** argv)\n{\n    if (argc != 2) {\n        cout \u003c\u003c \"\\nUsage: docsample filename\\n\";\n        return 0;\n    }\n    const char* test_file_path = argv[1];\n    // Open the test file (must be UTF-8 encoded)\n    ifstream fs8(test_file_path);\n    if (!fs8.is_open()) {\n        cout \u003c\u003c \"Could not open \" \u003c\u003c test_file_path \u003c\u003c endl;\n        return 0;\n    }\n\n    unsigned line_count = 1;\n    string line;\n    // Play with all the lines in the file\n    while (getline(fs8, line)) {\n        // check for invalid utf-8 (for a simple yes/no check, there is also utf8::is_valid function)\n#if __cplusplus \u003e= 201103L // C++ 11 or later\n        auto end_it = utf8::find_invalid(line.begin(), line.end());\n#else\n        string::iterator end_it = utf8::find_invalid(line.begin(), line.end());\n#endif // C++ 11\n        if (end_it != line.end()) {\n            cout \u003c\u003c \"Invalid UTF-8 encoding detected at line \" \u003c\u003c line_count \u003c\u003c \"\\n\";\n            cout \u003c\u003c \"This part is fine: \" \u003c\u003c string(line.begin(), end_it) \u003c\u003c \"\\n\";\n        }\n        // Get the line length (at least for the valid part)\n        int length = utf8::distance(line.begin(), end_it);\n        cout \u003c\u003c \"Length of line \" \u003c\u003c line_count \u003c\u003c \" is \" \u003c\u003c length \u003c\u003c  \"\\n\";\n\n        // Convert it to utf-16\n#if __cplusplus \u003e= 201103L // C++ 11 or later\n        u16string utf16line = utf8::utf8to16(line);\n#else\n        vector\u003cunsigned short\u003e utf16line;\n        utf8::utf8to16(line.begin(), end_it, back_inserter(utf16line));\n#endif // C++ 11\n        // And back to utf-8;\n#if __cplusplus \u003e= 201103L // C++ 11 or later\n        string utf8line = utf8::utf16to8(utf16line);\n#else\n        string utf8line; \n        utf8::utf16to8(utf16line.begin(), utf16line.end(), back_inserter(utf8line));\n#endif // C++ 11\n        // Confirm that the conversion went OK:\n        if (utf8line != string(line.begin(), end_it))\n            cout \u003c\u003c \"Error in UTF-16 conversion at line: \" \u003c\u003c line_count \u003c\u003c \"\\n\";        \n\n        line_count++;\n    } \n\n    return 0;\n}\n```\n\nIn the previous code sample, for each line we performed a detection of invalid UTF-8 sequences with `find_invalid`; the number of characters (more precisely - the number of Unicode code points, including the end of line and even BOM if there is one) in each line was determined with a use of `utf8::distance`; finally, we have converted each line to UTF-16 encoding with `utf8to16` and back to UTF-8 with `utf16to8`.\n\nNote a different pattern of usage for old compilers. For instance, this is how we convert\na UTF-8 encoded string to a UTF-16 encoded one with a pre - C++11 compiler:\n```cpp\n    vector\u003cunsigned short\u003e utf16line;\n    utf8::utf8to16(line.begin(), end_it, back_inserter(utf16line));\n```\n\nWith a more modern compiler, the same operation would look like:\n```cpp\n    u16string utf16line = utf8::utf8to16(line);\n```\nIf `__cplusplus` macro points to a C++ 11 or later, the library exposes API that takes into \naccount C++ standard Unicode strings and move semantics. With an older compiler, it is still\npossible to use the same functionality, just in a little less convenient way\n\nIn case you do not trust the `__cplusplus` macro or, for instance, do not want to include\nthe C++ 11 helper functions even with a modern compiler, define `UTF_CPP_CPLUSPLUS` macro\nbefore including `utf8.h` and assign it a value for the standard you want to use - the values are the same as for the `__cplusplus` macro. This can be also useful with compilers that are conservative in setting the `__cplusplus` macro even if they have a good support for a recent standard edition - Microsoft's Visual C++ is one example.\n\n\u003c!-- TOC --\u003e\u003ca name=\"checking-if-a-file-contains-valid-utf-8-text\"\u003e\u003c/a\u003e\n### Checking if a file contains valid UTF-8 text\n\nHere is a function that checks whether the content of a file is valid UTF-8 encoded text without reading the content into the memory:\n\n```cpp\nbool valid_utf8_file(const char* file_name)\n{\n    ifstream ifs(file_name);\n    if (!ifs)\n        return false; // even better, throw here\n\n    istreambuf_iterator\u003cchar\u003e it(ifs.rdbuf());\n    istreambuf_iterator\u003cchar\u003e eos;\n\n    return utf8::is_valid(it, eos);\n}\n```\n\nBecause the function `utf8::is_valid()` works with input iterators, we were able to pass an `istreambuf_iterator` to `it` and read the content of the file directly without loading it to the memory first.\n\nNote that other functions that take input iterator arguments can be used in a similar way. For instance, to read the content of a UTF-8 encoded text file and convert the text to UTF-16, just do something like:\n\n```cpp\n    utf8::utf8to16(it, eos, back_inserter(u16string));\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"ensure-that-a-string-contains-valid-utf-8-text\"\u003e\u003c/a\u003e\n### Ensure that a string contains valid UTF-8 text\n\nIf we have some text that \"probably\" contains UTF-8 encoded text and we want to replace any invalid UTF-8 sequence with a replacement character, something like the following function may be used:\n\n```cpp\nvoid fix_utf8_string(std::string\u0026 str)\n{\n    std::string temp;\n    utf8::replace_invalid(str.begin(), str.end(), back_inserter(temp));\n    str = temp;\n}\n```\n\nThe function will replace any invalid UTF-8 sequence with a Unicode replacement character. There is an overloaded function that enables the caller to supply their own replacement character.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"points-of-interest\"\u003e\u003c/a\u003e\n## Points of interest\n\n\u003c!-- TOC --\u003e\u003ca name=\"design-goals-and-decisions\"\u003e\u003c/a\u003e\n#### Design goals and decisions\n\nThe library was designed to be:\n\n1.  Generic: for better or worse, there are many C++ string classes out there, and the library should work with as many of them as possible.\n2.  Portable: the library should be portable both across different platforms and compilers. The only non-portable code is a small section that declares unsigned integers of different sizes: three typedefs. They can be changed by the users of the library if they don't match their platform. The default setting should work for Windows (both 32 and 64 bit), and most 32 bit and 64 bit Unix derivatives. Support for post C++03 language features is included for modern compilers at API level only, so the library should work even with pretty old compilers.\n3.  Lightweight: follow the \"pay only for what you use\" guideline.\n4.  Unintrusive: avoid forcing any particular design or even programming style on the user. This is a library, not a framework.\n\n\u003c!-- TOC --\u003e\u003ca name=\"alternatives\"\u003e\u003c/a\u003e\n#### Alternatives\n\nFor alternatives and comparisons, I recommend the following article: [The Wonderfully Terrible World of C and C++ Encoding APIs (with Some Rust)](https://thephd.dev/the-c-c++-rust-string-text-encoding-api-landscape), by JeanHeyd Meneide. In the article, this library is compared with:\n\n- [simdutf](https://github.com/simdutf/simdutf)\n- [iconv](https://www.gnu.org/software/libiconv/)\n- [boost.text](https://github.com/tzlaine/text)\n- [ICU](https://unicode-org.github.io/icu/userguide/conversion/converters.html)\n- [encoding_rs](https://github.com/hsivonen/encoding_rs)\n- [Windows API functions for converting text between encodings](https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/)\n- [ztd.text](https://github.com/soasis/text/)\n\nThe article presents author's view of the quality of the API design, but also some speed benchmarks.\n\n\u003c!-- TOC --\u003e\u003ca name=\"reference\"\u003e\u003c/a\u003e\n## Reference\n\n\u003c!-- TOC --\u003e\u003ca name=\"functions-from-utf8-namespace\"\u003e\u003c/a\u003e\n### Functions From utf8 Namespace\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8append\"\u003e\u003c/a\u003e\n#### utf8::append\n\n\u003c!-- TOC --\u003e\u003ca name=\"octet_iterator-appendutfchar32_t-cp-octet_iterator-result\"\u003e\u003c/a\u003e\n##### octet_iterator append(utfchar32_t cp, octet_iterator result)\n\nAvailable in version 1.0 and later.\n\nEncodes a 32 bit code point as a UTF-8 sequence of octets and appends the sequence to a UTF-8 string.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\noctet_iterator append(utfchar32_t cp, octet_iterator result);\n```\n\n`octet_iterator`: an output iterator.  \n`cp`: a 32 bit integer representing a code point to append to the sequence.  \n`result`: an output iterator to the place in the sequence where to append the code point.  \nReturn value: an iterator pointing to the place after the newly appended sequence.\n\nExample of use:\n\n```cpp\nunsigned char u[5] = {0,0,0,0,0};\nunsigned char* end = append(0x0448, u);\nassert (u[0] == 0xd1 \u0026\u0026 u[1] == 0x88 \u0026\u0026 u[2] == 0 \u0026\u0026 u[3] == 0 \u0026\u0026 u[4] == 0);\n```\n\nNote that `append` does not allocate any memory - it is the burden of the caller to make sure there is enough memory allocated for the operation. To make things more interesting, `append` can add anywhere between 1 and 4 octets to the sequence. In practice, you would most often want to use `std::back_inserter` to ensure that the necessary memory is allocated.\n\nIn case of an invalid code point, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"void-appendutfchar32_t-cp-stdstring-s\"\u003e\u003c/a\u003e\n##### void append(utfchar32_t cp, std::string\u0026 s);\n\nAvailable in version 3.0 and later. Prior to 4.0 it required a C++ 11 compiler; the requirement is lifted with 4.0.\n\nEncodes a 32 bit code point as a UTF-8 sequence of octets and appends the sequence to a UTF-8 string.\n\n```cpp\nvoid append(utfchar32_t cp, std::string\u0026 s);\n```\n\n`cp`: a code point to append to the string.  \n`s`: a utf-8 encoded string to append the code point to.  \n\nExample of use:\n\n```cpp\nstd::string u;\nappend(0x0448, u);\nassert (u[0] == char(0xd1) \u0026\u0026 u[1] == char(0x88) \u0026\u0026 u.length() == 2);\n```\n\nIn case of an invalid code point, a `utf8::invalid_code_point` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8append16\"\u003e\u003c/a\u003e\n#### utf8::append16\n\u003c!-- TOC --\u003e\u003ca name=\"word_iterator-append16utfchar32_t-cp-word_iterator-result\"\u003e\u003c/a\u003e\n##### word_iterator append16(utfchar32_t cp, word_iterator result)\n\nAvailable in version 4.0 and later.\n\nEncodes a 32 bit code point as a UTF-16 sequence of words and appends the sequence to a UTF-16 string.\n\n```cpp\ntemplate \u003ctypename word_iterator\u003e\nword_iterator append16(utfchar32_t cp, word_iterator result);\n```\n\n`word_iterator`: an output iterator.  \n`cp`: a 32 bit integer representing a code point to append to the sequence.  \n`result`: an output iterator to the place in the sequence where to append the code point.  \nReturn value: an iterator pointing to the place after the newly appended sequence.\n\nExample of use:\n\n```cpp\nunsigned short u[2] = {0,0};\nunsigned short* end = append16(0x0448, u);\nassert (u[0] == 0x0448 \u0026\u0026 u[1] == 0);\n```\n\nNote that `append16` does not allocate any memory - it is the burden of the caller to make sure there is enough memory allocated for the operation. To make things more interesting, `append16` can add either one or two words to the sequence. In practice, you would most often want to use `std::back_inserter` to ensure that the necessary memory is allocated.\n\nIn case of an invalid code point, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"void-appendutfchar32_t-cp-stdu16string-s\"\u003e\u003c/a\u003e\n##### void append(utfchar32_t cp, std::u16string\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++11 compliant compiler.\n\nEncodes a 32 bit code point as a UTF-16 sequence of words and appends the sequence to a UTF-16 string.\n\n```cpp\nvoid append(utfchar32_t cp, std::u16string\u0026 s);\n```\n\n`cp`: a code point to append to the string.  \n`s`: a utf-16 encoded string to append the code point to.  \n\nExample of use:\n\n```cpp\nstd::u16string u;\nappend(0x0448, u);\nassert (u[0] == 0x0448 \u0026\u0026 u.length() == 1);\n```\n\nIn case of an invalid code point, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8next\"\u003e\u003c/a\u003e\n#### utf8::next\n\nAvailable in version 1.0 and later.\n\nGiven the iterator to the beginning of the UTF-8 sequence, it returns the code point and moves the iterator to the next position.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \nutfchar32_t next(octet_iterator\u0026 it, octet_iterator end);\n```\n\n`octet_iterator`: an input iterator.  \n`it`: a reference to an iterator pointing to the beginning of an UTF-8 encoded code point. After the function returns, it is incremented to point to the beginning of the next code point.  \n`end`: end of the UTF-8 sequence to be processed. If `it` gets equal to `end` during the extraction of a code point, an `utf8::not_enough_room` exception is thrown.  \nReturn value: the 32 bit representation of the processed UTF-8 code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars;\nint cp = next(w, twochars + 6);\nassert (cp == 0x65e5);\nassert (w == twochars + 3);\n```\n\nThis function is typically used to iterate through a UTF-8 encoded string.\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8next16\"\u003e\u003c/a\u003e\n#### utf8::next16\n\nAvailable in version 4.0 and later.\n\nGiven the iterator to the beginning of the UTF-16 sequence, it returns the code point and moves the iterator to the next position.\n\n```cpp\ntemplate \u003ctypename word_iterator\u003e\nutfchar32_t next16(word_iterator\u0026 it, word_iterator end);\n```\n\n`word_iterator`: an input iterator.  \n`it`: a reference to an iterator pointing to the beginning of an UTF-16 encoded code point. After the function returns, it is incremented to point to the beginning of the next code point.  \n`end`: end of the UTF-16 sequence to be processed. If `it` gets equal to `end` during the extraction of a code point, an `utf8::not_enough_room` exception is thrown.  \nReturn value: the 32 bit representation of the processed UTF-16 code point.\n\nExample of use:\n\n```cpp\nconst unsigned short u[3] = {0x65e5, 0xd800, 0xdf46};\nconst unsigned short* w = u;\nint cp = next16(w, w + 3);\nassert (cp, 0x65e5);\nassert (w, u + 1);\n```\n\nThis function is typically used to iterate through a UTF-16 encoded string.\n\nIn case of an invalid UTF-16 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8peek_next\"\u003e\u003c/a\u003e\n#### utf8::peek_next\n\nAvailable in version 2.1 and later.\n\nGiven the iterator to the beginning of the UTF-8 sequence, it returns the code point for the following sequence without changing the value of the iterator.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \nutfchar32_t peek_next(octet_iterator it, octet_iterator end);\n```\n\n\n`octet_iterator`: an input iterator.  \n`it`: an iterator pointing to the beginning of an UTF-8 encoded code point.  \n`end`: end of the UTF-8 sequence to be processed. If `it` gets equal to `end` during the extraction of a code point, an `utf8::not_enough_room` exception is thrown.  \nReturn value: the 32 bit representation of the processed UTF-8 code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars;\nint cp = peek_next(w, twochars + 6);\nassert (cp == 0x65e5);\nassert (w == twochars);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8prior\"\u003e\u003c/a\u003e\n#### utf8::prior\n\nAvailable in version 1.02 and later.\n\nGiven a reference to an iterator pointing to an octet in a UTF-8 sequence, it decreases the iterator until it hits the beginning of the previous UTF-8 encoded code point and returns the 32 bits representation of the code point.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \nutfchar32_t prior(octet_iterator\u0026 it, octet_iterator start);\n```\n\n`octet_iterator`: a bidirectional iterator.  \n`it`: a reference pointing to an octet within a UTF-8 encoded string. After the function returns, it is decremented to point to the beginning of the previous code point.  \n`start`: an iterator to the beginning of the sequence where the search for the beginning of a code point is performed. It is a safety measure to prevent passing the beginning of the string in the search for a UTF-8 lead octet.  \n Return value: the 32 bit representation of the previous code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nunsigned char* w = twochars + 3;\nint cp = prior (w, twochars);\nassert (cp == 0x65e5);\nassert (w == twochars);\n```\n\nThis function has two purposes: one is two iterate backwards through a UTF-8 encoded string. Note that it is usually a better idea to iterate forward instead, since `utf8::next` is faster. The second purpose is to find a beginning of a UTF-8 sequence if we have a random position within a string. Note that in that case `utf8::prior` may not detect an invalid UTF-8 sequence in some scenarios: for instance if there are superfluous trail octets, it will just skip them.\n\n`it` will typically point to the beginning of a code point, and `start` will point to the beginning of the string to ensure we don't go backwards too far. `it` is decreased until it points to a lead UTF-8 octet, and then the UTF-8 sequence beginning with that octet is decoded to a 32 bit representation and returned.\n\nIn case `start` is reached before a UTF-8 lead octet is hit, or if an invalid UTF-8 sequence is started by the lead octet, an `invalid_utf8` exception is thrown.\n\nIn case `start` equals `it`, a `not_enough_room` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8advance\"\u003e\u003c/a\u003e\n#### utf8::advance\nAvailable in version 1.0 and later.\n\nAdvances an iterator by the specified number of code points within an UTF-8 sequence.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename distance_type\u003e \nvoid advance (octet_iterator\u0026 it, distance_type n, octet_iterator end);\n```\n\n`octet_iterator`: an input iterator.  \n`distance_type`: an integral type convertible to `octet_iterator`'s difference type.  \n`it`: a reference to an iterator pointing to the beginning of an UTF-8 encoded code point. After the function returns, it is incremented to point to the nth following code point.  \n`n`: number of code points `it` should be advanced. A negative value means decrement.  \n`end`: limit of the UTF-8 sequence to be processed. If `n` is positive and `it` gets equal to `end` during the extraction of a code point, an `utf8::not_enough_room` exception is thrown. If `n` is negative and `it` reaches `end` while `it` points t a trail byte of a UTF-8 sequence, a `utf8::invalid_code_point` exception is thrown.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nunsigned char* w = twochars;\nadvance (w, 2, twochars + 6);\nassert (w == twochars + 5);\nadvance (w, -2, twochars);\nassert (w == twochars);\n```\n\nIn case of an invalid code point, a `utf8::invalid_code_point` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8distance\"\u003e\u003c/a\u003e\n#### utf8::distance\n\nAvailable in version 1.0 and later.\n\nGiven the iterators to two UTF-8 encoded code points in a sequence, returns the number of code points between them.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \ntypename std::iterator_traits\u003coctet_iterator\u003e::difference_type distance (octet_iterator first, octet_iterator last);\n```\n\n`octet_iterator`: an input iterator.  \n`first`: an iterator to a beginning of a UTF-8 encoded code point.  \n`last`: an iterator to a \"post-end\" of the last UTF-8 encoded code point in the sequence we are trying to determine the length. It can be the beginning of a new code point, or not.  \n Return value the distance between the iterators, in code points.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nsize_t dist = utf8::distance(twochars, twochars + 5);\nassert (dist == 2);\n```\n\nThis function is used to find the length (in code points) of a UTF-8 encoded string. The reason it is called _distance_, rather than, say, _length_ is mainly because developers are used that _length_ is an O(1) function. Computing the length of an UTF-8 string is a linear operation, and it looked better to model it after `std::distance` algorithm.\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown. If `last` does not point to the past-of-end of a UTF-8 sequence, a `utf8::not_enough_room` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8utf16to8\"\u003e\u003c/a\u003e\n#### utf8::utf16to8\n\u003c!-- TOC --\u003e\u003ca name=\"octet_iterator-utf16to8-u16bit_iterator-start-u16bit_iterator-end-octet_iterator-result\"\u003e\u003c/a\u003e\n##### octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\ntemplate \u003ctypename u16bit_iterator, typename octet_iterator\u003e\noctet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result);\n```\n\n`u16bit_iterator`: an input iterator.  \n`octet_iterator`: an output iterator.  \n`start`: an iterator pointing to the beginning of the UTF-16 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-16 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-8 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-8 string.\n\nExample of use:\n\n```cpp\nunsigned short utf16string[] = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\nvector\u003cunsigned char\u003e utf8result;\nutf16to8(utf16string, utf16string + 5, back_inserter(utf8result));\nassert (utf8result.size() == 10);    \n```\n\nIn case of invalid UTF-16 sequence, a `utf8::invalid_utf16` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-utf16to8const-stdu16string-s\"\u003e\u003c/a\u003e\n##### std::string utf16to8(const std::u16string\u0026 s)\n\nAvailable in version 3.0 and later. Requires a C++ 11 compliant compiler.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\nstd::string utf16to8(const std::u16string\u0026 s);\n```\n\n`s`: a UTF-16 encoded string.\nReturn value: A UTF-8 encoded string.\n\nExample of use:\n\n```cpp\n    u16string utf16string = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\n    string u = utf16to8(utf16string);\n    assert (u.size() == 10);\n```\n\nIn case of invalid UTF-16 sequence, a `utf8::invalid_utf16` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-utf16to8stdu16string_view-s\"\u003e\u003c/a\u003e\n##### std::string utf16to8(std::u16string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\nstd::string utf16to8(std::u16string_view s);\n```\n\n`s`: a UTF-16 encoded string.\nReturn value: A UTF-8 encoded string.\n\nExample of use:\n\n```cpp\n    u16string utf16string = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\n    u16string_view utf16stringview(u16string);\n    string u = utf16to8(utf16string);\n    assert (u.size() == 10);\n```\n\nIn case of invalid UTF-16 sequence, a `utf8::invalid_utf16` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8utf16tou8\"\u003e\u003c/a\u003e\n#### utf8::utf16tou8\n\u003c!-- TOC --\u003e\u003ca name=\"stdu8string-utf16tou8const-stdu16string-s\"\u003e\u003c/a\u003e\n##### std::u8string utf16tou8(const std::u16string\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\nstd::u8string utf16tou8(const std::u16string\u0026 s);\n```\n\n`s`: a UTF-16 encoded string.\nReturn value: A UTF-8 encoded string.\n\nExample of use:\n\n```cpp\n    u16string utf16string = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\n    u8string u = utf16tou8(utf16string);\n    assert (u.size() == 10);\n```\n\nIn case of invalid UTF-16 sequence, a `utf8::invalid_utf16` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu8string-utf16tou8const-stdu16string_view-s\"\u003e\u003c/a\u003e\n##### std::u8string utf16tou8(const std::u16string_view\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\nstd::u8string utf16tou8(const std::u16string_view\u0026 s);\n```\n\n`s`: a UTF-16 encoded string.\nReturn value: A UTF-8 encoded string.\n\nExample of use:\n\n```cpp\n    u16string utf16string = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\n    u16string_view utf16stringview(u16string);\n    u8string u = utf16tou8(utf16string);\n    assert (u.size() == 10);\n```\n\nIn case of invalid UTF-16 sequence, a `utf8::invalid_utf16` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8utf8to16\"\u003e\u003c/a\u003e\n#### utf8::utf8to16\n\u003c!-- TOC --\u003e\u003ca name=\"u16bit_iterator-utf8to16-octet_iterator-start-octet_iterator-end-u16bit_iterator-result\"\u003e\u003c/a\u003e\n##### u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)\n\nAvailable in version 1.0 and later.\n\nConverts an UTF-8 encoded string to UTF-16\n\n```cpp\ntemplate \u003ctypename u16bit_iterator, typename octet_iterator\u003e\nu16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result);\n```\n\n`octet_iterator`: an input iterator.  \n`u16bit_iterator`: an output iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 encoded string to convert. \n`end`: an iterator pointing to pass-the-end of the UTF-8 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-16 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-16 string.\n\nExample of use:\n\n```cpp\nchar utf8_with_surrogates[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nvector \u003cunsigned short\u003e utf16result;\nutf8to16(utf8_with_surrogates, utf8_with_surrogates + 9, back_inserter(utf16result));\nassert (utf16result.size() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown. If `end` does not point to the past-of-end of a UTF-8 sequence, a `utf8::not_enough_room` exception is thrown.\n\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu16string-utf8to16const-stdstring-s\"\u003e\u003c/a\u003e\n##### std::u16string utf8to16(const std::string\u0026 s)\n\nAvailable in version 3.0 and later. Requires a C++ 11 compliant compiler.\n\nConverts an UTF-8 encoded string to UTF-16.\n\n```cpp\nstd::u16string utf8to16(const std::string\u0026 s);\n```\n\n`s`: an UTF-8 encoded string to convert.  \nReturn value: A UTF-16 encoded string\n\nExample of use:\n\n```cpp\nstring utf8_with_surrogates = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nu16string utf16result = utf8to16(utf8_with_surrogates);\nassert (utf16result.length() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu16string-utf8to16stdstring_view-s\"\u003e\u003c/a\u003e\n##### std::u16string utf8to16(std::string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nConverts an UTF-8 encoded string to UTF-16.\n\n```cpp\nstd::u16string utf8to16(std::string_view s);\n```\n\n`s`: an UTF-8 encoded string to convert.  \nReturn value: A UTF-16 encoded string\n\nExample of use:\n\n```cpp\nstring_view utf8_with_surrogates = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nu16string utf16result = utf8to16(utf8_with_surrogates);\nassert (utf16result.length() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu16string-utf8to16stdu8string-s\"\u003e\u003c/a\u003e\n##### std::u16string utf8to16(std::u8string\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts an UTF-8 encoded string to UTF-16.\n\n```cpp\nstd::u16string utf8to16(std::u8string\u0026 s);\n```\n\n`s`: an UTF-8 encoded string to convert.  \nReturn value: A UTF-16 encoded string\n\nExample of use:\n\n```cpp\nstd::u8string utf8_with_surrogates = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nstd::u16string utf16result = utf8to16(utf8_with_surrogates);\nassert (utf16result.length() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu16string-utf8to16stdu8string_view-s\"\u003e\u003c/a\u003e\n##### std::u16string utf8to16(std::u8string_view\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts an UTF-8 encoded string to UTF-16.\n\n```cpp\nstd::u16string utf8to16(std::u8string_view\u0026 s);\n```\n\n`s`: an UTF-8 encoded string to convert.  \nReturn value: A UTF-16 encoded string\n\nExample of use:\n\n```cpp\nstd::u8string utf8_with_surrogates = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nstd::u8string_view utf8stringview {utf8_with_surrogates}\nstd::u16string utf16result = utf8to16(utf8stringview);\nassert (utf16result.length() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8utf32to8\"\u003e\u003c/a\u003e\n#### utf8::utf32to8\n\u003c!-- TOC --\u003e\u003ca name=\"octet_iterator-utf32to8-u32bit_iterator-start-u32bit_iterator-end-octet_iterator-result\"\u003e\u003c/a\u003e\n##### octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename u32bit_iterator\u003e\noctet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result);\n```\n\n`octet_iterator`: an output iterator.  \n`u32bit_iterator`: an input iterator.  \n`start`: an iterator pointing to the beginning of the UTF-32 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-32 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-8 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-8 string.\n\nExample of use:\n\n```cpp\nint utf32string[] = {0x448, 0x65E5, 0x10346, 0};\nvector\u003cunsigned char\u003e utf8result;\nutf32to8(utf32string, utf32string + 3, back_inserter(utf8result));\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-utf32to8const-stdu32string-s\"\u003e\u003c/a\u003e\n##### std::string utf32to8(const std::u32string\u0026 s)\n\nAvailable in version 3.0 and later. Requires a C++ 11 compliant compiler.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\nstd::string utf32to8(const std::u32string\u0026 s);\n```\n\n`s`: a UTF-32 encoded string.  \nReturn value: a UTF-8 encoded string.\n\nExample of use:\n\n```cpp\nu32string utf32string = {0x448, 0x65E5, 0x10346};\nstring utf8result = utf32to8(utf32string);\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu8string-utf32to8const-stdu32string-s\"\u003e\u003c/a\u003e\n##### std::u8string utf32to8(const std::u32string\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\nstd::u8string utf32to8(const std::u32string\u0026 s);\n```\n\n`s`: a UTF-32 encoded string.  \nReturn value: a UTF-8 encoded string.\n\nExample of use:\n\n```cpp\nu32string utf32string = {0x448, 0x65E5, 0x10346};\nu8string utf8result = utf32to8(utf32string);\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu8string-utf32to8const-stdu32string_view-s\"\u003e\u003c/a\u003e\n##### std::u8string utf32to8(const std::u32string_view\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\nstd::u8string utf32to8(const std::u32string_view\u0026 s);\n```\n\n`s`: a UTF-32 encoded string.  \nReturn value: a UTF-8 encoded string.\n\nExample of use:\n\n```cpp\nu32string utf32string = {0x448, 0x65E5, 0x10346};\nu32string_view utf32stringview(utf32string);\nu8string utf8result = utf32to8(utf32stringview);\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-utf32to8const-stdu32string-s-1\"\u003e\u003c/a\u003e\n##### std::string utf32to8(const std::u32string\u0026 s)\n\nAvailable in version 3.0 and later. Requires a C++ 11 compliant compiler.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\nstd::string utf32to8(const std::u32string\u0026 s);\n```\n\n`s`: a UTF-32 encoded string.  \nReturn value: a UTF-8 encoded string.\n\nExample of use:\n\n```cpp\nu32string utf32string = {0x448, 0x65E5, 0x10346};\nstring utf8result = utf32to8(utf32string);\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-utf32to8stdu32string_view-s\"\u003e\u003c/a\u003e\n##### std::string utf32to8(std::u32string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\nstd::string utf32to8(std::u32string_view s);\n```\n\n`s`: a UTF-32 encoded string.  \nReturn value: a UTF-8 encoded string.\n\nExample of use:\n\n```cpp\nu32string utf32string = {0x448, 0x65E5, 0x10346};\nu32string_view utf32stringview(utf32string);\nstring utf8result = utf32to8(utf32stringview);\nassert (utf8result.size() == 9);\n```\n\nIn case of invalid UTF-32 string, a `utf8::invalid_code_point` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8utf8to32\"\u003e\u003c/a\u003e\n#### utf8::utf8to32\n\u003c!-- TOC --\u003e\u003ca name=\"u32bit_iterator-utf8to32-octet_iterator-start-octet_iterator-end-u32bit_iterator-result\"\u003e\u003c/a\u003e\n##### u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename u32bit_iterator\u003e\nu32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result);\n```\n\n`octet_iterator`: an input iterator.  \n`u32bit_iterator`: an output iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-32 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-32 string.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nvector\u003cint\u003e utf32result;\nutf8to32(twochars, twochars + 5, back_inserter(utf32result));\nassert (utf32result.size() == 2);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown. If `end` does not point to the past-of-end of a UTF-8 sequence, a `utf8::not_enough_room` exception is thrown.\n\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu32string-utf8to32const-stdu8string-s\"\u003e\u003c/a\u003e\n##### std::u32string utf8to32(const std::u8string\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\nstd::u32string utf8to32(const std::u8string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: a UTF-32 encoded string.\n\nExample of use:\n\n```cpp\nconst std::u8string* twochars = u8\"\\xe6\\x97\\xa5\\xd1\\x88\";\nu32string utf32result = utf8to32(twochars);\nassert (utf32result.size() == 2);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu32string-utf8to32const-stdu8string_view-s\"\u003e\u003c/a\u003e\n##### std::u32string utf8to32(const std::u8string_view\u0026 s)\n\nAvailable in version 4.0 and later. Requires a C++ 20 compliant compiler.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\nstd::u32string utf8to32(const std::u8string_view\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: a UTF-32 encoded string.\n\nExample of use:\n\n```cpp\nconst u8string* twochars = u8\"\\xe6\\x97\\xa5\\xd1\\x88\";\nconst u8string_view stringview{twochars};\nu32string utf32result = utf8to32(stringview);\nassert (utf32result.size() == 2);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu32string-utf8to32const-stdstring-s\"\u003e\u003c/a\u003e\n##### std::u32string utf8to32(const std::string\u0026 s)\n\nAvailable in version 3.0 and later. Requires a C++ 11 compliant compiler.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\nstd::u32string utf8to32(const std::string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: a UTF-32 encoded string.\n\nExample of use:\n\n```cpp\nconst char* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nu32string utf32result = utf8to32(twochars);\nassert (utf32result.size() == 2);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdu32string-utf8to32stdstring_view-s\"\u003e\u003c/a\u003e\n##### std::u32string utf8to32(std::string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\nstd::u32string utf8to32(std::string_view s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: a UTF-32 encoded string.\n\nExample of use:\n\n```cpp\nstring_view twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nu32string utf32result = utf8to32(twochars);\nassert (utf32result.size() == 2);\n```\n\nIn case of an invalid UTF-8 sequence, a `utf8::invalid_utf8` exception is thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8find_invalid\"\u003e\u003c/a\u003e\n#### utf8::find_invalid\n\u003c!-- TOC --\u003e\u003ca name=\"octet_iterator-find_invalidoctet_iterator-start-octet_iterator-end\"\u003e\u003c/a\u003e\n##### octet_iterator find_invalid(octet_iterator start, octet_iterator end)\n\nAvailable in version 1.0 and later.\n\nDetects an invalid sequence within a UTF-8 string.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \noctet_iterator find_invalid(octet_iterator start, octet_iterator end);\n```\n\n`octet_iterator`: an input iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 string to test for validity.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 string to test for validity.  \nReturn value: an iterator pointing to the first invalid octet in the UTF-8 string. In case none were found, equals `end`.\n\nExample of use:\n\n```cpp\nchar utf_invalid[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nchar* invalid = find_invalid(utf_invalid, utf_invalid + 6);\nassert (invalid == utf_invalid + 5);\n```\n\nThis function is typically used to make sure a UTF-8 string is valid before processing it with other functions. It is especially important to call it if before doing any of the _unchecked_ operations on it.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"const-char-find_invalidconst-char-str\"\u003e\u003c/a\u003e\n##### const char* find_invalid(const char* str)\n\nAvailable in version 4.0 and later.\n\nDetects an invalid sequence within a C-style UTF-8 string.\n\n```cpp\nconst char* find_invalid(const char* str);\n```\n\n`str`: a UTF-8 encoded string.\nReturn value: a pointer to the first invalid octet in the UTF-8 string. In case none were found, points to the trailing zero byte.\n\nExample of use:\n\n```cpp\nconst char* utf_invalid = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nconst char* invalid = find_invalid(utf_invalid);\nassert ((invalid - utf_invalid) == 5);\n```\n\nThis function is typically used to make sure a UTF-8 string is valid before processing it with other functions. It is especially important to call it if before doing any of the _unchecked_ operations on it.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdsize_t-find_invalidconst-stdstring-s\"\u003e\u003c/a\u003e\n##### std::size_t find_invalid(const std::string\u0026 s)\n\nAvailable in version 3.0 and later. Prior to 4.0 it required a C++ 11 compiler; the requirement is lifted with 4.0\n\nDetects an invalid sequence within a UTF-8 string.\n\n```cpp\nstd::size_t find_invalid(const std::string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: the index of the first invalid octet in the UTF-8 string. In case none were found, equals `std::string::npos`.\n\nExample of use:\n\n```cpp\nstring utf_invalid = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nauto invalid = find_invalid(utf_invalid);\nassert (invalid == 5);\n```\n\nThis function is typically used to make sure a UTF-8 string is valid before processing it with other functions. It is especially important to call it if before doing any of the _unchecked_ operations on it.\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdsize_t-find_invalidstdstring_view-s\"\u003e\u003c/a\u003e\n##### std::size_t find_invalid(std::string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nDetects an invalid sequence within a UTF-8 string.\n\n```cpp\nstd::size_t find_invalid(std::string_view s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: the index of the first invalid octet in the UTF-8 string. In case none were found, equals `std::string_view::npos`.\n\nExample of use:\n\n```cpp\nstring_view utf_invalid = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nauto invalid = find_invalid(utf_invalid);\nassert (invalid == 5);\n```\n\nThis function is typically used to make sure a UTF-8 string is valid before processing it with other functions. It is especially important to call it if before doing any of the _unchecked_ operations on it.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8is_valid\"\u003e\u003c/a\u003e\n#### utf8::is_valid\n\u003c!-- TOC --\u003e\u003ca name=\"bool-is_validoctet_iterator-start-octet_iterator-end\"\u003e\u003c/a\u003e\n##### bool is_valid(octet_iterator start, octet_iterator end)\n\nAvailable in version 1.0 and later.\n\nChecks whether a sequence of octets is a valid UTF-8 string.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \nbool is_valid(octet_iterator start, octet_iterator end);\n```\n\n`octet_iterator`: an input iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 string to test for validity.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 string to test for validity.  \nReturn value: `true` if the sequence is a valid UTF-8 string; `false` if not.\n\nExample of use:\n\n```cpp\nchar utf_invalid[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nbool bvalid = is_valid(utf_invalid, utf_invalid + 6);\nassert (bvalid == false);\n```\n\n`is_valid` is a shorthand for `find_invalid(start, end) == end;`. You may want to use it to make sure that a byte sequence is a valid UTF-8 string without the need to know where it fails if it is not valid.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"bool-is_validconst-char-str\"\u003e\u003c/a\u003e\n##### bool is_valid(const char* str)\n\nAvailable in version 4.0 and later.\n\nChecks whether a C-style string contains valid UTF-8 encoded text.\n\n```cpp\nbool is_valid(const char* str);\n```\n\n`str`: a UTF-8 encoded string.  \nReturn value: `true` if the string contains valid UTF-8 encoded text; `false` if not.\n\nExample of use:\n\n```cpp\nchar utf_invalid[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nbool bvalid = is_valid(utf_invalid);\nassert (bvalid == false);\n```\n\nYou may want to use `is_valid` to make sure that a string contains valid UTF-8 text without the need to know where it fails if it is not valid.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"bool-is_validconst-stdstring-s\"\u003e\u003c/a\u003e\n##### bool is_valid(const std::string\u0026 s)\n\nAvailable in version 3.0 and later. Prior to 4.0 it required a C++ 11 compiler; the requirement is lifted with 4.0\n\nChecks whether a string object contains valid UTF-8 encoded text.\n\n```cpp\nbool is_valid(const std::string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.  \nReturn value: `true` if the string contains valid UTF-8 encoded text; `false` if not.\n\nExample of use:\n\n```cpp\nchar utf_invalid[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nbool bvalid = is_valid(utf_invalid);\nassert (bvalid == false);\n```\n\nYou may want to use `is_valid` to make sure that a string contains valid UTF-8 text without the need to know where it fails if it is not valid.\n\n\u003c!-- TOC --\u003e\u003ca name=\"bool-is_validstdstring_view-s\"\u003e\u003c/a\u003e\n##### bool is_valid(std::string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nChecks whether a string object contains valid UTF-8 encoded text.\n\n```cpp\nbool is_valid(std::string_view s);\n```\n\n`s`: a UTF-8 encoded string.  \nReturn value: `true` if the string contains valid UTF-8 encoded text; `false` if not.\n\nExample of use:\n\n```cpp\nstring_view utf_invalid = \"\\xe6\\x97\\xa5\\xd1\\x88\\xfa\";\nbool bvalid = is_valid(utf_invalid);\nassert (bvalid == false);\n```\n\nYou may want to use `is_valid` to make sure that a string contains valid UTF-8 text without the need to know where it fails if it is not valid.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8replace_invalid\"\u003e\u003c/a\u003e\n#### utf8::replace_invalid\n\u003c!-- TOC --\u003e\u003ca name=\"output_iterator-replace_invalidoctet_iterator-start-octet_iterator-end-output_iterator-out-utfchar32_t-replacement\"\u003e\u003c/a\u003e\n##### output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement)\n\nAvailable in version 2.0 and later.\n\nReplaces all invalid UTF-8 sequences within a string with a replacement marker.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename output_iterator\u003e\noutput_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement);\ntemplate \u003ctypename octet_iterator, typename output_iterator\u003e\noutput_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out);\n```\n\n`octet_iterator`: an input iterator.  \n`output_iterator`: an output iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 string to look for invalid UTF-8 sequences.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 string to look for invalid UTF-8 sequences.  \n`out`: An output iterator to the range where the result of replacement is stored.  \n`replacement`: A Unicode code point for the replacement marker. The version without this parameter assumes the value `0xfffd`  \nReturn value: An iterator pointing to the place after the UTF-8 string with replaced invalid sequences.\n\nExample of use:\n\n```cpp\nchar invalid_sequence[] = \"a\\x80\\xe0\\xa0\\xc0\\xaf\\xed\\xa0\\x80z\";\nvector\u003cchar\u003e replace_invalid_result;\nreplace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), back_inserter(replace_invalid_result), '?');\nbvalid = is_valid(replace_invalid_result.begin(), replace_invalid_result.end());\nassert (bvalid);\nchar* fixed_invalid_sequence = \"a????z\";\nassert (std::equal(replace_invalid_result.begin(), replace_invalid_result.end(), fixed_invalid_sequence));\n```\n\n`replace_invalid` does not perform in-place replacement of invalid sequences. Rather, it produces a copy of the original string with the invalid sequences replaced with a replacement marker. Therefore, `out` must not be in the `[start, end]` range.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-replace_invalidconst-stdstring-s-utfchar32_t-replacement\"\u003e\u003c/a\u003e\n##### std::string replace_invalid(const std::string\u0026 s, utfchar32_t replacement)\n\nAvailable in version 3.0 and later. Prior to 4.0 it required a C++ 11 compiler; the requirement is lifted with 4.0\n\nReplaces all invalid UTF-8 sequences within a string with a replacement marker.\n\n```cpp\nstd::string replace_invalid(const std::string\u0026 s, utfchar32_t replacement);\nstd::string replace_invalid(const std::string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.  \n`replacement`: A Unicode code point for the replacement marker. The version without this parameter assumes the value `0xfffd`  \nReturn value: A UTF-8 encoded string with replaced invalid sequences.\n\nExample of use:\n\n```cpp\nstring invalid_sequence = \"a\\x80\\xe0\\xa0\\xc0\\xaf\\xed\\xa0\\x80z\";\nstring replace_invalid_result = replace_invalid(invalid_sequence, '?');\nbvalid = is_valid(replace_invalid_result);\nassert (bvalid);\nconst string fixed_invalid_sequence = \"a????z\";\nassert (fixed_invalid_sequence == replace_invalid_result);\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"stdstring-replace_invalidstdstring_view-s-char32_t-replacement\"\u003e\u003c/a\u003e\n##### std::string replace_invalid(std::string_view s, char32_t replacement)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nReplaces all invalid UTF-8 sequences within a string with a replacement marker.\n\n```cpp\nstd::string replace_invalid(std::string_view s, char32_t replacement);\nstd::string replace_invalid(std::string_view s);\n```\n\n`s`: a UTF-8 encoded string.  \n`replacement`: A Unicode code point for the replacement marker. The version without this parameter assumes the value `0xfffd`  \nReturn value: A UTF-8 encoded string with replaced invalid sequences.\n\nExample of use:\n\n```cpp\nstring_view invalid_sequence = \"a\\x80\\xe0\\xa0\\xc0\\xaf\\xed\\xa0\\x80z\";\nstring replace_invalid_result = replace_invalid(invalid_sequence, '?');\nbool bvalid = is_valid(replace_invalid_result);\nassert (bvalid);\nconst string fixed_invalid_sequence = \"a????z\";\nassert(fixed_invalid_sequence, replace_invalid_result);\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8starts_with_bom\"\u003e\u003c/a\u003e\n#### utf8::starts_with_bom\n\u003c!-- TOC --\u003e\u003ca name=\"bool-starts_with_bom-octet_iterator-it-octet_iterator-end\"\u003e\u003c/a\u003e\n##### bool starts_with_bom (octet_iterator it, octet_iterator end)\n\nAvailable in version 2.3 and later.\n\nChecks whether an octet sequence starts with a UTF-8 byte order mark (BOM)\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e \nbool starts_with_bom (octet_iterator it, octet_iterator end);\n```\n\n`octet_iterator`: an input iterator.  \n`it`: beginning of the octet sequence to check  \n`end`: pass-end of the sequence to check  \nReturn value: `true` if the sequence starts with a UTF-8 byte order mark; `false` if not.\n\nExample of use:\n\n```cpp\nunsigned char byte_order_mark[] = {0xef, 0xbb, 0xbf};\nbool bbom = starts_with_bom(byte_order_mark, byte_order_mark + sizeof(byte_order_mark));\nassert (bbom == true);\n```\n\nThe typical use of this function is to check the first three bytes of a file. If they form the UTF-8 BOM, we want to skip them before processing the actual UTF-8 encoded text.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"bool-starts_with_bomconst-stdstring-s\"\u003e\u003c/a\u003e\n##### bool starts_with_bom(const std::string\u0026 s)\n\nAvailable in version 3.0 and later. Prior to 4.0 it required a C++ 11 compiler; the requirement is lifted with 4.0\n\nChecks whether a string starts with a UTF-8 byte order mark (BOM)\n\n```cpp\nbool starts_with_bom(const std::string\u0026 s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: `true` if the string starts with a UTF-8 byte order mark; `false` if not.\n\nExample of use:\n\n```cpp\nstring byte_order_mark = {char(0xef), char(0xbb), char(0xbf)};\nbool bbom = starts_with_bom(byte_order_mark);\nassert (bbom == true);\nstring threechars = \"\\xf0\\x90\\x8d\\x86\\xe6\\x97\\xa5\\xd1\\x88\";\nbool no_bbom = starts_with_bom(threechars);\nassert (no_bbom == false);\n ```\n\nThe typical use of this function is to check the first three bytes of a file. If they form the UTF-8 BOM, we want to skip them before processing the actual UTF-8 encoded text.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"bool-starts_with_bomstdstring_view-s\"\u003e\u003c/a\u003e\n##### bool starts_with_bom(std::string_view s)\n\nAvailable in version 3.2 and later. Requires a C++ 17 compliant compiler.\n\nChecks whether a string starts with a UTF-8 byte order mark (BOM)\n\n```cpp\nbool starts_with_bom(std::string_view s);\n```\n\n`s`: a UTF-8 encoded string.\nReturn value: `true` if the string starts with a UTF-8 byte order mark; `false` if not.\n\nExample of use:\n\n```cpp\nstring byte_order_mark = {char(0xef), char(0xbb), char(0xbf)};\nstring_view byte_order_mark_view(byte_order_mark);\nbool bbom = starts_with_bom(byte_order_mark_view);\nassert (bbom);\nstring_view threechars = \"\\xf0\\x90\\x8d\\x86\\xe6\\x97\\xa5\\xd1\\x88\";\nbool no_bbom = starts_with_bom(threechars);\nassert (!no_bbom);\n ```\n\nThe typical use of this function is to check the first three bytes of a file. If they form the UTF-8 BOM, we want to skip them before processing the actual UTF-8 encoded text.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"types-from-utf8-namespace\"\u003e\u003c/a\u003e\n### Types From utf8 Namespace\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8exception\"\u003e\u003c/a\u003e\n#### utf8::exception\n\nAvailable in version 2.3 and later.\n\nBase class for the exceptions thrown by UTF CPP library functions.\n\n```cpp\nclass exception : public std::exception {};\n```\n\nExample of use:\n\n```cpp\ntry {\n  code_that_uses_utf_cpp_library();\n}\ncatch(const utf8::exception\u0026 utfcpp_ex) {\n  cerr \u003c\u003c utfcpp_ex.what();\n}\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8invalid_code_point\"\u003e\u003c/a\u003e\n#### utf8::invalid_code_point\n\nAvailable in version 1.0 and later.\n\nThrown by UTF8 CPP functions such as `advance` and `next` if an UTF-8 sequence represents and invalid code point.\n\n```cpp\nclass invalid_code_point : public exception {\npublic: \n    utfchar32_t code_point() const;\n};\n```\n\nMember function `code_point()` can be used to determine the invalid code point that caused the exception to be thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8invalid_utf8\"\u003e\u003c/a\u003e\n#### utf8::invalid_utf8\n\nAvailable in version 1.0 and later.\n\nThrown by UTF8 CPP functions such as `next` and `prior` if an invalid UTF-8 sequence is detected during decoding.\n\n```cpp\nclass invalid_utf8 : public exception {\npublic: \n    utfchar8_t utf8_octet() const;\n};\n```\n\nMember function `utf8_octet()` can be used to determine the beginning of the byte sequence that caused the exception to be thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8invalid_utf16\"\u003e\u003c/a\u003e\n#### utf8::invalid_utf16\n\nAvailable in version 1.0 and later.\n\nThrown by UTF8 CPP function `utf16to8` if an invalid UTF-16 sequence is detected during decoding.\n\n```cpp\nclass invalid_utf16 : public exception {\npublic: \n    utfchar16_t utf16_word() const;\n};\n```\n\nMember function `utf16_word()` can be used to determine the UTF-16 code unit that caused the exception to be thrown.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8not_enough_room\"\u003e\u003c/a\u003e\n#### utf8::not_enough_room\n\nAvailable in version 1.0 and later.\n\nThrown by UTF8 CPP functions such as `next` if the end of the decoded UTF-8 sequence was reached before the code point was decoded.\n\n```cpp\nclass not_enough_room : public exception {};\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8iterator\"\u003e\u003c/a\u003e\n#### utf8::iterator\n\nAvailable in version 2.0 and later.\n\nAdapts the underlying octet iterator to iterate over the sequence of code points, rather than raw octets.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\nclass iterator;\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"member-functions\"\u003e\u003c/a\u003e\n##### Member functions\n\n`iterator();` the default constructor; the underlying octet_iterator is constructed with its default constructor.\n\n`explicit iterator (const octet_iterator\u0026 octet_it, const octet_iterator\u0026 range_start, const octet_iterator\u0026 range_end);` a constructor that initializes the underlying octet_iterator with octet_it and sets the range in which the iterator is considered valid.\n\n`octet_iterator base () const;` returns the underlying octet_iterator.\n\n`utfchar32_t operator * () const;` decodes the utf-8 sequence the underlying octet_iterator is pointing to and returns the code point.\n\n`bool operator == (const iterator\u0026 rhs) const;` returns `true` if the two underlying iterators are equal.\n\n`bool operator != (const iterator\u0026 rhs) const;` returns `true` if the two underlying iterators are not equal.\n\n`iterator\u0026 operator ++ ();` the prefix increment - moves the iterator to the next UTF-8 encoded code point.\n\n`iterator operator ++ (int);` the postfix increment - moves the iterator to the next UTF-8 encoded code point and returns the current one.\n\n`iterator\u0026 operator -- ();` the prefix decrement - moves the iterator to the previous UTF-8 encoded code point.\n\n`iterator operator -- (int);` the postfix decrement - moves the iterator to the previous UTF-8 encoded code point and returns the current one.\n\nExample of use:\n\n```cpp\nchar* threechars = \"\\xf0\\x90\\x8d\\x86\\xe6\\x97\\xa5\\xd1\\x88\";\nutf8::iterator\u003cchar*\u003e it(threechars, threechars, threechars + 9);\nutf8::iterator\u003cchar*\u003e it2 = it;\nassert (it2 == it);\nassert (*it == 0x10346);\nassert (*(++it) == 0x65e5);\nassert ((*it++) == 0x65e5);\nassert (*it == 0x0448);\nassert (it != it2);\nutf8::iterator\u003cchar*\u003e endit (threechars + 9, threechars, threechars + 9);  \nassert (++it == endit);\nassert (*(--it) == 0x0448);\nassert ((*it--) == 0x0448);\nassert (*it == 0x65e5);\nassert (--it == utf8::iterator\u003cchar*\u003e(threechars, threechars, threechars + 9));\nassert (*it == 0x10346);\n```\n\nThe purpose of `utf8::iterator` adapter is to enable easy iteration as well as the use of STL algorithms with UTF-8 encoded strings. Increment and decrement operators are implemented in terms of `utf8::next()` and `utf8::prior()` functions.\n\nNote that `utf8::iterator` adapter is a checked iterator. It operates on the range specified in the constructor; any attempt to go out of that range will result in an exception. Even the comparison operators require both iterator object to be constructed against the same range - otherwise an exception is thrown. Typically, the range will be determined by sequence container functions `begin` and `end`, i.e.:\n\n```cpp\nstd::string s = \"example\";\nutf8::iterator i (s.begin(), s.begin(), s.end());\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"functions-from-utf8unchecked-namespace\"\u003e\u003c/a\u003e\n### Functions From utf8::unchecked Namespace\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedappend\"\u003e\u003c/a\u003e\n#### utf8::unchecked::append\n\nAvailable in version 1.0 and later.\n\nEncodes a 32 bit code point as a UTF-8 sequence of octets and appends the sequence to a UTF-8 string.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\noctet_iterator append(utfchar32_t cp, octet_iterator result);\n```\n\n`cp`: A 32 bit integer representing a code point to append to the sequence.  \n`result`: An output iterator to the place in the sequence where to append the code point.  \nReturn value: An iterator pointing to the place after the newly appended sequence.\n\nExample of use:\n\n```cpp\nunsigned char u[5] = {0,0,0,0,0};\nunsigned char* end = unchecked::append(0x0448, u);\nassert (u[0] == 0xd1 \u0026\u0026 u[1] == 0x88 \u0026\u0026 u[2] == 0 \u0026\u0026 u[3] == 0 \u0026\u0026 u[4] == 0);\n```\n\nThis is a faster but less safe version of `utf8::append`. It does not check for validity of the supplied code point, and may produce an invalid UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedappend16\"\u003e\u003c/a\u003e\n#### utf8::unchecked::append16\n\nAvailable in version 4.0 and later.\n\nEncodes a 32 bit code point as a UTF-16 sequence of words and appends the sequence to a UTF-16 string.\n\n```cpp\ntemplate \u003ctypename word_iterator\u003e\nword_iterator append16(utfchar32_t cp, word_iterator result)\n```\n\n`cp`: A 32 bit integer representing a code point to append to the sequence.  \n`result`: An output iterator to the place in the sequence where to append the code point.  \nReturn value: An iterator pointing to the place after the newly appended sequence.\n\nExample of use:\n\n```cpp\nunsigned short u[5] = {0,0};\nutf8::unchecked::append16(0x0448, u);\nassert(u[0], 0x0448);\nassert(u[1], 0x0000);\n```\n\nThis is a faster but less safe version of `utf8::append`. It does not check for validity of the supplied code point, and may produce an invalid UTF-8 sequence.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckednext\"\u003e\u003c/a\u003e\n#### utf8::unchecked::next\n\nAvailable in version 1.0 and later.\n\nGiven the iterator to the beginning of a UTF-8 sequence, it returns the code point and moves the iterator to the next position.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\nutfchar32_t next(octet_iterator\u0026 it);\n```\n\n`it`: a reference to an iterator pointing to the beginning of an UTF-8 encoded code point. After the function returns, it is incremented to point to the beginning of the next code point.  \n Return value: the 32 bit representation of the processed UTF-8 code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars;\nint cp = unchecked::next(w);\nassert (cp == 0x65e5);\nassert (w == twochars + 3);\n```\n\nThis is a faster but less safe version of `utf8::next`. It does not check for validity of the supplied UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8next16-1\"\u003e\u003c/a\u003e\n#### utf8::next16\n\nAvailable in version 4.0 and later.\n\nGiven the iterator to the beginning of the UTF-16 sequence, it returns the code point and moves the iterator to the next position.\n\n```cpp\ntemplate \u003ctypename word_iterator\u003e\nutfchar32_t next16(word_iterator\u0026 it);\n```\n\n`word_iterator`: an input iterator.  \n`it`: a reference to an iterator pointing to the beginning of an UTF-16 encoded code point. After the function returns, it is incremented to point to the beginning of the next code point.  \n\nReturn value: the 32 bit representation of the processed UTF-16 code point.\n\nExample of use:\n\n```cpp\nconst unsigned short u[3] = {0x65e5, 0xd800, 0xdf46};\nconst unsigned short* w = u;\nint cp = unchecked::next16(w);\nassert (cp, 0x65e5);\nassert (w, u + 1);\n```\n\nThis function is typically used to iterate through a UTF-16 encoded string.\n\nThis is a faster but less safe version of `utf8::next16`. It does not check for validity of the supplied UTF-8 sequence.\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedpeek_next\"\u003e\u003c/a\u003e\n#### utf8::unchecked::peek_next\n\nAvailable in version 2.1 and later.\n\nGiven the iterator to the beginning of a UTF-8 sequence, it returns the code point.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\nutfchar32_t peek_next(octet_iterator it);\n```\n\n`it`: an iterator pointing to the beginning of an UTF-8 encoded code point.  \nReturn value: the 32 bit representation of the processed UTF-8 code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars;\nint cp = unchecked::peek_next(w);\nassert (cp == 0x65e5);\nassert (w == twochars);\n```\n\nThis is a faster but less safe version of `utf8::peek_next`. It does not check for validity of the supplied UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedprior\"\u003e\u003c/a\u003e\n#### utf8::unchecked::prior\n\nAvailable in version 1.02 and later.\n\nGiven a reference to an iterator pointing to an octet in a UTF-8 sequence, it decreases the iterator until it hits the beginning of the previous UTF-8 encoded code point and returns the 32 bits representation of the code point.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\nutfchar32_t prior(octet_iterator\u0026 it);\n```\n\n`it`: a reference pointing to an octet within a UTF-8 encoded string. After the function returns, it is decremented to point to the beginning of the previous code point.  \n Return value: the 32 bit representation of the previous code point.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars + 3;\nint cp = unchecked::prior (w);\nassert (cp == 0x65e5);\nassert (w == twochars);\n```\n\nThis is a faster but less safe version of `utf8::prior`. It does not check for validity of the supplied UTF-8 sequence and offers no boundary checking.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedadvance\"\u003e\u003c/a\u003e\n#### utf8::unchecked::advance\n\nAvailable in version 1.0 and later.\n\nAdvances an iterator by the specified number of code points within an UTF-8 sequence.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename distance_type\u003e\nvoid advance (octet_iterator\u0026 it, distance_type n);\n```\n\n`it`: a reference to an iterator pointing to the beginning of an UTF-8 encoded code point. After the function returns, it is incremented to point to the nth following code point.\n`n`: number of code points `it` should be advanced. A negative value means decrement.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nchar* w = twochars;\nunchecked::advance (w, 2);\nassert (w == twochars + 5);\n```\n\nThis is a faster but less safe version of `utf8::advance`. It does not check for validity of the supplied UTF-8 sequence and offers no boundary checking.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckeddistance\"\u003e\u003c/a\u003e\n#### utf8::unchecked::distance\n\nAvailable in version 1.0 and later.\n\nGiven the iterators to two UTF-8 encoded code points in a sequence, returns the number of code points between them.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\ntypename std::iterator_traits\u003coctet_iterator\u003e::difference_type distance (octet_iterator first, octet_iterator last);\n```\n\n`first`: an iterator to a beginning of a UTF-8 encoded code point.  \n`last`: an iterator to a \"post-end\" of the last UTF-8 encoded code point in the sequence we are trying to determine the length. It can be the beginning of a new code point, or not.  \nReturn value: the distance between the iterators, in code points.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nsize_t dist = utf8::unchecked::distance(twochars, twochars + 5);\nassert (dist == 2);\n```\n\nThis is a faster but less safe version of `utf8::distance`. It does not check for validity of the supplied UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedutf16to8\"\u003e\u003c/a\u003e\n#### utf8::unchecked::utf16to8\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-16 encoded string to UTF-8.\n\n```cpp\ntemplate \u003ctypename u16bit_iterator, typename octet_iterator\u003e\noctet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result);\n```\n\n`start`: an iterator pointing to the beginning of the UTF-16 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-16 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-8 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-8 string.\n\nExample of use:\n\n```cpp\nunsigned short utf16string[] = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};\nvector\u003cunsigned char\u003e utf8result;\nunchecked::utf16to8(utf16string, utf16string + 5, back_inserter(utf8result));\nassert (utf8result.size() == 10);    \n```\n\nThis is a faster but less safe version of `utf8::utf16to8`. It does not check for validity of the supplied UTF-16 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedutf8to16\"\u003e\u003c/a\u003e\n#### utf8::unchecked::utf8to16\n\nAvailable in version 1.0 and later.\n\nConverts an UTF-8 encoded string to UTF-16\n\n```cpp\ntemplate \u003ctypename u16bit_iterator, typename octet_iterator\u003e\nu16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result);\n```\n\n`start`: an iterator pointing to the beginning of the UTF-8 encoded string to convert.\n`end`: an iterator pointing to pass-the-end of the UTF-8 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-16 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-16 string.\n\nExample of use:\n\n```cpp\nchar utf8_with_surrogates[] = \"\\xe6\\x97\\xa5\\xd1\\x88\\xf0\\x9d\\x84\\x9e\";\nvector \u003cunsigned short\u003e utf16result;\nunchecked::utf8to16(utf8_with_surrogates, utf8_with_surrogates + 9, back_inserter(utf16result));\nassert (utf16result.size() == 4);\nassert (utf16result[2] == 0xd834);\nassert (utf16result[3] == 0xdd1e);\n```\n\nThis is a faster but less safe version of `utf8::utf8to16`. It does not check for validity of the supplied UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedutf32to8\"\u003e\u003c/a\u003e\n#### utf8::unchecked::utf32to8\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-32 encoded string to UTF-8.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename u32bit_iterator\u003e\noctet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result);\n```\n\n`start`: an iterator pointing to the beginning of the UTF-32 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-32 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-8 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-8 string.\n\nExample of use:\n\n```cpp\nint utf32string[] = {0x448, 0x65e5, 0x10346, 0};\nvector\u003cunsigned char\u003e utf8result;\nutf32to8(utf32string, utf32string + 3, back_inserter(utf8result));\nassert (utf8result.size() == 9);\n```\n\nThis is a faster but less safe version of `utf8::utf32to8`. It does not check for validity of the supplied UTF-32 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedutf8to32\"\u003e\u003c/a\u003e\n#### utf8::unchecked::utf8to32\n\nAvailable in version 1.0 and later.\n\nConverts a UTF-8 encoded string to UTF-32.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename u32bit_iterator\u003e\nu32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result);\n```\n\n`start`: an iterator pointing to the beginning of the UTF-8 encoded string to convert.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 encoded string to convert.  \n`result`: an output iterator to the place in the UTF-32 string where to append the result of conversion.  \nReturn value: An iterator pointing to the place after the appended UTF-32 string.\n\nExample of use:\n\n```cpp\nchar* twochars = \"\\xe6\\x97\\xa5\\xd1\\x88\";\nvector\u003cint\u003e utf32result;\nunchecked::utf8to32(twochars, twochars + 5, back_inserter(utf32result));\nassert (utf32result.size() == 2);\n```\n\nThis is a faster but less safe version of `utf8::utf8to32`. It does not check for validity of the supplied UTF-8 sequence.\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8uncheckedreplace_invalid\"\u003e\u003c/a\u003e\n#### utf8::unchecked::replace_invalid\n\nAvailable in version 3.1 and later.\n\nReplaces all invalid UTF-8 sequences within a string with a replacement marker.\n\n```cpp\ntemplate \u003ctypename octet_iterator, typename output_iterator\u003e\noutput_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, utfchar32_t replacement);\ntemplate \u003ctypename octet_iterator, typename output_iterator\u003e\noutput_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out);\n```\n\n`octet_iterator`: an input iterator.  \n`output_iterator`: an output iterator.  \n`start`: an iterator pointing to the beginning of the UTF-8 string to look for invalid UTF-8 sequences.  \n`end`: an iterator pointing to pass-the-end of the UTF-8 string to look for invalid UTF-8 sequences.  \n`out`: An output iterator to the range where the result of replacement is stored.  \n`replacement`: A Unicode code point for the replacement marker. The version without this parameter assumes the value `0xfffd`  \nReturn value: An iterator pointing to the place after the UTF-8 string with replaced invalid sequences.\n\nExample of use:\n\n```cpp\nchar invalid_sequence[] = \"a\\x80\\xe0\\xa0\\xc0\\xaf\\xed\\xa0\\x80z\";\nvector\u003cchar\u003e replace_invalid_result;\nunchecked::replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), back_inserter(replace_invalid_result), '?');\nbvalid = utf8::is_valid(replace_invalid_result.begin(), replace_invalid_result.end());\nassert (bvalid);\nchar* fixed_invalid_sequence = \"a????z\";\nassert (std::equal(replace_invalid_result.begin(), replace_invalid_result.end(), fixed_invalid_sequence));\n```\n\n`replace_invalid` does not perform in-place replacement of invalid sequences. Rather, it produces a copy of the original string with the invalid sequences replaced with a replacement marker. Therefore, `out` must not be in the `[start, end]` range.\n\nUnlike `utf8::replace_invalid`, this function does not verify validity of the replacement marker.\n\n\u003c!-- TOC --\u003e\u003ca name=\"types-from-utf8unchecked-namespace\"\u003e\u003c/a\u003e\n### Types From utf8::unchecked Namespace\n\n\u003c!-- TOC --\u003e\u003ca name=\"utf8iterator-1\"\u003e\u003c/a\u003e\n#### utf8::iterator\n\nAvailable in version 2.0 and later.\n\nAdapts the underlying octet iterator to iterate over the sequence of code points, rather than raw octets.\n\n```cpp\ntemplate \u003ctypename octet_iterator\u003e\nclass iterator;\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"member-functions-1\"\u003e\u003c/a\u003e\n##### Member functions\n\n`iterator();` the default constructor; the underlying octet_iterator is constructed with its default constructor.\n\n`explicit iterator (const octet_iterator\u0026 octet_it);` a constructor that initializes the underlying octet_iterator with `octet_it`.\n\n`octet_iterator base () const;` returns the underlying octet_iterator.\n\n`utfchar32_t operator * () const;` decodes the utf-8 sequence the underlying octet_iterator is pointing to and returns the code point.\n\n`bool operator == (const iterator\u0026 rhs) const;` returns `true` if the two underlying iterators are equal.\n\n`bool operator != (const iterator\u0026 rhs) const;` returns `true` if the two underlying iterators are not equal.\n\n`iterator\u0026 operator ++ ();` the prefix increment - moves the iterator to the next UTF-8 encoded code point.\n\n`iterator operator ++ (int);` the postfix increment - moves the iterator to the next UTF-8 encoded code point and returns the current one.\n\n`iterator\u0026 operator -- ();` the prefix decrement - moves the iterator to the previous UTF-8 encoded code point.\n\n`iterator operator -- (int);` the postfix decrement - moves the iterator to the previous UTF-8 encoded code point and returns the current one.\n\nExample of use:\n\n```cpp\nchar* threechars = \"\\xf0\\x90\\x8d\\x86\\xe6\\x97\\xa5\\xd1\\x88\";\nutf8::unchecked::iterator\u003cchar*\u003e un_it(threechars);\nutf8::unchecked::iterator\u003cchar*\u003e un_it2 = un_it;\nassert (un_it2 == un_it);\nassert (*un_it == 0x10346);\nassert (*(++un_it) == 0x65e5);\nassert ((*un_it++) == 0x65e5);\nassert (*un_it == 0x0448);\nassert (un_it != un_it2);\nutf8::::unchecked::iterator\u003cchar*\u003e un_endit (threechars + 9);  \nassert (++un_it == un_endit);\nassert (*(--un_it) == 0x0448);\nassert ((*un_it--) == 0x0448);\nassert (*un_it == 0x65e5);\nassert (--un_it == utf8::unchecked::iterator\u003cchar*\u003e(threechars));\nassert (*un_it == 0x10346);\n```\n\nThis is an unchecked version of `utf8::iterator`. It is faster in many cases, but offers no validity or range checks.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtrif%2Futfcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnemtrif%2Futfcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnemtrif%2Futfcpp/lists"}