Warning: this (and uppercase_first()) relies on no libc (glibc, BSD libc, MSVC crt) supporting letters that expand or contract, like German ß (-> SS) upon capitalization / lowercasing. This is mostly a fault of the API -- there's no way to return two characters in one code point. Also, all characters must have the same length in bytes before and after lowercasing, all platforms currently have this
| 86 | // A non-hacky version would be slower for no gain other than sane code; at |
| 87 | // least unless you use some more powerful API. |
| 88 | string lowercase_first(string s) |
| 89 | { |
| 90 | char32_t c; |
| 91 | if (!s.empty()) |
| 92 | { |
| 93 | utf8towc(&c, &s[0]); |
| 94 | wctoutf8(&s[0], towlower(c)); |
| 95 | } |
| 96 | return s; |
| 97 | } |
| 98 | |
| 99 | string uppercase_first(string s) |
| 100 | { |
no test coverage detected