Comment #1 by andrej.mitrovich — 2012-01-04T16:59:06Z
Created attachment 1067
utf
Added implementation to be added to std.conv. These have to be further verified.
Comment #2 by andrej.mitrovich — 2012-01-04T17:00:31Z
Btw, several people have asked for to!(char*)/to!(wchar*)/to!(dchar*) to work, so I've added a simple template overload that forwards to toUTFz. Personally I think this is a good convenience.
Comment #3 by andrej.mitrovich — 2012-10-06T14:45:55Z
Whoa, this has now turned from CT failure to outputting garbage. I'm raising importance of this:
import std.stdio;
import std.conv;
void main()
{
char* cstr = "bla".dup.ptr;
wchar* wstr = "bla"w.dup.ptr;
dchar* dstr = "bla"d.dup.ptr;
writeln( to!string(cstr) ); bla
writeln( to!string(wstr) ); // 972F90
writeln( to!string(dstr) ); // 972F80
}
Comment #4 by andrej.mitrovich — 2012-10-06T14:46:50Z
(In reply to comment #3)
> Whoa, this has now turned from CT failure to outputting garbage.
Technically not garbage but the pointed value is interpreted as an integer.
Comment #5 by andrej.mitrovich — 2013-01-13T10:34:43Z
*** This issue has been marked as a duplicate of issue 8384 ***
Comment #6 by dfj1esp02 — 2014-02-20T10:27:27Z
The example is not good, dup duplicated only 3 chars, so the resulting strings are not null-terminated.
Comment #7 by andrej.mitrovich — 2014-02-20T13:45:37Z
(In reply to comment #6)
> The example is not good, dup duplicated only 3 chars, so the resulting strings
> are not null-terminated.
IIRC these used to be compile-time errors. But yes, \0 is missing.
-----
import std.conv;
import std.stdio;
void main()
{
char* cstr = "foo\0".dup.ptr;
wchar* wstr = "foo\0"w.dup.ptr;
dchar* dstr = "foo\0"d.dup.ptr;
auto x = to!string(cstr);
auto y = to!string(wstr);
auto z = to!string(dstr);
writeln(x); // foo
writeln(y); // memory address
writeln(z); // memory address
}
-----
But nowadays I get the feeling a fromUTFz would be more appropriate.