3 ms·
Good job! Simple and pretty elegant. Just curious, is there a reason to use wide-character versions of isdigit, isalnum etc. and pass there single UTF-8 byte?
by tonygluk 4y ago
Good job! Simple and pretty elegant.
Just curious, is there a reason to use wide-character versions of isdigit, isalnum etc. and pass there single UTF-8 byte? `iswdigit(cdpt(txt))` would seem more logical to me than `iswdigit(txt[0])`.
- torstenvl 4y agoThanks! And good catch, it's fixed now. I found something interesting while trying to add a test case. I had to come up with something that would fail iswalnum() in ranges above 128, and I knew Japanese has its own punctuation marks, so I tried that. However, apparently, iswxxxxx is broken for East Asian languages and Arabic in macOS's system library (including with locale set to, e.g., ja_JP.UTF-8). There are characters for which iswalpha, iswcntrl, iswdigit, iswpunct, and iswspace are all false, in violation of the standard. For the purposes of testing my library (rather than underlying OS locale support), I ended up going with Armenian, but it's a disappointing issue nonetheless. I may have to roll my own at some point.
- tonygluk 4y agoI'm not sure that complete reliability in this matter can be achieved without dragging ICU into a project, which is a mildly depressing thought.