This is my take on an improved Title Case function. As you know the Title case option of StringUpper/Lower commands is not ideal as it doesn't take into account the many exceptions AHK -> Ahk and AutoHotkey -> Autohotkey for example.
This function makes use of an INI file so you can setup a number of rules for various languages or you can simply use different INI files for specific projects. If an INI file is not present a default one is created (more to illustrate how to use it). If you have examples for non-English INI setups feel free to post. Other suggestions also welcome of course. (This will be part of a future Lintalist update, but thought it was useful to share and also gather some feedback before doing so - perhaps the INI should also include some RegExReplace codes for example).
ExamplesDocumentation:
Options:
- Text sentence to convert to TitleCase
- lang language to use (reads from ini), default "en" for English
- ini ini file to use, default "TitleCase.ini". If there is no INI present in A_ScriptDir it will create a default one ("en" only)
The text is transformed first to AutoHotkey Title case format.
After that several functions are called to process exceptions in the order as outlined below in the INI setup.
Ini setup - all keys are CSV lists:
[lang]
LowerCaseList= words you would prefer to have lowercase: a,and,is,the,etc [1]
UpperCaseList= words you would prefer to have uppercase: AHK,IBM,UK
MixedCaseList= words you would prefer to have MixedCase: AutoHotkey,iPhone
ExceptionsList= [2]
AlwaysLowerCaseList= final check to ensure that any of the actions above haven't transformed specific words
[1] Also does RegExReplace(Text, "im)([’'`])s","$1s") ; to prevent grocer'S
[2] Also does RegExReplace(Text, "im)[\.:;] \K([a-z])","$U{1}") ; first letter after .:; uppercase
The ini file can have multiple [sections] for speficic languages - you can also use multiple INI files
In : autohotkey voted best scripting language in the world: IBM survey
Out: AutoHotkey Voted Best Scripting Language in the World: IBM Survey
In : the QUICK BROWN fox jumps over the lazy dog
Out: The Quick Brown Fox Jumps over the Lazy Dog
In : Get help with using AutoHotkey and its commands and hotkeys
Out: Get Help with Using AutoHotkey and its Commands and Hotkeys
In : Post your working scripts, libraries and tools
Out: Post Your Working Scripts, Libraries and Tools
In : Helpful script writing tricks and HowTo's
Out: Helpful Script Writing Tricks and Howto's
In : Discuss features, issues, about Editors for AHK
Out: Discuss Features, Issues, About Editors for AHK