Mojibake 0.2.7 – Zero‑Dependency Unicode 17 Library for C11/C++17

Mojibake 0.2.7 – Zero‑Dependency Unicode 17 Library for C11/C++17

Mojibake 0.2.7 delivers full Unicode 17 support in a single‑file C library

Mojibake 0.2.7 は、正規化、ケースフォールディング、セグメンテーション、双方向レイアウト、絵文字処理、照合、セキュリティチェックを含む Unicode 17.0.0 仕様全体を実装し、外部依存ゼロかつランタイム不要で提供します。これにより、重厚なライブラリを導入できない低レベルプロジェクトに最適です。


Why a zero‑dependency Unicode library matters

ほとんどの C/C++ プロジェクトは、巨大なコードベースや複雑なビルドシステム、ランタイムデータテーブルを伴うサードパーティ製 Unicode ライブラリ(例: ICU)に依存しています。Mojibake は、すべてのソースと Unicode データテーブルを 2 つのファイル(mojibake.cmojibake.h)にまとめることで、これらの問題を回避します。その結果、シングルヘッダー/実装となり、任意の C11 または C++17 コンパイラでコンパイルでき、追加のライブラリなしでリンク可能です。


Core capabilities at a glance

Capability API function(s) Standard reference
Normalization (NFC, NFD, NFKC, NFKD) mjb_normalize, mjb_string_is_normalized UAX #15
Case folding & conversion (upper, lower, title, NFKC casefold) mjb_case, mjb_nfkc_casefold UAX #31, UAX #15
Segmentation (grapheme clusters, words, sentences, line breaks) mjb_break_grapheme_cluster, mjb_break_word, mjb_break_sentence, mjb_break_line UAX #29, UAX #14
Bidirectional algorithm (paragraph resolution, line reordering) mjb_bidi_resolve, mjb_bidi_reorder_line UAX #9
Emoji analysis (properties, sequence detection, RGI check) mjb_string_emoji_sequence, mjb_string_is_rgi_emoji UTS #51
Collation (UCA compare, sort‑key generation) mjb_string_compare, mjb_collation_key UTS #10
Security (confusable detection, identifier validation) mjb_confusable_skeleton, mjb_string_is_confusable, mjb_string_is_identifier UTS #39, UAX #31
Encoding conversion (UTF‑8, UTF‑16LE/BE, UTF‑32LE/BE) mjb_string_convert_encoding, mjb_string_encoding
Display width & truncation (terminal columns, width‑aware truncation) mjb_display_width, mjb_truncate_width UAX #11

All functions return a detailed mjb_status enum, allowing callers to distinguish success, invalid arguments, memory failures, and overflow conditions.


Minimal integration steps

  1. Download the amalgamationmojibake-amalgamation-027.zip contains mojibake.c and mojibake.h.
  2. Add the files to your project source tree.
  3. Include the header where Unicode handling is needed:
    #include "mojibake.h"
    
  4. Compile with any C11 or C++17 compiler; no linker flags are required.

Because the library has no runtime, you can also embed it in static libraries, firmware, or WebAssembly modules without pulling in additional binaries.


Performance considerations (community questions)

"How does it compare with utf8proc?" – @lifthrasiir

Mojibake は utf8proc(UTF‑8 の検証、正規化、ケースフォールディングに特化)よりも広範な機能を提供します。双方向処理、Unicode 照合、絵文字シーケンス検出、セキュリティ指向の混同チェックが追加されています。著者はベンチマーク数値を公開していないため、速度比較は逸話的です。

"What's performance like compared to Python's ftfy module?" – @tjwebbnorfolk

ftfy は高度な Python ライブラリで、壊れた Unicode の自動修正を行います。Mojibake は低レベルでアルゴリズムをそのまま提供するため、エラー修正は自動では行われません。そのため、純粋なスループットは高いと予想されますが、ソース側での直接比較ベンチマークは提供されていません。


Build‑time feature toggles for size‑constrained environments

Mojibake はコンパイル時にオプションテーブルを除外でき、バイナリサイズを削減します。たとえば文字名を無効化するとデータフットプリントが 約30 % 減少します:

# CMake
cmake -S . -B build-no-name -DMJB_FEATURE_CHARACTER_NAMES=OFF
cmake --build build-no-name

# Makefile shortcut
make build BUILD_DIR=build-no-name FEATURE_CHARACTER_NAMES=OFF

他のテーブル(例: 絵文字プロパティ、スクリプト拡張)も MJB_FEATURE_* マクロで同様にトリミング可能です。


Security‑focused utilities

  • Confusable detectionmjb_confusable_skeleton は言語非依存のスケルトンを生成し、mjb_string_is_confusable は視覚的類似性を比較してホモグラフ攻撃から保護します。
  • Identifier validationmjb_string_is_identifier は Unicode 識別子規則(ID_Start/ID_Continue または XID バリアント)を強制し、コンパイラやインタプリタで有用です。

Both utilities rely on the official Unicode security data files (confusables.txt, IdentifierStatus.txt).


Testing, fuzzing, and conformance guarantees

Mojibake はサポート対象すべてのアルゴリズムに対し、公式 Unicode テストスイートで検証されています。プロジェクトは Attractor テストハーネスを使用し、150 万件以上のアサーション を実行します。含まれるテスト例:

  • 完全な Unicode 正規化ベクトル。
  • 双方向アルゴリズムの適合性。
  • 照合テストデータ。
  • 絵文字シーケンスの検証。

さらに、ライブラリは libFuzzer で継続的にファジングされ、すべてのビルドは AddressSanitizerUBSan の下で実行され、メモリ安全性の問題を検出します。


Community reception (selected HN comments)

"Love the amalgamation approach—the C/C++ ecosystem desperately needs cleaner, lightweight Unicode support without pulling in massive dependencies... thanks for sharing" – @digg99

単一ファイルライブラリの実用的価値を強調するコメントです。重厚な依存関係を抱えられないプロジェクトにとって大きな助けとなります。

"I have come to the conclusion that the only Unicode support needed in C is supporting pointers to char and arrays but lightweight C libraries are always welcome" – @avadodin

最小限の Unicode 処理(長さカウントやケースフォールディング)でも、単なるバイト配列以上の機能が必要になることを指摘し、Mojibake がそのギャップを埋めることを示しています。

"Not to bikeshed, but isn’t the word ‘mojibake’ synonymous with ‘when character encoding breaks’?" – @CharlesW

ライブラリ名は文字化け(mojibake)という古典的問題に由来し、それを防止するツールを提供する意図が込められています。


License and legal notices

Mojibake は MIT License の下でリリースされています。Unicode Character Database と CLDR データを組み込んでおり、これらは元の Unicode ライセンス(license.txt と CLDR LICENSE を参照)を保持します。


Getting started

  1. Download the latest release (v0.2.7) from the GitHub releases page.
  2. Read the API reference (API.md) for detailed function signatures.
  3. Run the CLI (src/shell/mojibake) for quick experiments, e.g.:
    mojibake nfc $'Cafe\u0301'   # → NFC: Café
    mojibake emoji "☺️"        # → shows emoji classification
    
  4. Contribute – see CONTRIBUTING.md for guidelines on adding new Unicode versions or fixing bugs.

Bottom line

Mojibake 0.2.7 は、依存ゼロの小さなパッケージで、完全かつ標準準拠の Unicode 17 実装を提供します。そのシングルファイル配布、豊富な機能セット、徹底したテストにより、重厚なライブラリを導入できない C または C++ プロジェクトにとって魅力的な選択肢となります。

Sources