satoru
How to check if a Unicode codepoint represents a letter or an uppercase letter?
I’m working on the “Bob” exercise on the Elixir Track in Exercism.
I am testing for uppercase letter with this simple check: c in ?A..?Z, but one of the test cases requires that Unicode uppercase letters be handled.
I’ve Googled a little bit and couldn’t found anything useful. An answer on Stackoverflow suggested to use regular expression on the string. I wonder if there’s anything as simple as Unicode.is_upper? in the standard library.
Most Liked
malaire
Perhaps check if Unicode.category/1 returns :Lu.
EDIT: Just noticed that there is also Unicode.uppercase?/1 which does this exact check.
LostKobrakai
I was about to suggest ex_unicode as well, but given the nature of this being an exercise I doubt they expect people to use an external dependency.
egze
Just a hint, I don’t think you need to check every codepoint individually, but instead try to work with the whole string input and just the String module.
malaire
Unicode is from ex_unicode package.
Alternatively if you want to stay with standard library, check out Regex character classes which include alpha and upper.
Dusty
When I first solved Bob, I did so entirely with the Regex module. One of the comments my mentor made, was that, although Bob can be solved many ways, the intent of this exercise (on the Elixir track) is to get you familiar with the String module. I was encouraged to return to the String module, and solve the exercise without using any regexes at all. The solution I came up with turned out to be much more elegant than the regex solution, and indeed required only functions from String.
Here is a hint to get you started: Under what conditions would the uppercase version of a string be the same as the original? Are there other relationships like this you can leverage?







