On 7/13/2011 12:07 PM, Jonathan M Davis wrote:
On Wednesday 13 July 2011 11:56:10 Tyro[a.c.edwards] wrote:
Methinks function local imports (introduced in 2.054) is a great idea,
however if it is to be allowed, I believe it should provide all the
functionality of global imports: which it currently does not.
import std.stdio;
import std.string;
import std.conv;
// Note: all of these import formats work if imported here but only
// the first work if imported locally to the function.
//import std.utf;
//import std.utf: toUTF16z;
//import std.utf: wcp = toUTF16z;
void main()
{
auto s = "漢字を書くのはどうかな~?";
auto s1 = genText(s);
writeln(to!string(typeid(s1)));
}
auto genText(string t)
{
import std.utf; // This works
//import std.utf: toUTF16z; // This doesn't
//import std.utf: wcp = toUTF16z; // Neither does this
version(Unicode)
{
// Note: Everything here works with global import
// but only the first line works with function local imports
return toUTF16z(t); // This works
//return t.toUTF16z; // This doesn't
//return wcp(t); // Neither does this
//return t.wcp; // Or this
}
else
{
return t.toStringz;
}
}
import std.utf: toUTF16z;
is broken to begin with:
http://d.puremagic.com/issues/show_bug.cgi?id=314
http://d.puremagic.com/issues/show_bug.cgi?id=5161
Rather than just importing the symbol like it should, a selective import
essentially create a new symbol. So, that's probably why it doesn't work when
importing inside of a function.
IC, thanks for the response/info... Now I know!
[OT - toUTFz]
Wasn't there discussion about adding toUTFz to the std.utf? For some
reason I thought that was forthcoming in 2.054... whatever happened there?
It hasn't been merged in yet. It should be in 2.055.
https://github.com/D-Programming-Language/phobos/pull/123
- Jonathan M Davis
Got it. Thanks again.