Boost logo

Boost :

From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2002-10-18 15:55:08


"Thorsten Ottosen" <nesotto_at_[hidden]> wrote in message
news:01bc01c276bc$dbbcfc00$41c3a8c0_at_nesottolap...
>
> > Many times I was missing some fundamental string manipulation routines,
> > which are not part of STL, especially functions link trim and various
> > conversion routines like to_upper and to_lower.

Conversion of case can easily be performed with
std::transform(str.begin(), str.end(), str.begin(), ::toupper);

How do you propose a simplified version? Perhaps
template<typename T>
void to_upper(T &cont)
{
    std::transform(cont.begin(), cont.end(), cont.begin(), ::toupper);
}

or something similar ?

> > So is there anyone who thinks, that something like this shoud be useful
> enough
> > to include it in the boost?

I think it would be a great additional to the sequence_algo library.

> Oh yes. I also found myself writing these:
>
> inline bool contains( string_c& s, string_c& other )
> inline bool contains_back( string_c& s, string_c& back )
> inline bool contains_front( string_c& s, string_c& front )
> inline string substr_until( string_c& s, string_c& end )
> inline string substr_after( string_c& s, string_c& begin )
> inline string substr_without( string_c& s, string_c& out )
> inline void erase_all( string& s, string_c& what )
> inline void erase_front( string& s, string_c& what )
> inline void erase_back( string& s, string_c& what )
>
> typedef std::pair<string, string> string_pair;
> inline string_pair split( string_c& s, string_c at )

It would be nice to see these implemented generically rather than
specifically for strings. Most of the functions in the list above could
equally apply to sequences of other types. Thus

template<typename ItIn1, ItIn2>
inline bool contains(ItIn1 begin1, ItIn1 end1, InIt2 begin2, InIt2 end)

> I not sure they are the best possible names, and maybe they should
> beoverloaded for char

No overload would be needed with the templated signature :-)

Regards
-- Craig


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