Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-07 23:29:16


on 3/7/00 11:21 AM, Dietmar Kuehl at dietmar_kuehl_at_[hidden] wrote:

> Concerning the format string stuff we have seen several implementations
> by now. However, I was missing the possibility to extend the format
> strings by user defined formating flags. IOStreams have the possibility
> to set up user defined formating flags using the 'pword()'/'iword()'
> mechanism. I can image that it would be useful to allow something
> similar. Now, how is this intended to work? Actually, quite simple: If
> an object is to be formatted, the object and the corresponding format
> is passed to a function which is supposed to print the object. The
> default implementation just calls 'operator<<()' for the object after
> "normal" setup of the flags. A replacement version can do more fancy
> things.

You probably need to educate us (me, definitely) about what these flags are
used for.

>
> The only problem is that the parser for the format string somehow has
> to know where the format string ends! Inventing completely new format
> strings this would be simple: Eg. a format specification could be a %
> followed by all characters until a ;.

I suggest that type-specific formatting goes outside the format string, and
only alignment and width appear inside. That would solve this problem, I'm
pretty sure.

> Unfortunately, most people
> probably would like to use printf() format specifiers for the built-in
> types

Not, me, definitely! All I want is a syntax like this:

%[0-9] argument selection
%w[0-9]+ field width
%l left alignment
%r right alignment
%c center alignment
%% % sign

Thus, %w12%r%3 means format argument 3 in a 12-space field, right aligned.

     -Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk