digitalmars.D.learn - Append wchar enumeration to string
- Nrgyzer (17/17) Nov 21 2010 Hello guys,
- Simen kjaeraas (10/14) Nov 21 2010 The problem is that not all UTF-8 code points fit in one char.
- Nrgzyer (2/2) Nov 21 2010 When I use an string enumeration, I get the following error (dmd1):
- Simen kjaeraas (5/7) Nov 21 2010 Ah, you're using D1. Well, a solution would be to use dchar[] instead
- Steven Schveighoffer (8/20) Nov 22 2010 I'm guessing from the code/error, this is D1. D2 does support appending...
Hello guys, I have an enumeration which contains symbols of different currencies like the following: enum CURRENCY : wchar { DOLLAR = '$', EURO = '¤', YEN = ... } When I try to append it to a string like char[] myString = "Currency: " ~ CURRENCY.DOLLAR I get the following error: "Error: incompatible types for... 'char[]' and 'int'" But... when I try the following: char[] myString = "Currency: " ~ cast(char) CURRENCY.DOLLAR It works, but not for all currencies. What can I do to support all currencies? Thanks for any help.
Nov 21 2010
Nrgyzer <nrgyzer gmail.com> wrote:But... when I try the following: char[] myString =3D "Currency: " ~ cast(char) CURRENCY.DOLLAR It works, but not for all currencies. What can I do to support all currencies?The problem is that not all UTF-8 code points fit in one char. I would recommend in this situation to use a string enum: enum CURRENCY : string { DOLLAR =3D "$", EURO =3D "=E2=82=AC", YEN =3D ... } -- = Simen
Nov 21 2010
When I use an string enumeration, I get the following error (dmd1): CURRENCY base type must be of integral type, not char[]
Nov 21 2010
Nrgzyer <nrgzyer gmail.com> wrote:When I use an string enumeration, I get the following error (dmd1): CURRENCY base type must be of integral type, not char[]Ah, you're using D1. Well, a solution would be to use dchar[] instead of char[]. -- Simen
Nov 21 2010
But for enums I can't use char[] as basetype and when I use cast(dchar) or cast(wchar) I also get "Error: incompatible types for...".
Nov 21 2010
I solved the problem by using toUTF8 from std.utf but I think it's a dirty solution because I have to cast wchar to wchar[] because a simple toUTF8(CURRENCY.DOLLAR) matches wchar[] and dchar[] signatures.
Nov 21 2010
On Sun, 21 Nov 2010 05:58:30 -0500, Nrgyzer <nrgyzer gmail.com> wrote:Hello guys, I have an enumeration which contains symbols of different currencies like the following: enum CURRENCY : wchar { DOLLAR = '$', EURO = '�', YEN = ... } When I try to append it to a string like char[] myString = "Currency: " ~ CURRENCY.DOLLAR I get the following error: "Error: incompatible types for... 'char[]' and 'int'"I'm guessing from the code/error, this is D1. D2 does support appending different width characters to dchar[], I'm not sure about appending wchar to a char[] though. I don't think D1 has such support. It also doesn't have support for enums as strings, so I think you may just have to create a function that returns a char[], given a wchar. -Steve
Nov 22 2010