Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-06-12 13:26:05


These would be great! This kind of functionality is especially important
for entry-level C++ programmers. With that in mind we should strive to
keep this library easy to use (as easy as Beman's examples below).

On Tue, 12 Jun 2001, Beman Dawes wrote:

> I'd like to see a Boost string algorithms library.
>
> For the sake of discussion, let's assume:
>
> * The interface is via free functions (rather than modifying
> std::basic_string or inheriting from it).
>
> * The examples below use std::string but a real library would deal with
> wstrings too, if not the full basic_string template.
>
> * The examples ignore obvious variations like rfind, and size_type p=0
> arguments, but a real library would supply variations.
>
> The set of Boost algorithms I'd like to discuss is:
>
> size_type find( const string & s, const string & search );
> string & erase( string & s, const string & search );
> string & erase_all( string & s, const string & search );
> string & replace( string & s, const string & search,
> const string & replacement );
> string & replace_all( string & s, const string & search,
> const string & replacement );
>
> Presumable the overloads would include "const char *" for the "search"
> argument.
>
> Example usage:
>
> string s ( "How now brown brown cow" );
> string::size_type p;
> p = find( s, "br" ); // p == 8
> erase( s, "br" ); // s == "How now own brown cow"
> replace_all( s, "ow", "*" ); // s == "H* n* *n br*n c*"
>
> Now the tricky part - users would also like options:
>
> The "search" argument to be a regular expression.
>
> The "search" comparison to be treated as case insensitive.
>
> From a user perspective, it seems to me overloading the "search" argument
> is preferable to having if_regex, erase_regex, etc. The same for case
> insensitive operations.
>
> I guess the user would then write things like:
>
> string s ( "axacab" );
> erase( s, regex("a(b|c)") ); // s == "axab"
>
> Will that work? I don't see why not.
>
> Even if that works, I'm not sure how to apply the same approach to case
> insensitive compares, including issues of locale.
>
> The point of this posting is to get both general and specific feedback. Is
> a string algorithms library a good idea? Is anyone is interested in
> working on such a library?
>
> --Beman
>
>
>
> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
 Summer Manager, AT&T Research phone: (973) 360-8185
----------------------------------------------------------------------


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