[string_algo] split algorithm predicate question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[string_algo] split algorithm predicate question

Jeff Garland

I've used the boost::algorithm::split successfully in the past with the
is_any_of predicate as shown in the docs.  Something like:

using namespace boost_algorithm;
std::vector<std::string> split_result;
split( split_result, some_string, is_any_of("=+") );

But now I want to match a multi char string exactly on the split.  Effectively
something like:

std::string some_data("1===2);
split( split_result, some_data, is_equal("===") ); //result gets strings "1","2"

I'm not finding a predicate or easy way to do this.  Is this not supported or
am I just missing something?

Thx,

Jeff

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [string_algo] split algorithm predicate question

Pavol Droba
Hi Jeff,

You can do this, but split is not to right function. It is a simple
wrapper over the find/split_iterator.

So I suggest you to use split_iterator directly:

   std::string some_data("1===2);
   typedef split_iterator<string::iterator> string_split_iterator;
   for(string_split_iterator It=
       make_split_iterator(some_data, first_finder("===", is_iequal()));
       It!=string_split_iterator();
       ++It)
    {
        cout << copy_range<std::string>(*It) << endl;
    }

Alternatively you can use iter_split, it has similar interface as split:

   iter_split( split_result, some_data, first_finder("===", is_iequal()));


Regards,
Pavol



On Sat, Mar 25, 2006 at 07:55:34PM -0700, Jeff Garland wrote:

>
> I've used the boost::algorithm::split successfully in the past with the
> is_any_of predicate as shown in the docs.  Something like:
>
> using namespace boost_algorithm;
> std::vector<std::string> split_result;
> split( split_result, some_string, is_any_of("=+") );
>
> But now I want to match a multi char string exactly on the split.  Effectively
> something like:
>
> std::string some_data("1===2);
> split( split_result, some_data, is_equal("===") ); //result gets strings "1","2"
>
> I'm not finding a predicate or easy way to do this.  Is this not supported or
> am I just missing something?
>
> Thx,
>
> Jeff
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [string_algo] split algorithm predicate question

Jeff Garland
On Sun, 26 Mar 2006 12:16:37 +0200, Pavol Droba wrote

> Hi Jeff,
>
> You can do this, but split is not to right function. It is a simple
> wrapper over the find/split_iterator.
>
> So I suggest you to use split_iterator directly:
>
>    std::string some_data("1===2);
>    typedef split_iterator<string::iterator> string_split_iterator;
>    for(string_split_iterator It=
>        make_split_iterator(some_data, first_finder("===", is_iequal()
> ));       It!=string_split_iterator();       ++It)    {        cout
> << copy_range<std::string>(*It) << endl;    }
>
> Alternatively you can use iter_split, it has similar interface as split:
>
>    iter_split( split_result, some_data, first_finder("===",
>  is_iequal()));

iter_split is exactly what I wanted -- had a feeling it was in there somewhere
:-)  I will note that iter_split doesn't seem to be in the docs anywhere.

Thx again for the very useful library!

Jeff
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users