Rename std.string.toStringz?

Timon Gehr timon.gehr at gmx.ch
Mon Jun 20 12:49:50 PDT 2011


Andrej Mitrovic wrote:
> We could use std.conv.to to convert strings to char pointers and
> vice-versa, however I know of at least two functions which have
> different semantics which complicate things:
>
> std.string.toStringz only appends a null and returns the pointer,
> std.windows.charset.toMBSz converts the string to the Windows 8-bit
> charset and then appends the null and returns the pointer.
>
> So what would to!(char*)(str) do?
>
> The opposite, which currently works:
> to!(string)(charPtr);
>
> assumes the char pointer is just a null-terminated string. IIRC there
> were bugs in std.registry that were recently fixed where
> to!string(char*) was used instead of the fromMBSz function.
>
> So assuming to!() will always do the right thing could be a bad idea.

Using char to hold anything different from an UTF8 code point is a bad idea.
It is like using a pointer to store an integer value.

Cheers,
-Timon


More information about the Digitalmars-d mailing list