Escaping control in formatting

kenji hara k.hara.pg at gmail.com
Mon Apr 23 10:15:55 PDT 2012


2012年4月24日1:14 Denis Shelomovskij <verylonglogin.reg at gmail.com>:
> 23.04.2012 18:54, kenji hara написал:
>
>> Please give us use cases. I cannot imagine why you want to
>> change/remove quotations but keep escaped contents.
>
>
> Sorry, I should mention that !' and !" are optional and aren't commonly
> used, and all !?* are very optional and are here just for completeness
> (IMHO).
>
> An example is generating a complicated string for C/C++:
> ---
> myCppFile.writefln(`tmp = "%!?"s, and %!?"s, and even %!?"s";`,
>                   str1, str2, str3)
> ---
>
>
> --
> Денис В. Шеломовский
> Denis V. Shelomovskij

During my improvements of std.format module, I have decided a design.
If you format some values with a format specifier, you should unformat
the output with same format specifier.

Example:
    import std.format, std.array;

    auto aa = [1:"hello", 2:"world"];
    auto writer = appender!string();
    formattedWrite(writer, "%s", aa);

    aa = null;

    auto output = writer.data;
    formattedRead(output, "%s", &aa);  // same format specifier
    assert(aa == [1:"hello", 2:"world"]);

More details:
    https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L3264

I call this "reflective formatting", and it supports simple text based
serialization and de-serialization.
Automatic quotation/escaping for nested elements is necessary for the feature.

But your proposal will break this design very easy, and it is
impossible to unformat the outputs reflectively.

For these reasons, your suggestion is hard to accept.

Kenji Hara


More information about the Digitalmars-d mailing list