toString vs. toUtf8
Sean Kelly
sean at f4.ca
Mon Nov 19 16:25:52 PST 2007
Steven Schveighoffer wrote:
>
> I'd say use toUtf8 when doing a conversion from one type of encoded string
> to another (i.e. utf-16 to utf-8), and use toString when overriding Object's
> toString, OR when converting a native type (i.e. int, float, etc). For
> example tango.text.convert.Integer.toUtf8 should be toString.
>
> In the case of tango.text.convert.Layout, I don't see any overriding of
> Object.toUtf8? The Unicode.toUtf8 should be left alone since it is a
> conversion between utf encodings. In any case, Unicode.toUtf8 is a global
> function, and is not overriding Object.toUtf8, so there is no conflict
> there.
There's no conflict, it's just more difficult to understand. Also, in
template code, having a consistent rule for overloaded functions can be
a valuable asset. I found myself wanting to simply change everything to
toString, toWString, and toDString rather than change only the Object
member function as originally planned. And the conflict with other
encodings worried me so I posted here.
Sean
More information about the Digitalmars-d
mailing list