mcpp index

compat.utfcpp

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

mcpp add compat.utfcpp@5.0.0

用法

来自本仓库自己的测试项目 —— CI 真的编译并运行过,不是为了网站写的。

#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 · 项目 tests/examples/utfcpp

构建

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

源文件 (1)

  • mcpp_generated/utfcpp_anchor.c

生成的文件

  • mcpp_generated/utfcpp_anchor.c

版本

版本平台 镜像sha256
5.0.0 最新 LinuxWindowsmacOS CN GLOBAL 42c36e1ef130…