From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-09-21 11:48:44
John Torjo wrote:
>This just popped into my head. A lot of confusion seems to come from how
>you pass decorators. What I'm trying to say is that it can be very
>difficult to get the decorator strings right (especially for more complex
>things like XML) from the first time.
>I would suggest every formatter takes only one string which parses and
>finds all decorators itself.
>Each formatter will have one or more escape sequences which it uses to find
>// in this case, '%' is used for identifying an element
>// '*' is to mean "leave default" (don't change)
>// equivalent to your "[ ", ", ", " ]"
>std::cout << formatob(v, "[ %, % ]");
This looks good :) On the implementation side it would require splitting the
string into the 2/3 components and constructing the decorators accordingly.
Maybe defining an "extract_decorators" function internally, so
wrapper_decorators and sequence_decorators can process this internally. How
std::cout << io::object( v )( "[ %, % ]" );
I am sure this would be feasible.
>// eq. to "<< ", " | ", " >>"
>std::cout << formatob(v, "<< % | % >>");
>// set only open/close decorators
>std::cout << formatob(v, "<< %*% >>");
Here, you would need special handling of string == "*". This should also be
>// sets only the separator
>std::cout << formatob(v, "*% | %*");
>// for pair - you have "%1" and "%2"
>std::vector< std::pair<int,long> > vp;
>// write XML
>std::cout << formatob(vp,
> containerfmt("<elem> % </elem><elem> % </elem>",
Here, you don't need %1 and %2. You just do: "<int>%</int><long>%</long>".
In terms of implementability, I don't see a problem. The two issues I have
 What are the performance penalties for this?
 What if you want '%' or '*' in your format string, e.g. "[ a * b * c ]"?
You would thus need to implement some sort of escaping capability.
NOTE: This could sit along side using the 'decorate' function and Volodya's
idea for expressions, e.g.:
"<<" + fmt::container( fmt::pair()( "<a>%</a><b>%</b>" )) + " >>"
).decorate( " : " );
// output: << <a>2.75</a><b>1</b> : <a>3.14159</a><b>7</b> >>
Use MSN Messenger to send music and pics to your friends
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk