On Mon, 24 Dec 2012 12:00:05 -0000, Red <resm...@lavabit.com> wrote:

On Sunday, 23 December 2012 at 16:20:47 UTC, Mike Wey wrote:


If you declare an char array you could pass it's pointer and length as the first two arguments.

char[] buff = new char[1024];
fgets(buff.ptr, buff.length, someStream);
buff = buff[0 .. strlen(buff)];

Thanks, that does work (buff.length has to be cast to an int). Which is surprising. I would have thought that a char[] in D would not equate to a char array in C since the D char's are UTF-8, and that a byte[] would have to be used (byte[] also works with a cast).

Technically you're more or less correct :)

But, if your input is all ASCII then as ASCII is a subset of UTF-8 it "just works". If however your input is not ASCII, but say Chinese characters in a different encoding/locale then it will go "bang!" at some point, probably when you try to write it back to the screen or foreach over it.

Using ubyte[] is the technically correct method IMO. Then in a perfect world you'd call a method to convert that ubyte[] from it's known (has to be known or detectable somehow) encoding into UTF-8 for use in your D code.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to