| |
| Posted by David L. Davis | PermalinkReply |
|
David L. Davis
| Recently I've been trying to expand my ( bright :)) ) horzions beyond the char[] 8-bit universe, and use "D" to write code that's more useful to the "D" International Community by using wchar[]s. Which just a few months ago, I had decided to change to "D" as my secondary programming language from "C", because of its fantastically simple use of build-in strings, its minimum need for pointers, and while still retaining the "Full Power of C!!" ( Great Language Walter! )
But sadly, it seems that D's concatenation symbol (~) doesn't treat wchar[] and dchar[] as equal citizens with char[], below are a few examples:
# int main()
# {
# char[] sDynStr = "";
# wchar[] wsDynStr = "";
# dchar[] dsDynStr = "";
#
# // This works
# sDynStr = "Initializing to 8-Bit";
# wsDynStr2 = "Initializing to 16-Bit";
# dsDynStr2 = "Initializing to 32-bit";
#
# // This always works
# sDynStr = "This is" ~ " a test!";
#
# // But when I use the ~ operator it forces
# // the 2nd literal string to a char[]
# // thus causing the "cannot implicitly convert
# // expression "This is a test!"
# // of type char[15] to wchar[]" error.
# wsDynStr = "This is" ~ " a test!";
# dsDynStr = "This is" ~ " a test!";
#
# // This works - forced to cast() each literal string
# wsDynStr = cast(wchar[])"This is" ~ cast(wchar[])" a test!";
# dsDynStr = cast(dchar[])"This is" ~ cast(dchar[])" a test!";
#
# // This works - - forced to cast() a literal string with (x)s
# wsDynStr = cast(wchar[])( "This is" ~ " a test!" );
# dsDynStr = cast(dchar[])( "This is" ~ " a test!" );
#
# return 0;
#
# } // end int main()
It would sure be great it if we had the w"This is" ~ w" a test!" and d"This is"
~ d" a test!" that Jill had mentioned in one of her many Unicode posts...this
would truly make for cleaner code, and to help equal things out a bit between
the three character types. Also it would be nice, if the w"" and
d"" were to be added to "D", that they would also work well with the r"\", maybe
as wr"\" and dr"\".
Plus there are many other issues beyond the core language, when you're trying to use Phobos runtime functions with wchar[] or dchar[], but I think we need to start focusing on how to fix the problem first in core langauge, and then worry about the runtime library.
If I'm totally off my rocker, I'm sure someone here will let me know. :))
David L.
-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
|