A popular but wrong way to convert a string to uppercase or lowercase
111–120 of 272 posts
Re: A popular but wrong way to convert a string to uppercase or lowercase
#112Earlier quoted context omitted.
Python's strings have uppercase, lowercase and case-folding methods that don't choke on this. They don't use UTF-16 internally (they can use UCS-2 for strings whose code points will fit in that range; while a string might store code points from the surrogate-pair range, they're never interpreted as surrogate pairs, but instead as an error encoding so that e.g. invalid UTF-8 can be round-tripped) so they're never worr…
But that's wrong. The upper case for ß is ẞ.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#113He gave 4 examples of how it's done incorrectly, but zero actual examples of doing it correctly.
> If you need to perform a case mapping on a string, you can use LCMapStringEx with LCMAP_LOWERCASE or LCMAP_UPPERCASE, possibly with other flags like LCMAP_LINGUISTIC_CASING. If you use the International Components for Unicode (ICU) library, you can use u_strToUpper and u_strToLower.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#114He gave 4 examples of how it's done incorrectly, but zero actual examples of doing it correctly.
for (int i = 0; i
Jokes aside, I was kinda hoping for a good answer that doesn't rely on a Windows API or an external library, but I'm not sure there is one. It's a rather complex problem when you account for more than just ASCII and the English language.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#115Earlier quoted context omitted.
I'm referring to the people who call case conversion in general "a simple text operation". Say you have an std::string and you want to make it lower case. If you assume it contains just ASCII that's a simpler operation than if you assume it contains UTF-8, but C++ doesn't provide a single function that does either of them. A person can rightly complain that the former is a basic functionality that the language should…
For ascii in C++ isn't there std::tolower / std::toupper? If you're not dealing with unsigned char types there isn't a simple case conversion function, but that's for a good reason as the article lays out.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#116As always, Raymond is right. (And as usually, I could guess it's him before even clicking the link.) That said, 99% time when doing upper- or lowercase operation you're interested just in the 7-bit ASCII range of characters. For the remaining 1%, there's ICU library. Just like Raymond Chen mentioned.
I think it's more the exact opposite.
The only times I'm dealing with 7-bit ASCII is for internal identifiers like variable names or API endpoints. Which is a lot of the time, but I can't ever think of when I've needed my code to change their case. It might literally be never.
On the other hand, needing to switch between upper, lower, and title case happens all the time, always with people's names and article titles and product names and whatnot. Which are never in ASCII because this isn't 1990.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#117Man, I'm happy we don't need to deal with this crap in Rust, and we can just use String::to_lowercase. Not having to worry about things makes coding fun.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#118Earlier quoted context omitted.
Ah, i see, we disagree on what is "human language". An abbreviation like HTML and it's different capitalisations to me sound a lot like a feature of human language.
Is this a serious argument? Humans don't directly use HTML to communicate with each other. It's a document markup language rendered by user agents, developed against a specification.
And to GP, SGML/HTML actually has a facility to define uppercasing rules beyond ASCII, namely the LCNMSTRT, UCNMSTRT, LCNMCHAR, UCNMCHAR options in the SYNTAX NAMING section in the SGML declaration introduced in the "Extended Naming Rules" revision of ISO 8879 (SGML std, cf. https://sgmljs.net/docs/sgmlrefman.html). Like basically everything else on this level, these rules are still used by HTML 5 to this date, and in particular, that while elements names can contain arbitrary characters, only those in the IRV (ASCII) get case-folded for canonization.
Re: A popular but wrong way to convert a string to uppercase or lowercase
#119Earlier quoted context omitted.
But that's wrong. The upper case for ß is ẞ.
That was only adopted in Germany like 7 years ago!
Re: A popular but wrong way to convert a string to uppercase or lowercase
#120Earlier quoted context omitted.
Incorrect. ẞ is still a thing.
Going by what you and the grandparent wrote, it's not just a thing, but two different things: ẞ ß It is probably time for an Esperanto advocate to show up and set us all straight.
What are you talking about? In Esperanto, one letter equals one sound.