$ show nemtrif/utfcpp
UTF8-CPP is a mature, header-only C++ library for encoding and decoding between UTF-8, UTF-16, and UTF-32 Unicode formats. It provides both checked (validating) and unchecked (fast) APIs for common operations such as iterating over code points, appending encoded sequences, converting between encodings, detecting invalid sequences, and replacing invalid sequences with a replacement character. The library is designed to be generic (works with any iterator model), portable across C++98/11/14/17/20, and lightweight (pay-only-for-what-you-use). It has a comprehensive test suite derived from Markus Kuhn's UTF-8 stress test and is widely used in open-source and commercial projects. The architecture is modular: core.h contains the low-level validation and encoding logic, checked.h adds exception-throwing wrappers, and unchecked.h provides non-throwing variants, with additional C++ standard edition-specific convenience overloads in cpp11.h, cpp17.h, and cpp20.h.
The LLM identified 1 files worth highlighting for reuse:
Contains the core UTF-8 decoding and encoding logic, including the internal `utf_error` enum, sequence length detection, and the `get_sequence_x` functions for parsing 1-4 byte sequences with proper overlong, surrogate, and out-of-range rejection. It also provides the `find_invalid` and `is_valid` public functions. This file is self-contained (only includes standard headers) and implements a rigorous, iterable state machine for UTF-8 validation that can be extracted and reused in any C++ project requiring low-level byte sequence analysis.