# text.normalise-name
Tidies a personal name typed into a form: " JOHN o'neill-MCDONALD " becomes
"John O'Neill-McDonald". It is for display and for comparing records, not for
deciding what someone's name "really" is.
## What it does
1. Trims, and collapses every run of whitespace to one ASCII space.
Whitespace is the Unicode White_Space set, listed explicitly so all three
languages agree (tab, line feed, vertical tab, form feed, carriage return,
space, U+0085, U+00A0, U+1680, U+2000-U+200A, U+2028, U+2029, U+202F,
U+205F, U+3000).
2. Leaves alone any word typed in **mixed case**. "DiCaprio", "MacKenzie",
"DeVito" and "Ludwig Van Beethoven" come back exactly as
typed. Someone who typed their own capitals knows better than a rule. Only
words that are all upper case or all lower case are recased.
3. Title-cases each single-case word: the first letter upper case, the rest
lower case, restarting after a hyphen, an apostrophe (' or ’) and a full
stop, so "mary-jane" is "Mary-Jane", "o'neill" is "O'Neill", "d'arcy" is
"D'Arcy" and "J.R.R." stays "J.R.R.".
4. **Mc**: a part starting "mc" gets a capital after it: "McDonald",
"McArthur".
5. **Mac**: a part starting "mac" and at least six letters long gets a
capital after it ("MacDonald", "MacIntyre"), except for a short list of
names where "mac" is not a prefix: Macari, Macaulay, Macedo, Macey,
Machado, Machell, Machen, Machin, Macias, Mackay, Mackey, Mackie, Mackin,
Macklin. Shorter words ("Mack", "Macon") are never changed.
6. **Particles**: van, von, de, da, di, del, della, der, den, des, du, la, le,
ter, ten, dos, das, do, bin and ibn are written in lower case when they are
a whole word that is neither the first nor the last: "Ludwig van
Beethoven", "Juan de la Cruz". As the first word they are capitalised
("Van Morrison").
## Honest limits
No rule gets every name right, and this one will be wrong for somebody. The
Mac rule is a heuristic: "Mackenzie" becomes "MacKenzie", which some
families spell and some do not, and a Mac-name missing from the exception
list will gain a capital it should not have. Particles are capitalised by
some families ("Dick Van Dyke") and not by others. Irish and Scottish Gaelic
forms ("Mac an tSaoir", "Ó Briain" as two words) and Arabic "al-" names are
not specially handled. Mixed-case words are trusted, so a genuinely mistyped
"jOHN" is kept too. The mixed-case rule is the escape hatch: store what the
person typed if they typed capitals, and show them the normalised form to
confirm rather than silently rewriting it.
## Letters outside ASCII
Upper and lower case come from each language's own per-character Unicode
mapping, used only when a character maps to exactly one character: "Ç" and
"ç", "Ë" and "ë", Greek and Cyrillic all work. Characters whose case mapping
would change the length ("ß" upper-cases to "SS", "İ" lower-cases to two code
points) are left as they are, which keeps the three languages identical.
Greek final sigma is not produced: an all-capitals Greek name ending in "Σ"
comes back ending in "σ", not "ς".
The input must be a string; anything else is an error.