Titlecase
Modern Objective-C port of title case script by John Gruber and Aristotle Pagaltzis.
Install / Use
/learn @iainc/TitlecaseREADME
Titlecase
Modern Objective-C port of title case script by John Gruber and Aristotle Pagaltzis.
It’s pretty easy to write a non-clever title-casing function. The simplest way is to just capitalize the first letter of every word. That’s not right, though, because it’ll leave you with capitalized small words like if, in, of, on, etc. What you want is something that not only knows not to capitalize such words, but will un-capitalize them if they’re erroneously capitalized in the input.
We originally developed the port for iA Writer 3.1.1. We decided to open source it because we think it woud be useful to others. We’d be happy to see proper title case available in more apps.
Components
NSString+IATitlecase
NSString category which returns a copy of a given string transformed to title case.
IARegularExpressionManager
Regular expressions benefit from proper formatting and comments just like any other code. Double escapes and the lack of multiple line support make inline regular expressions less portable and maintable in Cocoa. This class is intended to be used with strings initialized from a file where you can properly format regular expressions.
imageExpression = {
(?i)
$nameExpression
\.(jpe?g|png|gif)
}
nameExpression = {
(\w+)
}
Expression names and variables must be at least 3 characters long. You should use expressive names. Variables must be separated by a space or enclosed in parentheses.
IARegularExpressionManager is intended to be subclassed. Regular expressions in a string which have matching properties will be set using KVC. A shared instance is recommended to avoid parsing the file again and again.
IATitlecaseRegularExpressionManager and Titlecase.regex
Regular expressions from title case script by John Gruber and Aristotle Pagaltzis. This is a good example of a concrete subclass of IARegularExpressionManager.
NSTextView+IATitlecase
This category adds a “Make Title Case” transform to contextual menu in every NSTextView and NSTextField in your app. Requires Aspects by Peter Steinberger. titlecaseWord: behavior closely follows system methods such as lowercaseWord: and `capitalizeWord:
Tests
Titlecase passes tests from John Gruber, David Gouch, and Aristotle Pagaltzis. Only trimming tests are excluded, because our titlecaseString implementation follows the behavior of system methods such as uppercaseString and capitalizedString.
Supported SDK Versions
Titlecase requires ARC. Tested with iOS 9 and OS X 10.11. Supports iOS 7+ and OS X 10.7+.
License
MIT license. Copyright © 2016 Information Architects Inc.
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
