|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-06-12 11:36:05
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk