UTF-8 char and write(f)ln

Ali Çehreli acehreli at yahoo.com
Wed Mar 5 21:26:32 UTC 2025


On 3/5/25 11:59 AM, Vindex9 wrote:
 > On Wednesday, 5 March 2025 at 17:56:25 UTC, Ali Çehreli wrote:
 >> It shouldn't and does not work in my environment (both inside an Emacs
 >> buffer and inside a Linux terminal).
 >

The program just outputs characters to its stdout. One way to see this 
process is to redirect 'stdout' to a file:

$ my_program > my_output

Then, when you open file 'my_output' in a hex editor, you should see 
that the program did output just a single char with value e.g. 132. 
There are no other UTF-8 characters right after it, so I wouldn't expect 
'τ' to be formed on the output.

 > I used Terminator. I tried other terminal emulators and they behaved
 > differently (output unrecognized bits of characters as question marks).
 > Apparently Terminator has some weird buffering.

They probably keep state for Unicode characters but don't reset it. (I 
don't know whether they are required to.) Could you please try the 
following program to see whether it prints τ for all tau arrays below?

import std.stdio;
import std.algorithm;

void main() {
     char[][] taus = [ [ 207, 132 ],
                       [ 207, 0, 132 ],
                       [ 207, 'a', 132 ] ];

     foreach (i, tau; taus) {
         write(i, ": ");
         tau.each!(write);
         writeln();
     }
}

For me, only the first one is a τ in a Unicode environment. You may see 
3 taus under Terminal.

 > Sorry to bother you.

Not at all! I assume everybody here finds these topic very interesting 
like I do. :)

Ali



More information about the Digitalmars-d-learn mailing list