3 ms·
That article contained this text and code: Many developers believe that that a case-insensitive comparison is achieved by mapping both strings being compared t
by unwind 7y ago
That article contained this text and code:
Many developers believe that that a case-insensitive comparison is achieved by mapping both strings being compared to either upper- or lowercase and then comparing the resulting bytes. The existence of functions such as ‘strcasecmp’ in some C libraries, for example, or common examples in programming books reinforces this belief:
if (strcmp(toupper(foo),toupper(bar))==0) { // a typical caseless comparison
which I guess should be C, but makes no sense at all. The standard functions toupper() and tolower() operate on single characters, not strings. Modifying entire strings in place and returning them also seems odd.
Also the text leading up to the code talks about strcasecmp(), but the code doesn't use it, and claims the existance of strcasecmp() proves that people like to smash the case of strings before comparing them. Of course, strcasecmp() is the exact opposite, it just does a case-insensitive comparison and doesn't say anything about how that is achieved.
Very confusing.
- rurban 7y agoIt is not defined in any standard. wcscmp, wcsfc and wcsnorm are missing. They should follow the unicode rules. And not be locale run-time dependent, only config-time. And then this wchar_t turkey in the standard which no-one needs at all. We need an u8* API only, nothing else. The next C standard deliberately did nothing on all big open issues. Not even constexpr which is broken in gcc. It's not confusing, it's just a huge mess.