sheredom/utf8.h
Free📚 single header utf8 string functions for C and C++
FreeFree tier
About sheredom/utf8.h
utf8.h is a single-header C and C++ library that provides UTF-8 string manipulation functions with an API closely mirroring the standard C string.h and strings.h headers. It offers functions such as utf8len, utf8cmp, utf8chr, plus unique utilities like utf8valid, utf8codepoint, and case conversion. Many functions support C++14 constexpr. The library is designed for easy integration (just #include the header) and works on Linux, macOS, and Windows with GCC, Clang, MSVC, and clang-cl.
Key Features
Single header file, no dependencies
UTF-8 equivalents of string.h functions (utf8len, utf8cmp, utf8cpy, etc.)
UTF-8 equivalents of strings.h functions (utf8casecmp, utf8ncasecmp, utf8casestr)
Unique functions: utf8codepoint, utf8valid, utf8makevalid, utf8lwr, utf8upr
C++14 constexpr support for many functions
Cross-platform (Linux, macOS, Windows)
Support for GCC, Clang, MSVC, clang-cl
Pros & Cons
Pros
- Easy integration with single header file
- Comprehensive API covering most string.h functions
- Case-insensitive comparison and case conversion
- Validation functions to ensure proper UTF-8
- Constexpr support for compile-time operations
- Portable across major platforms and compilers
Cons
- Only works with C/C++ (no bindings for other languages)
- No wide character or locale support beyond UTF-8
- No built-in iteration abstraction beyond raw pointer manipulation
Best For
Internationalizing C/C++ applicationsParsing and validating UTF-8 textImplementing text search and comparison on UTF-8 stringsConverting between case or extracting codepoints from UTF-8 strings
FAQ
What is utf8.h?
It's a single-header C and C++ library that provides UTF-8 string functions mirroring the standard string.h and strings.h APIs, plus additional UTF-8-specific utilities.
How do I use utf8.h in my project?
Simply download the utf8.h header file and include it with #include 'utf8.h' in your C or C++ source code.
What compilers and platforms are supported?
utf8.h supports GCC, Clang, MSVC, and clang-cl on Linux, macOS, and Windows.
Does utf8.h support C++11 or C++14?
Many functions are marked as C++14 constexpr, allowing compile-time evaluation when using C++14 or later.