27 #include <boost/lexical_cast.hpp>
28 #include <boost/algorithm/string.hpp>
43 inline static bool nocase_compare(
char c1,
char c2 );
48 explicit StringUtil(
const string& data =
"" ) : m_Separator(
" " ), m_Data( data ), m_SeparatorIndex( 0 ) {};
50 void Split(
const string& separator );
52 bool MoreTokens()
const;
56 static string Trim(
const string& source );
59 static inline long ParseLong(
const string& source ) {
return strtol( source.c_str(), NULL, 10 ); }
60 static inline unsigned long ParseULong(
const string& source )
62 unsigned long x = strtoul( source.c_str(), NULL, 10 );
63 if ( source[ 0 ] ==
'-' )
64 throw boost::bad_lexical_cast(
typeid( source ),
typeid( x ) );
68 static inline int ParseInt(
const string& source ) {
return atoi( source.c_str() ); }
69 static inline unsigned int ParseUInt(
const string& source )
71 unsigned int x = (
unsigned int )strtoul( source.c_str(), NULL, 10 );
72 if ( source[ 0 ] ==
'-' )
73 throw boost::bad_lexical_cast(
typeid( source ),
typeid( x ) );
77 static inline short ParseShort(
const string& source )
79 int x = atoi( source.c_str() );
80 if ( ( x < SHRT_MIN ) || ( x > SHRT_MAX ) )
81 throw boost::bad_lexical_cast(
typeid( source ),
typeid( x ) );
84 static inline float ParseFloat(
const string& source ) {
return (
float )atof( source.c_str() ); }
85 static inline double ParseDouble(
const string& source ){
return strtod( source.c_str(), NULL ); }
88 static inline string ToString(
const T value ) {
return boost::lexical_cast<
string >( value ); }
90 static string FindBetween(
const string& value,
const string& first,
const string& last );
91 static string Pad(
const string& value,
const string& padleft,
const string& padright );
92 static string Replace(
const string& value,
const string& what,
const string& with );
93 static bool StartsWith(
const string& value,
const string& with );
95 static string::size_type CaseInsensitiveFind(
const string& first,
const string& second );
96 static string ToUpper(
const string& input );
97 static string ToLower(
const string& input );
99 static bool IsAlphaNumeric(
const string& input );
101 static string DeserializeFromFile(
const string& filename );
102 static void SerializeToFile(
const string& filename,
const string& content );
106 #endif // STRINGUTIL_H