[D-runtime] localized readln() reads nothing in MS Windows console application

Andrei aalub at mail.ru
Fri Dec 29 11:41:03 UTC 2017

Since D language proclaims using Unicode in string type it seems 
natural that the following statement reading localized input 
(say, Russian) throws exception "std.utf.UTFException... Invalid 
UTF-8 sequence":

auto response=readln().strip();

because the result is ubyte[] containing raw values above 127 
unconverted to UTF8.

Experienced programmers advise to use SetConsoleCP(65001) Windows 
function to set up console application, which seems to be the 
solution, but it brings an unexpected result: while the user 
feeds the readln() function with ASCII (below 128) input it works 
perfect, and when [s]he inputs localized text - it returns empty 
line and any consequent readln()s do not wait for user's input 
and immediately return empty string too.

It seems to me a runtime function issue - or do I something wrong?

More information about the D-runtime mailing list