Escaping control in formatting (again)

kenji hara k.hara.pg at gmail.com
Mon May 7 00:39:54 PDT 2012


In prev thread, I have posted a proposal, but it didn't posted to
newsgroup, I don't know why.
I re-post my proposal.

----
If the leading compound format specifier has a '-' flag, like "%-( ...
%)", it disables auto-escaping for the elements formatting.

writefln(">%(%s, %)<", ["hello", "world"]); // output: >"hello", "world"<
writefln(">%-(%s, %)<", ["hello", "world"]); // output: >hello, world<

You can format the elements as like outside of compound format specifiers.
How about you?
----

Kenji Hara

2012/5/6 Denis Shelomovskij <verylonglogin.reg at gmail.com>:
> Sorry for wasting your time again, but I'm so silly that I still believe I
> was right in previous thread about enabling escaping control in formatting.
>
> To convince me I'm wrong, pleas write to this thread that this isn't a
> desired formatting functionality for you:
>
> ---
> auto myInterfaces = ["Iface1", "Iface2", "Iface3"];
> // %!-s disables escaping
> myDFile.writefln(`class C: %(%!-s, %)`, myInterfaces);
> ---
>
> ---
> // %!+s enables escaping
> debug if(str1 != str2) writefln(`WARNING: %!+s != %!+s`, str1, str2);
> ---
>
> and current (undocumented) escaping rules a good for you:
> 1. User has no escaping control.
> 2. Escaping is enabled only for associative arrays, ranges (not strings),
> user-defined types, and all its sub-elements unless a sub element is a
> character and is formatted with %c or a struct/class formatted using its
> `toString` method.
>
> (it took lot time to understand this rules for me, but this isn't an issue
> because if they are good, they will be documented some day)
>
>
> Original thread (with only mine and Kenji Hara opinions (yes, and one post
> from Dmitry who don't know current escaping rules):
> http://forum.dlang.org/thread/jn3ibu$tp7$1@digitalmars.com
>
> --
> Денис В. Шеломовский
> Denis V. Shelomovskij


More information about the Digitalmars-d mailing list