mcpp index

compat.utfcpp

UTF8-CPP — UTF-8 with C++ in a portable way (header-only)

mcpp add compat.utfcpp@5.0.0

Usage

From this repository's own test project — built and run by CI, not written for the website.

#include <string>
#include <string_view>
#include <vector>

#include <utf8.h>
#include <utf8/cpp17.h>

int main() {
    bool ok = true;

    // "Hi, 世界!" in UTF-8: 'H','i',',',' ' (4) + U+4E16 (3 bytes) + U+754C (3 bytes) + '!' (1) = 7 code points
    const std::string text = "Hi, \xE4\xB8\x96\xE7\x95\x8C!";
    ok = ok && utf8::is_valid(text.begin(), text.end());
    ok = ok && utf8::distance(text.begin(), text.end()) == 7;

    // UTF-8 <-> UTF-16 round-trip via C++17 string_view helpers
    std::u16string u16 = utf8::utf8to16(std::string_view(text));
    ok = ok && u16.size() == 7;
    ok = ok && u16[4] == u'\u4E16' && u16[5] == u'\u754C';

    std::string back = utf8::utf16to8(std::u16string_view(u16));
    ok = ok && back == text;
// …

tests/examples/utfcpp/tests/test_utfcpp.cpp · project tests/examples/utfcpp

Build

targets
utfcpp (lib)
language
c++23
C standard
c11
import std
no
include dirs
*/source

Sources (1)

  • mcpp_generated/utfcpp_anchor.c

Generated files

  • mcpp_generated/utfcpp_anchor.c

Versions

VersionPlatforms Mirrorssha256
5.0.0 latest LinuxWindowsmacOS CN GLOBAL 42c36e1ef130…