Boost logo

Boost :

Subject: [boost] [RFC] string inserter/extractor "q u o t i n g"
From: Beman Dawes (bdawes_at_[hidden])
Date: 2010-06-16 09:47:37


This is a request for comments on a delimited string
inserter/extractor facility for Boost.

The initial motivation is a need for Boost.Filesystem class path
inserters and extractors to handle paths with embedded spaces. The
problems stems from standard library stream I/O not round-tripping
strings with embedded spaces, so a general solution might be of
interest. It is a bit surprising that Boost doesn't seem to already
have such a utility.

The general solution presented here follows very common practice as to
the format: strings are enclosed in delimiters on output and the
delimiters (if present) are stripped on input. In the external format,
an escape character precedes itself or the delimiter character should
either be present in the string. The default delimiter character is
the double-quote (") and the default escape character is the backslash
(\). These defaults can be overridden.

Example:

    const std::string expected("foo\\bar, \" *");

    std::cout << delimit(expected);

    std::string actual;
    std::stringstream ss;

    ss << delimit(expected);
    ss >> undelimit(actual);

    assert(expected == actual);

The output to cout is "foo\\bar, \" *"

A prototype is available at
http://svn.boost.org/svn/boost/branches/filesystem3/boost/delimit_string.hpp.
It is a header only implementation.

Do you think this component, with suitable documentation, tests, etc.,
should become a part of Boost?

If so,

What library should it be part of? Seems too small to be a library all
of its own.

Where should the header live?

What namespace should it be in?

Are delimit() and undelimit() suitable names for the functions?

Any other comments?

Thanks,

--Beman


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