Subject: Re: [boost] [RFC] string inserter/extractor "q u o t i n g"
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2010-06-30 18:12:54
On 6/23/2010 9:59 PM, Rob Stewart wrote:
> When considered as the inverse of quote(), unquote() should
> simply strip leading and trailing delimiters and look for escaped
> delimiters and escaped escape characters within. To supply the
> extra semantics you've suggested, quote() must also be enhanced
I've attached a new version of unquote() (along with quote() and
the updated test program) with that behavior.
As implemented, unquote() stops at the first delimiter it finds
after the first character (whether the first is a delimiter or
not). Until then, it "unescapes" escaped characters. Note the
last test case:
a = "embedded ";
b = quote(a);
b += "quotation mark\"";
BOOST_ASSERT("\"embedded \"quotation mark\"" == b);
b = unquote(b);
BOOST_ASSERT(a == b);
In that test, "quotation mark\"" is ignored by unquote() because
it stops writing to the output iterator up finding the quotation
mark after the space following "embedded."
It is possible for unquote() to leave the embedded quotation
mark, as if it had been escaped, but it would complicate the
algorithm -- unless I assume random access iterators -- and its
This version doesn't care whether the first or last characters
are delimiters, thus "muddling through" as Eric suggested.
I haven't taken the time to consider other reasonable ideas for
delimiter support such as multiple character delimiters or
distinct start and end delimiters.