On Tuesday, 22 January 2019 at 21:49:00 UTC, bauss wrote:
On Tuesday, 22 January 2019 at 19:14:43 UTC, Jonathan M Davis
Is there a reason we cannot implement toStringz like:
immutable(TChar)* toStringz(TChar = char)(scope const(TChar)[]
s) @trusted pure nothrow;
// Couldn't find a way to get the char type of a string, so
"core.sys.windows.windows.winbase",it's implementation is a good
choice.
couldn't make the following generic:
immutable(char)* toStringz(return scope string s) @trusted pure
nothrow;
immutable(wchar)* toStringz(return scope wstring s) @trusted
pure nothrow;
immutable(dchar)* toStringz(return scope dstring s) @trusted
pure nothrow;
For example:
/////////////////////////////////START//////////////////////////////////////
import core.sys.windows.windows;
import std.stdio;
import std.string;
import std.conv;
void main()
{
auto strA_Z ="CD"w;
auto type = GetDriveType((to!wstring(strA_Z[0])~":\\"w).tos);
writeln(to!wstring(strA_Z[0])~" is ",type);
}
private auto tos(wstring str)
{
version (ANSI)
{
writeln("ANSI");
return cast(const(char)*)(str);
}
else
{
writeln("Unicode");
return cast(const(wchar)*)(str);
}
}
private auto tos(string str)
{
version (ANSI)
{
writeln("ANSI");
return cast(const(char)*)(str);
}
else
{
writeln("Unicode");
return cast(const(wchar)*)(str);
}
}
/////////////////////////////////END//////////////////////////////////
It's work ok.