www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - About variadic in functions and dstring type

reply Lorenzo Villani <arbiter arbiterlab.net> writes:
Hi, I want to modify or extend std.stdio.writefln in order to support (for
example) a String object.. i.e.: I would like to be able to do something like
that

String s = new String("Hello World");
writefln(s);

I thought that it should be possible by writing some sort of wrapper around the
original writefln which scans the _arguments array and if an argument is a
String object it does an in-place substitution of the argument to a standard D
string type printable by writefln.

Now let's come to my 2nd question: what are dchar and dstring and their
differences from char[] (or wchar[]) ?

Thanks in advance
Lorenzo "Arbiter" Villani
Jan 22 2008
parent reply torhu <no spam.invalid> writes:
Lorenzo Villani wrote:
 Hi, I want to modify or extend std.stdio.writefln in order to support (for
example) a String object.. i.e.: I would like to be able to do something like
that
 
 String s = new String("Hello World");
 writefln(s);
 
 I thought that it should be possible by writing some sort of wrapper around
the original writefln which scans the _arguments array and if an argument is a
String object it does an in-place substitution of the argument to a standard D
string type printable by writefln.

You just need to define a toString() method for your class, then writefln will automatically call that.
 
 Now let's come to my 2nd question: what are dchar and dstring and their
differences from char[] (or wchar[]) ?

dchar is a 32-bit type, for storing a UTF-32 code unit. dstring is an array of dchar, in other words a UTF-32 string. wchar and wstring are for UTF-16.
Jan 22 2008
next sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 1/22/08, torhu <no spam.invalid> wrote:
 dchar is a 32-bit type, for storing a UTF-32 code unit.  dstring is an
 array of dchar, in other words a UTF-32 string.  wchar and wstring are
 for UTF-16.

What dstring is varies from version to version of D, but it's always the correct type to use for strings. In D1.x, dstring is an alias for dchar[] In early D2.x, dstring was an alias for const(dchar)[] In current D2.x, dstring is an alias for invariant(dchar)[]
Jan 22 2008
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 1/22/08, Janice Caron <caron800 googlemail.com> wrote:
 What dstring is varies from version to version of D, but it's always
 the correct type to use for strings.

Sorry, I meant, for UTF-32 strings.
Jan 22 2008