Hi guys.
I recently made a request to implement functionality for GLib, creating a title function just like it has in python. However, I was instructed by the maintainers to open a discussion here on the GNOME Discourse. I made a small implementation of this function, for me it works correctly. I would like to know if the community thinks it is viable to have this functionality in GLib, if the code I made is correct or needs improvement. Please leave your comments and criticisms on the subject, so that we can have feedback on the topic in question.
Iām a bit confused here: you mention you want to implement a title() function, but then some of the functions in your code block are about clearing whitespace for some reason.
In general: +1 for having a ātitlecaseā API for strings in GLib (I could actually use this in some projects at least).
Btw, if there is an issue/MR on GitLab which contains prior discussion, it might make sense to link to that in your post
Sorry, I think thatās too specific to what a particular application would want (and also very hard to do correctly for every locale). If you can show that the same implementation of title casing would be useful for three or more applications (see CONTRIBUTING.md), then please re-open this issue. Thanks.
That response still stands ā converting strings to title case is very use-case specific (why would an application want to do it; on what kind of strings; to produce what kind of title case) and would be hard to get working across multiple locales. Applications with specific use cases may be able to avoid that difficulty perhaps by ignoring non-Western-European locales (depending on their use case and target audience, Iām not advising it though). GLib canāt, so any implementation in GLib would have to do something appropriate for all locales.
To be clear, adding this functionality would need a very strongly evidence-backed proposal of how it would make several application authorsā lives easier, and would need to come with an implementation which can be shown to make sense for all locales.
Hello everyone, anyone can use this code if they want. In my case I have several input fields for the user, and I donāt want the data entered to look like this:
` my name is danilo.ā several blank spaces
This illustrates my point well: the code youāve posted will actually generate the string My Name Is Danilo. (note the capitalised āIsā). Typically title case in English will keep short words and connectives (āisā, āorā, āandā, etc.) in lowercase, though; and thatās where it becomes difficult to implement in a way that works for every locale and every use-case.
This kind of string manipulation is too specific to a single use-case to be in GLib.
This is imo a bit beyond the unicode functionality that glib can and should provide out of the box. We have case conversion and case properties for individual characters, and we have breaking properties. But the actual Unicode break algorithm (TR14) is implemented in pango.