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…