Commmandline arguments and UTF8 error

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Mon Feb 22 07:09:32 PST 2010


Lars T. Kyllingstad wrote:
> Nils Hensel wrote:
>> Daniel Keep schrieb:
>>> If you look at the real main function in src\phobos\internal\dmain2.d,
>>> you'll see this somewhere around line 109 (I'm using 1.051, but it's
>>> unlikely to be much different in an earlier version):
>>>
>>>> for (size_t i = 0; i < argc; i++)
>>>> {
>>>>     auto len = strlen(argv[i]);
>>>>     am[i] = argv[i][0 .. len];
>>>> }
>>>>
>>>> args = am[0 .. argc];
>>>>
>>>> result = main(args);
>>> In other words, Phobos never bothers to actually convert the arguments
>>> to UTF-8.
>>
>> Hmm, I really can't see any benefit. Did Walter ever comment on this
>> matter? Surely, I can't be the only one who is unable to use D for
>> something as mundane as a command line tool that takes file names for
>> arguments?
>>
>>> Tango does (tango\core\rt\compiler\dmd\rt\dmain2.d:238 for a recent-ish
>>> trunk).
>>
>> Actually I was trying to avoid Tango. For one I'm not too fond of the
>> interface [Stdout.format(...).newline just seems awkward und
>> unnecessarily complicated compared to writef(...)]. Also, I use derelict
>> which I don't believe supports Tango yet. And I liked the
>> out-of-the-box-feeling of Phobos which is supposedly the standard.
>>
>> Guess I have to make up my mind if all the extra hassle of installing
>> and learning (and updating) another and utterly different "standard"
>> library outweighs the benefits of developing in D.
> 
> My humble opinion is that instead of doing that, you should consider 
> switching to D2.  Most D1 code should compile as D2 code (the most 
> common change will be inout->ref), and Phobos2 has the same "feel" as 
> Phobos1, just a lot better and more extensive.  Specifically, it has 
> std.encoding, which may aid you in decoding filenames from your file 
> system's character set.
> 
> If D2 is not an option, you can always look at the std.encoding source 
> code and write your own YourEncoding->UTF-8 function:
> 
> http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/encoding.d

I just realised that D2 also does what Daniel says Tango does.  I guess 
this is because D2's runtime, druntime, is based on Tango's runtime.  So 
most likely you don't need to use std.encoding after all.

-Lars


More information about the Digitalmars-d-learn mailing list