nalgeon / sqlean

The ultimate set of SQLite extensions
MIT License
3.65k stars 115 forks source link

Unicode's hidden `title` function #126

Closed christippett closed 1 month ago

christippett commented 1 month ago

I've been on the lookout for an extension that would allow for converting text to title case. I was intrigued to find that alongside upper and lower in the unicode library, there's also a title function defined (albeit commented out).

I tried compiling the extension with SQLITE3_UNICODE_TITLE enabled, however the resulting functionality doesn't work as intended – all it does is convert everything to uppercase (probably why it's commented out!).

I appreciate it's likely to be far down your list of priorities, but is there any chance we might see this functionality resurrected and included in a future sqlean release?

nalgeon commented 1 month ago

Yes, I plan to review the unicode extension and change the underlying implementation to enable the title function. Probably later this year.

christippett commented 1 month ago

Brilliant! Thanks for the update, I look forward to it.

nalgeon commented 1 month ago

As of 0.25.0 you can use the text_title function from the text extension:

select text_title('cómo estás');
-- Cómo Estás

Please give it a try.

christippett commented 1 month ago

Works well from my limited testing. I added the following two test cases to my local fork, the first passes but the second fails. Other title() implementations also don't handle this second case, so it's not unexpected.

select '27_07', text_title('conan o''brien') = 'Conan O''Brien';
select '27_08', text_title('ronald mcDonald') = 'Ronald McDonald';
nalgeon commented 1 month ago

Thanks for trying! text_title will capitalize the characters on word boundaries and lowercase the rest. In mcDonald there is no word boundary before d, hence Mcdonald.