25 #ifndef WSTRINGUTILS_H
26 #define WSTRINGUTILS_H
38 #include <boost/lexical_cast.hpp>
40 #include "WExportCommon.h"
60 namespace string_utils
68 extern OWCOMMON_EXPORT
const std::string
WHITESPACE;
79 std::string OWCOMMON_EXPORT
rTrim(
const std::string& source,
const std::string& t =
WHITESPACE );
89 std::string OWCOMMON_EXPORT
lTrim(
const std::string& source,
const std::string& t =
100 std::string OWCOMMON_EXPORT
trim(
const std::string& source,
const std::string& t =
WHITESPACE );
109 std::string OWCOMMON_EXPORT
toUpper(
const std::string& source );
118 std::string OWCOMMON_EXPORT
toLower(
const std::string& source );
130 std::vector< std::string > OWCOMMON_EXPORT
tokenize(
const std::string& source,
132 bool compress =
true );
142 template<
class T > std::ostream& operator<<( std::ostream& os, const std::vector< T >& v )
144 std::stringstream result;
145 result <<
"[" << std::scientific << std::setprecision( 16 );
146 std::copy( v.begin(), v.end(), std::ostream_iterator< T >( result,
", " ) );
147 os <<
rTrim( result.str(),
", " ) <<
"]";
165 template<
class T > std::istream&
operator>>( std::istream& in, std::vector< T >& v )
170 std::vector< std::string > tokens =
tokenize( str,
", " );
172 v.reserve( tokens.size() );
173 for(
size_t i = 0; i < tokens.size(); ++i )
175 v.push_back( boost::lexical_cast< T >( tokens[i] ) );
188 template<
class T > std::ostream& operator<<( std::ostream& os, const std::list< T >& l )
190 std::stringstream result;
191 result <<
"<" << std::scientific;
192 std::copy( l.begin(), l.end(), std::ostream_iterator< T >( result,
", " ) );
193 os <<
rTrim( result.str(),
", " ) <<
">";
205 template<
class T > std::ostream& operator<<( std::ostream& os, const std::set< T >& s )
207 std::stringstream result;
208 result <<
"{" << std::scientific;
209 std::copy( s.begin(), s.end(), std::ostream_iterator< T >( result,
", " ) );
210 os <<
rTrim( result.str(),
", " ) <<
"}";
215 #endif // WSTRINGUTILS_H