On Friday, 21 September 2018 at 12:15:52 UTC, NX wrote:
How can I properly convert a character, say, first one to upper
case in a unicode correct manner?
In which code level I should be working on? Grapheme? Or maybe
code point is sufficient?
There are few phobos functions like asCapitalized() none of
which are what I want.
----------
import std.conv : to;
import std.stdio : writeln;
import std.string : capitalize;
import std.utf : decode;
size_t index = 1;
size_t oldIndex = index;
auto theString = "hëllo, world";
auto firstLetter = theString.decode(index);
auto result = theString[0 .. oldIndex] ~
capitalize(firstLetter.to!string) ~ theString[index .. $];
writeln(result);
----------
(This could be a lot prettier, but this seems to basically work)