Boost logo

Boost Testing :

Subject: Re: [Boost-testing] String split behaviour
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2015-05-20 16:29:27


On Wed, May 20, 2015 at 11:32 AM, Venkateswara Rao Sanaka <
moderncpp.venki_at_[hidden]> wrote:

> Hi,
>
> I am getting two empty strings from the following program,
>
> void boost_split_test() {
>
> const string &text("-");
>
> vector<string> tokens;
>
> split(tokens, text, boost::is_any_of("-"), token_compress_on);
>
>
> cout << "size of tokens " << tokens.size() << '\n';
>
>
> for (auto const &e : tokens)
>
> cout << e.size() << '\n';
>
> }
>
>
> Output:
>
>
> size of tokens 2
> 0
> 0
>
>
> Is this expected output? I expecting an zero split parts. Could someone
> clarify?
>
>
This seems reasonable to me.

You asked it to split the string containing a single dash into parts
separated by dashes.
The string gets split into an empty string, a dash (which is not returned
to you, being the separator), and an empty string.

Consider splitting the input string "Foo-" (or "-Foo") compared to "Foo".
One gives two strings (one before the dash, one after the dash), the other
gives one string (because there are no dashes).

Given a string with "n" separators, you should get "n+1" strings back (with
the proviso that consecutive separators are collapsed together, so "Foo--"
is treated the same as "Foo-").

-- Marshall

P.S. Checking the tests, I notice that there's no coverage for this case
(separators at the beginning or the end of the input). I'll put it on my
list. Thanks!



Boost-testing list run by mbergal at meta-comm.com