Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2001-12-19 14:00:36


> It depends who you are. All I wanted was %1 %2 %3 in the format string; I
> don't remember printf syntax as though I can write it in my sleep, and don't
> want to be burdened with the extra characters.

Let me just make a point as to how format strings are usually used.
In C programs which require translation strings are all specified with
a i18n macro like N_().

Thus we get a program like

   char* format=N_("Your name is %s, and your age is %d.");
   printf(format,name,age);

When it comes time for internationalization these strings are parsed
out to a file where they are given to the translator. The translator
sends back a file which contains a map from string to string.
The i18n macro when compiled for internationalization then
looks up the strings and provides the translation for the formats
at run time.

The format strings can come from any level of the library. C or C++.
Thus it is very desirable to have 'strict' compatiblity to C printf
standard as the translator do not know from which level the string
came in mixed codes.

If you want an extension, use the recommended print form type or some
out of the way code. Printf formats go "% specifiers type". So
I see nothing wrong with abusing the code %#%.
Thus format(""%1% %2% %3%") makes more sense.

Second point. The problem of ambiguity...

  format("%10%2") means what? 10 arguments with 1,3-9 unused or
   "%1"0"%2".

Use of strict printf solve this "%1$s0$2$s".

(Aside)
Anything other than strict compilence is worthless for my project uses.
My project is mixed C/C++ and I must adhere to the standard. As the
original submitter of the i18n format class, it was my intent for
boost to get a "printf" compatible format. If a simpler one is called
for just reorganizing the order of arguments, it really should be
separate class.

--Karl


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