Skip to content

About

Cross-platform Unicode Library

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Cross-platform Unicode Library

Header-only Unicode tables and functions without dependencies.

Character properties, case mappings, normalization and text segmentation follow the Unicode Character Database (currently Unicode 16.0.0). Include only what you need. A header pulls in only the tables it uses, and the linker drops any table your code doesn't reference.

Header Contents
unicodebase.h Table lookup, UTF-16 code point access (C++11)
unicodecodec.h UTF-8 and UTF-16 encoding, readers, writers, code point iterator (C++11)
unicodeproperties.h isAlpha, isUppercase, isLowercase, isNumeric, isWhitespace, isCased, isFullWidth, getCombiningClass, ...
unicodecase.h Simple case mappings, case folding, in-place string case conversion (final sigma), capitalize
unicodenormalization.h NFC, NFD, NFKC, NFKD
unicodecompare.h Canonical caseless comparison, search, numeric comparison
unicodegrapheme.h Grapheme cluster boundaries (UAX #29)
codepageascii.h ASCII (with transliteration)
codepageisolatin1.h ISO Latin 1 (with transliteration)
codepagewindowslatin1.h Windows Latin 1 (codepage 1252)
codepagemacroman.h Mac Roman
codepagedoslatinus.h DOS Latin US (codepage 437)
codepageshiftjis.h Shift-JIS (codepage 932), about 60 KB of tables

Headers with tables require C++17 (inline variables). unicodebase.h and unicodecodec.h only require C++11.

All functions are in namespace CrossPlatformUnicode. String functions are templates for any 16 bit code unit type (char16_t, wchar_t on Windows, unsigned short), and they work on code points, so surrogate pairs are handled. No function allocates memory: normalization and string conversion first report the required buffer size.

#include "cross-platform-unicode/unicodecase.h"

char16_t text[] = u"\u00E4rger";
CrossPlatformUnicode::toUppercase (text, CrossPlatformUnicode::getLength (text)); // u"\u00C4RGER"

Updating the tables

The files in tables/ are generated by tools/generate-tables.py from the Unicode Character Database and the codecs of the Python standard library. Change UNICODE_VERSION in the script, run it and commit the changed files. ascii-encode.inc, latin1-encode.inc, cp437-*.inc and charset-whitespace.inc are maintained manually.

The unicode-*.inc tables contain data from the Unicode Character Database and are covered by the Unicode License v3.

The cp1252-*.inc, macroman-*.inc and cp932-*.inc tables are generated from the Python codecs, which are based on the vendor mapping files published by Unicode (MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT, CP932.TXT and MAPPINGS/VENDORS/APPLE/ROMAN.TXT).

Testing

test/unicodetest.cpp is a standalone test without dependencies, e.g. c++ -std=c++17 test/unicodetest.cpp && ./a.out.

About

Cross-platform Unicode Library

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages