www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Escaping control in formatting (again)

reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
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
May 06 2012
parent reply kenji hara <k.hara.pg gmail.com> writes:
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 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 formattin=
g.
 To convince me I'm wrong, pleas write to this thread that this isn't a
 desired formatting functionality for you:

 ---
 auto myInterfaces =3D ["Iface1", "Iface2", "Iface3"];
 // %!-s disables escaping
 myDFile.writefln(`class C: %(%!-s, %)`, myInterfaces);
 ---

 ---
 // %!+s enables escaping
 debug if(str1 !=3D str2) writefln(`WARNING: %!+s !=3D %!+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 issu=
e
 because if they are good, they will be documented some day)


 Original thread (with only mine and Kenji Hara opinions (yes, and one pos=
t
 from Dmitry who don't know current escaping rules):
 http://forum.dlang.org/thread/jn3ibu$tp7$1 digitalmars.com

 --
 =E4=C5=CE=C9=D3 =F7. =FB=C5=CC=CF=CD=CF=D7=D3=CB=C9=CA
 Denis V. Shelomovskij
May 07 2012
parent reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
07.05.2012 11:39, kenji hara :
 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?
This is enough for my own needs. Thanks! Who is to implement this? Looks line nobody needs features from my original proposal so they shouldn't be discussed further (unless will become needed). -- . Denis V. Shelomovskij
May 07 2012
parent kenji hara <k.hara.pg gmail.com> writes:
Posted pull request:
https://github.com/D-Programming-Language/phobos/pull/573

Kenji Hara

2012/5/7 Denis Shelomovskij <verylonglogin.reg gmail.com>:
 07.05.2012 11:39, kenji hara =CE=C1=D0=C9=D3=C1=CC:

 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 specifier=
s.
 How about you?
This is enough for my own needs. Thanks! Who is to implement this? Looks line nobody needs features from my original proposal so they should=
n't
 be discussed further (unless will become needed).


 --
 =E4=C5=CE=C9=D3 =F7. =FB=C5=CC=CF=CD=CF=D7=D3=CB=C9=CA
 Denis V. Shelomovskij
May 07 2012