View mode: basic / threaded / horizontal-split · Log in · Help
May 05, 2008
i18n and string in another locales [charsets],,??
why  d compiler refuse to swallow  strings [char[] or string] in another languages??
c/c++  java/c# etc... comiplers/interpreters can  swallow strings  in any charset
without complain

---------------------------------------------------------------------------------------------------
and i want to know  why i can't do these things too:

1]Suppose we have  a String Class  with Constructors String(char)/String(char[])/String(String) So why I can't do this
String  mystr="Hello,World";  // Or
String  mystr='c';

there is no implicit constructor conversion in d  like  c++/java/c#
2] construct like this  char[4] str=new char[4] {'A','B','C','D'};
3] I know  that  java importing with *   [import  xx.yy.*;] is slow  but with * importing  it is not necessary to write  every time  about 5 to 10 lines of import 
statements
4]why  the compiler depends on the phobos by this intimate relationship
  d compiler must be generic like c++
----------------------------------
i know i am BORING but

Thanks
May 06, 2008
Re: i18n and string in another locales [charsets],,??
d-user wrote:
> why  d compiler refuse to swallow  strings [char[] or string] in another languages??
> c/c++  java/c# etc... comiplers/interpreters can  swallow strings  in any charset
> without complain

char[] is defined to be UTF-8, which can represent characters in many 
languages. DMD (and maybe GDC) requires that the source file be in one 
of ASCII, UTF-8, UTF-16, or UTF-32, so there shouldn't be a problem. If 
you want to accept strings of other charsets in your code (i.e. from a 
network or file), use ubyte[] and/or convert it to UTF-{8, 16, 32}.

> ---------------------------------------------------------------------------------------------------
> and i want to know  why i can't do these things too:
> 
> 1]Suppose we have  a String Class  with Constructors String(char)/String(char[])/String(String) So why I can't do this
> String  mystr="Hello,World";  // Or
> String  mystr='c';
> 
> there is no implicit constructor conversion in d  like  c++/java/c#
> 2] construct like this  char[4] str=new char[4] {'A','B','C','D'};
> 3] I know  that  java importing with *   [import  xx.yy.*;] is slow  but with * importing  it is not necessary to write  every time  about 5 to 10 lines of import 
> statements

You already got answers to these three in your other post. Please don't 
double-post. If the answers were confusing, follow-up there.

> 4]why  the compiler depends on the phobos by this intimate relationship
>    d compiler must be generic like c++

C/C++ has a runtime component, too. D's is a bit bigger because of 
things like the garbage collector, etc.

> ----------------------------------
> i know i am BORING but
> 
> Thanks
May 06, 2008
Re: i18n and string in another locales [charsets],,??
2008/5/6  <d-user@puremagic.com>:
> why  d compiler refuse to swallow  strings [char[] or string] in another languages??
>  c/c++  java/c# etc... comiplers/interpreters can  swallow strings  in any charset
>  without complain

D natively uses Unicode. Unicode can be expressed in three ways,
called UTF-8 (which uses chars), UTF-16 (which uses wchars), and
UTF-32 (which uses dchars).

For all other encodings (and incidently, all other encodings are a
/subset/ of Unicode), to need to convert to and from Unicode.

std.encoding knows also about ASCII, Latin-1, and Windows-1252.
std.encoding also provides the EncodingScheme abstract class, from
which additional encodings may be subclassed. That module is still in
its infancy, but if there is any /specific/ encoding you need support
for, let us know.
Top | Discussion index | About this forum | D home