- Is this safe? - 5 Updates
| Muttley@dastardlyhq.com: Feb 20 04:45PM It occured to me that I don't actually know the answer. It works, but will it always work? Could it crash certain string implementations? std::string s = "hello"; for(auto &c: s) c = toupper(c); std::cout << s << std::endl; |
| Bonita Montero <Bonita.Montero@gmail.com>: Feb 20 06:34PM +0100 > std::string s = "hello"; > for(auto &c: s) c = toupper(c); > std::cout << s << std::endl; Why should this not work ? |
| Chris Vine <vine24683579@gmail.com>: Feb 20 11:16AM -0800 On Monday, 20 February 2023 at 17:33:38 UTC, Bonita Montero wrote: > > for(auto &c: s) c = toupper(c); > > std::cout << s << std::endl; > Why should this not work ? The problem is that UTF-8 is now more or less ubiquitous for narrow strings and std::toupper only works for UTF-8 strings guaranteed to be in the ASCII subset. Apart from the fact that in UTF-8, any one unicode code point can require between 1 and 5 bytes (code units) to encode it, upper and lower case representations can occupy different numbers of code points. Since you are in Germany, one example is the esszet (ß), which is one code point in lower case but two code points in upper case (SS or SZ) by old/traditional orthography. |
| Bonita Montero <Bonita.Montero@gmail.com>: Feb 20 09:39PM +0100 Am 20.02.2023 um 20:16 schrieb Chris Vine: > The problem is that UTF-8 is now more or less ubiquitous for narrow > strings and std::toupper only works for UTF-8 strings guaranteed to > be in the ASCII subset. Muttley didn't talk about UTF-8. But toupper() also works with UTF-8. |
| Chris Vine <vine24683579@gmail.com>: Feb 20 12:56PM -0800 On Monday, 20 February 2023 at 20:38:09 UTC, Bonita Montero wrote: > > strings and std::toupper only works for UTF-8 strings guaranteed to > > be in the ASCII subset. > ... But toupper() also works with UTF-8. You are ill informed. It only works for the ASCII subset of UTF-8. |
| You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment