Mercurial > projects > ldc
annotate lphobos/std/stdio.d @ 21:8d45266bbabe trunk
[svn r25] * Fixed a lot of problems with string literals
* Fixed slice-slice copying assignment
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 07:01:15 +0200 |
parents | c05ef76f1c20 |
children | a6360e68134a |
rev | line source |
---|---|
18 | 1 module std.stdio; |
2 | |
3 void _writef(T)(T t) { | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
4 static if(is(T: Object)) _writef(t.toString()); else |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
5 static if(is(T==char)) _writef("%c", t); else |
18 | 6 static if(is(T: char[])) printf("%.*s", t.length, t.ptr); else |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
7 static if(isArray!(T)) { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
8 _writef('['); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
9 if (t.length) _writef(t[0]); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
10 for (int i=1; i<elem.length; ++i) { _writef(','); _writef(t[i]); } |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
11 _writef(']'); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
12 } else |
18 | 13 static if(is(T==int)) printf("%i", t); else |
14 static assert(false, "Cannot print "~T.stringof); | |
15 } | |
16 | |
17 void writef(T...)(T t) { | |
18 foreach (v; t) _writef(v); | |
19 } | |
20 void writefln(T...)(T t) { | |
21 writef(t, "\n"[]); | |
22 } |