Commmandline arguments and UTF8 error

Jacob Carlborg doob at me.com
Tue Feb 23 02:47:09 PST 2010


On 2/23/10 01:35, Daniel Keep wrote:
>
>
> Jacob Carlborg wrote:
>> On 2010-02-22 15.39, 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(...)].
>
> It *is* more verbose.  It's one of the few things I've never liked about
> Tango.
>
> That said, the justification for it is that Stdout.format /
> Stdout.formatln is significantly clearer.  Plus, you also get an Stderr
> version as well.
>
>>> Also, I use derelict
>>> which I don't believe supports Tango yet.
>
> I'm fairly certain it should.  I'm positive I've used them together in
> the past.
>
>>> And I liked the
>>> out-of-the-box-feeling of Phobos which is supposedly the standard.
>
> That's a bit like not using Boost because there's the C standard library.
>
> Whilst Tango is not a strict superset of Phobos, it generally does more
> and does it better.  For example, it actually makes the effort to decode
> command line arguments.  :P
>
>> You can use derelict with tango. I can agree you about Stdout.format,
>> You can create wrappers like this:
>>
>> void writeln (ARGS...) (ARGS args)
>> {
>>      foreach (arg ; args)
>>          Stdout(arg);
>>
>>      Stdout().newline;
>> }
>>
>> void writefln (ARGS...) (char[] str, ARGS args)
>> {
>>      foreach (arg ; args)
>>          Stdout.format(str, arg);
>>
>>      Stdout().newline;
>> }
>
> Shouldn't that be
>
> void writefln(Args...)(char[] str, Args args)
> {
>      Stdout.formatln(str, args);
> }

Yes, of course, my mistake.

> Incidentally, you don't need the `()`s before `.newline`.
>
>>> 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.
>
> Having written projects using both Phobos and Tango (not in the same
> project, mind you), I'd say Tango is very much worth the effort.
>
> Just... just don't use the Zip module.  It's complete and utter crap.



More information about the Digitalmars-d-learn mailing list