Boost logo

Boost Users :

From: Samuel Krempp (krempp_at_[hidden])
Date: 2004-11-07 04:06:14


On Thu, 2004-10-21 at 10:14, Barak Simon wrote:
> Hi,
> I have noticed that the format library does not support at present the printf asterisk for providing dynamic width as an extra parameter.
> Unfortunately my users need to use this widely and I would really hate to revert back to a non-typesafe solution.
>
> a. Are there any plans to support it in near future?

I was waiting to see if any people would need the feature before
implementing it.

> b. If not, is there an easy way to add that to parsing.hpp, parse_printf_directive method, parse_width & parse_precision sections? currently
> the asterisk is ignored, and the library throws an exception thinking it has an extra parameter.

hum, in the meantime ignoring the asterisk should ignore the extra
parameter too, my bad. I should be able to fix that tomorrow.

> c. Is there any workaround I miss which may give me the same expected result of providing say "%*s, width, charPtr" ?
> (I have 'width' and a non-null-terminated char pointer and need to construct the correct string from them without doing unnecessary copying...)

hmm, I could see a workaround like :
int n= 10;
string fmt = str(format( escape(" blabla %*d"), n));
format(fmt, 20);

where the escape function escapes the % characters, and changes the
asterisk into a %d :
" blabla %%%dd"

which will lead to fmt be :
" blabla %10d"

writing such an escape function shouldnt be too hard.
but adding the asterisk feature to boost::format neither, I just need to
take some time and do it.. I'll try to do that this week.

-- 
Samuel

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net