Normalization and case

The same text can be encoded more than one way, and text that differs only in case often has to compare equal. normalize.h and case.h cover both. Each is an optional component, on by default; see Build options.

Normal forms

"é" is one code point, or "e" followed by a combining acute accent. muniNormalize puts text into one of the four normal forms of UAX #15: NFC and NFD for canonical equivalence, NFKC and NFKD also folding compatibility characters such as ligatures and full-width letters. Store and compare text in NFC.

muniCheckNormalization tells quickly whether text is already in a form: yes, no, or maybe (only normalizing tells). Most text already is, which saves the copy.

muniDecomposePair and muniComposePair work on single code points one level deep, the way shapers ask for them. muniGetDecomposition gives a code point's full NFD or NFKD, every mapping applied; an array of MUNI_MAX_DECOMPOSITION code points always holds it.

Case

muniConvertCase lowercases, uppercases, titlecases or case folds text with the full mappings, which may change the length ("ß" uppercases to "SS"), and with the context rule of the final sigma. Titlecasing finds words by the word boundaries of UAX #29. A language selects extra rules:

muniGetLowercase, muniGetUppercase, muniGetTitlecase and muniFoldCase are the simple mappings of one code point; muniIsCased tells whether a code point has case.

Comparing strings

To compare strings without regard to case, fold both and compare the results. To compare them as users see them, as UAX #31 compares identifiers, use muniGetNfkcCasefold: it folds case, turns compatibility forms into their plain selves, drops default ignorables such as a soft hyphen or a zero width space, and puts the result in NFC. It needs both components.

size_t keyLength = 0;
muniTextResult result =
    muniGetNfkcCasefold(name, length, muni_convertStrict, key, sizeof(key), &keyLength);
// "Alice", "ALICE", a full-width "ALICE" and "Al" + soft hyphen + "ice"
// all get the key "alice".

Not obvious