Skip to content

Add String.titlecase/2 #10008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ukrbublik
Copy link
Contributor

@ukrbublik ukrbublik commented Apr 30, 2020

String.titlecase/2 is similar to String.capitalize/2 but it doesn't downcase the rest of the string.

Closes #9999

@josevalim josevalim merged commit 3be3afb into elixir-lang:master Apr 30, 2020
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

josevalim added a commit that referenced this pull request Apr 30, 2020
Unicode says "HH" is not titlecased, which means we need
to downcase the rest of the string, which is the behaviour
we already have in capitalize.

This reverts commit 3be3afb.
@ukrbublik
Copy link
Contributor Author

ukrbublik commented Apr 30, 2020

@josevalim

Unicode says "HH" is not titlecased, which means we need
to downcase the rest of the string, which is the behaviour
we already have in capitalize.

According to this, titlecase differs from uppercase.
There are special chars, eg.
dž (lowercased) -- Dž (titlecased) -- DŽ (uppercased)
So we need to have titlecase function.
Maybe it should work with grapheme instead of binary?

@ukrbublik
Copy link
Contributor Author

Or it should work with binaries but in more smart way - for each word in string.
However there are caveats, like:
"In Search of Sunrise" - we shouldn't titlecase "of" to "Of"
"McDonalds" - not "Mcdonalds"
"O'Brien" - not "O'brien"

@harrisi
Copy link
Contributor

harrisi commented Jun 28, 2024

Sorry for bringing this old PR up, but, did this never make it into a release?

@NickNeck
Copy link
Contributor

@harrisi the merged PR was reverted, see above.

@kipcole9
Copy link
Contributor

I have a lib that implements the Unicode case folding algorithm should you need it (it also does locale specific case folding and other stuff): https://hexdocs.pm/unicode_string/readme.html#case-mapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add String.titlecase/2
5 participants