|
Boost : |
From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2000-04-25 12:52:42
Rüdiger:
This looks really cool.
I think I found a small bug: Just some missing tests for the increment of
i.
case 'w':
if () {
..
if (wdth > 9) {
if (i + 1 < n) ++i;
else { s.set(FERROR); break; }
}
if (wdth > 99) {
if (i + 1 < n) ++i;
else s.set(FERROR);
}
else {
s.set(FERROR);
}
Also I was wondering if format should save the state of the iostream and
reset it after formatting each value. More of the way that printf works. (In
that centering one value doesn't leave the stream in a center all values
state.)
-gary-
> -----Original Message-----
> From: Rüdiger Loos [SMTP:loos_at_[hidden]]
> Sent: Thursday, April 20, 2000 9:06 AM
> To: boost_at_[hidden]
> Subject: RE: [boost] Re: Design discussion: easy i/o
>
> > output. I need to write internationalized code.
> >
> > -Dave
>
> Dave:
> I tried to combine the way Marco Manfredini treats positional parameters
> with the ideas
> of Boris Formitchev for specifiers and your syntax. The result is in the
> attached file frmt.cpp which compiles with gcc 2.95.2 (under NT both
> with the cygwin and mingw32 version, using the new SGI streams of
> STLport-4.0b5,
> and under Linux), mwcc 2.3, and comeau 4.2.42 online.
>
> The other file frmt1.cpp is for information only since it does not follow
> boost's
> conventions; it compiles with the previous compilers and in addition with
> VC++ 6.0 SP3
> and bcc32 5.5.
>
> In the following examples, No 11 was done with VC++ since I don't know how
> to switch
> locales with the other compilers; the strings for the locales by name are
> not
> standardized. Example No 12 gives different results; we contacted the
> vendor.
>
> The implementation may help to clarify some minor questions of syntax and
> some major
> questions of semantics of the design of an interface. Probably,
> manipulators as
> format parameters are against la raison d'être of format at all, but I
> hesitate to
> disallow them.
>
> Rüdiger
>
> Examples (the output is indented by 5 spaces):
> // 1. easy io
> cout << format("please type %1 rows of %2 characters", rows, cols);
> please type 2 rows of 10 characters
>
>
> // 2. Thus, for a translation to French, simply substitute the format
> string:
> cout << format(fmt[i++], chicken_cnt , coop_num);
> cout << format(fmt[i++], chicken_cnt , coop_num);
> 3 chickens can be found in coop number 5.
> Dans la cage le numéro 5, on y trouve 3 poulets.
>
>
> // 3. nested formats
> cout << format("The Truth is %1", format("%1 != %2", 1, 2)) << '\n';
> The Truth is 1 != 2
>
>
> // 4. centering
> cout << format("The Truth is %w20%c%1", format("%1 != %2", 1, 2)) << '\n';
> The Truth is 1 != 2
>
>
> // 5. adjust right (default)
> cout << format("The Truth is %w20%1", format("%1 != %2", 1, 2)) << '\n';
> The Truth is 1 != 2
>
>
> // 6. no right delimiter required, you see the parameter specifier?
> const string s21 = format("11%11", 21);
> cout << s21;
> 11211
>
>
> // 7. standard inserters inside of format, just in case...
> cout
> << format("The Truth is %w25%c%1",
> format("%3%4%1 != %2", 1.9999, 2.000, setprecision(2),
> fixed))
> setfill('.')) << '\n';
> The Truth is ....1.99990 != 2.00000...
>
>
> // 8. ... you got already used to
> cout
> << format("The Truth is %w20%c%1",
> format("%3%4%1 != %2", 1.9899, 2.000, scientific,
> setprecision(2)))
> << '\n';
> The Truth is 1.99e+00 != 2.00e+00
>
>
> // 9. standard inserters left of format retain their meaning
> cout << setfill('*') << setw(60)
> << format("The Truth is %w20%c%1",
> format("%3%4%1 != %2", 1.9899, 2.000, scientific,
> setprecision(2)))
> << '\n';
> ***************************The Truth is 1.99e+00 != 2.00e+00
>
>
> // 11. user defined inserter 'lang' for switching locales (VC++ only)
> for (i=0; i<7; ++i) {
> locale loc = locale(Name[i]);
> cout <<format("%1|%w37%l%2|%w14%3|%c%w9%4|", lang(loc), loc.name(),
> 1234567890,
> Name[i])
> <<'\n';
> |C | 1234567890| C |
> |English_United States.1252 | 1,234,567,890| US |
> |French_France.1252 | 1á234á567á890| French |
> |Spanish - Traditional Sort_Spain.1252| 1.234.567.890| Spanish |
> |Greek_Greece.1253 | 1.234.567.890| Greek |
> |Dutch_Netherlands.1252 | 1.234.567.890| Dutch |
> |German_Germany.1252 | 1.234.567.890| German |
>
>
> // 12a. dark corner (one compiler)
> const string s12 = format("22%12", 12);
> for (int w=0; w < 8; ++w)
> cout << setw(w) << s21 << ' ' << setw(w) << s12 << '\n'
> 11211 22122
> 1 2
> 11 22
> 112 221
> 1121 2212
> 11211 22122
> *11211 *22122
> **11211 **22122
>
> // 12b. dark corner (other compilers)
> const string s12 = format("22%12", 12);
> for (int w=0; w < 8; ++w)
> cout << setw(w) << s21 << ' ' << setw(w) << s12 << '\n'
> 11211 22122
> 11211 22122
> 11211 22122
> 11211 22122
> 11211 22122
> 11211 22122
> *11211 *22122
> **11211 **22122
>
> ------------------------------------------------------------------------
> Enjoy the award-winning journalism of The New York Times with
> convenient home delivery. And for a limited time, get 50% off for the
> first 8 weeks by subscribing. Pay by credit card and receive an
> additional 4 weeks at this low introductory rate.
> http://click.egroups.com/1/3102/2/_/9351/_/956246778/
> ------------------------------------------------------------------------
> << File: frmt.cpp >> << File: frmt1.cpp >>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk