Boost logo

Boost :

From: Stewart, Robert (stewart_at_[hidden])
Date: 2002-01-24 09:44:01


From: David Abrahams [SMTP:david.abrahams_at_[hidden]]
>
> From: "mfdylan" <dylan_at_[hidden]>
>
> > Surely it's fair to assume most translation services understand the %
> > 1 %2 %3 style? It's used by the Win32 FormatMessage API if nothing

I doubt any format we're discussing would be such a terrible burden on any
translation service, though piggybacking on printf() formats simplifies that
the most.

> > else. As for the problem of how to deal with a number directly after
> > the digit, has anyone seriously ever needed more than 9 positional
> > parameters in a sentence? And does it really happen so often that
> > breaking the string up into two is going to cause a major problem?
> > If not, then you just take the first digit after the % and you're
> > done. Simplifies parsing, and the pretty rare cases where you might
>
> Since we don't seem to be using %0 anyway, we could say that (where n,m

I was thinking that was really a problem, given the C/C++ approach to
things, but given that non-programmers might be called upon to translate
such strings, I can see the value of starting at 1.

> represent digits and x a non-digit):
>
> format("%012345") % "hello" => hello2345
>
> format("%12345") % "#1" % "#2" % "#3" % "#4" % "#5" % "#6" % "#7"
> % "#8" % "#9" % "#10" % "#11" % "$$" => $$345
>
> format("%2x") % "#1" % "$$" => $$x
>
> This arrangement allows us 99 parameters without introducing %{3} syntax.

That's an interesting alternative, but I don't think the tens place should
be optional if we adopt it. My reasoning is that making the tens place
digit optional can lead to subtle errors -- probably compile time, but
errors nonetheless -- when writing, for example, "%12345" and intending
"%012345."

However, looking at that example, I can see why "<<" was such a good choice
for streams (besides the directionality): "<<" stands out from its
surroundings better than does "%":

    format("%12345") % "#1" % "#2" % "#3" % "#4" % "#5" % "#6" % "#7"
        % "#8" % "#9" % "#10" % "#11" % "$$"

    format("%12345") << "#1" << "#2" << "#3" << "#4" << "#5" << "#6" << "#7"
        << "#8" << "#9" << "#10" << "#11" << "$$"

It's a little easier to see the <<'s in the second statement than the %'s in
the first. Unfortunately, using "<<" introduces problems interacting with
streams, and suggests that the insertion operators already defined for
various types would work with format, so it isn't a good choice.

At the risk of beating a dead (or very sick) horse, let me show the same
example in the [] notation:

    format("[12]345") ["#1"]["#2"]["#3"]["#4"]["#5"]["#6"]["#7"]
        ["#8"]["#9"]["#10"]["#11"]["$$"] => $$345

or:

    format("[12]345") ["#1"] ["#2"] ["#3"] ["#4"] ["#5"] ["#6"] ["#7"]
        ["#8"] ["#9"] ["#10"] ["#11"] ["$$"] => $$345

in case the added whitespace looks better to someone.

Now, add a couple of manipulators in there:

    format("%12345") % "#1" % "#2" % "#3" % hex % "#4" % "#5" % "#6" % "#7"
        % "#8" % "#9" % dec % "#10" % "#11" % "$$"

    format("[12]345") ["#1"]["#2"]["#3"](hex)["#4"]["#5"]["#6"]["#7"]
        ["#8"]["#9"](dec)["#10"]["#11"]["$$"]

The insertion of the manipulators is more obvious in the second form than
the first.

Rob
Susquehanna International Group, LLP
http://www.sig.com


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