Boost logo

Boost :

From: Andreas Pokorny (diemumiee_at_[hidden])
Date: 2004-09-23 15:44:51


On Thu, Sep 23, 2004 at 09:46:44AM -0400, Rob Stewart <stewart_at_[hidden]> wrote:
> From: Reece Dunn <msclrhd_at_[hidden]>
> > John Torjo wrote:
> > > Rob Stewart wrote:
> > >> Agreed, but pipes ("|") are easier to grok:
> > >>
> > >> "<elem> | </elem><elem> | </elem>"
> > >
> > > That's fine too.
> >
> > This again runs into the problem of what if you want '|' in your format
> > string? One possibility is to use non-printable characters, e.g. \xFF,
> > but I don't think this would have widespread support.
> >
> > Implementing escaping for the above will complicate the evaluation of
> > the format string as you cannot use str.find( "|" ). One possibility is
> > to check if '\' exists before '|' after a find; if yes, repeat. Thus '\'
> > becomes context-sensitive. This approach leads to "< |\\| >" for "<
> > a\\b\\c >" formatting being ill-defined.

> Some other good choices are "#", "@", "!", "^", and "_". Have a
> look at the previous example (I've removed the spaces so the
> delimiters are set apart with spaces so we can see how good they
> really are):
>
> "<elem>|</elem><elem>|</elem>"
>
> "<elem>#</elem><elem>#</elem>"
>
> "<elem>@</elem><elem>@</elem>"
>
> "<elem>!</elem><elem>!</elem>"
>
> "<elem>^</elem><elem>^</elem>"
>
> "<elem>_</elem><elem>_</elem>"
>

You could also make the divider a user defined value of the formater object
and maybe pick '%' as a default value:
  std::cout << formatob(v, "[ %, % ]");
  std::cout << formatob(v, "[ |, | ]", '|' );

Thus you could ignore the escape-problem completely.

Andreas Pokorny
  




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