00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef UTILITY_STRING_H
00037 #define UTILITY_STRING_H
00038
00039 #include <string>
00040 #include <vector>
00041 #include <stdarg.h>
00042 #include <boost/tokenizer.hpp>
00043
00044 namespace Onikiri
00045 {
00046 class String : public std::string
00047 {
00048 typedef std::string t_string;
00049
00050 public:
00051 String();
00052 String(const t_string &str, size_type pos = 0, size_type n = npos);
00053 String(const char* str);
00054 String& format_arg(const char* fmt, va_list& arg);
00055
00056
00057 String& format(const char* fmt, ... );
00058
00059 operator const char*() const { return c_str(); };
00060
00061 template<class T> String& operator=(const T& rhs)
00062 {
00063 assign(rhs);
00064 return *this;
00065 }
00066
00067 template<class T> String operator+(const T& rhs)
00068 {
00069 String tmp(*this);
00070 tmp.append(rhs);
00071 return tmp;
00072 }
00073
00074 String& operator=(const t_string& rhs)
00075 {
00076 assign(rhs);
00077 return *this;
00078 }
00079
00080 String operator+(const t_string& rhs)
00081 {
00082 String tmp(*this);
00083 tmp.append(rhs);
00084 return tmp;
00085 }
00086
00087 String& operator+=(const t_string& rhs)
00088 {
00089 append(rhs);
00090 return *this;
00091 }
00092
00093 template<class T> String& operator+=(const T& rhs)
00094 {
00095 append(rhs);
00096 return *this;
00097 }
00098
00099 String& operator+=(const char rhs)
00100 {
00101 append(&rhs, 1);
00102 return *this;
00103 }
00104
00105 void find_and_replace( const String& from, const String& to )
00106 {
00107 while( true ){
00108 std::string::size_type i = find( from );
00109
00110 if( i == std::string::npos ){
00111 break;
00112 }
00113
00114 std::string::replace( i, from.length(), to );
00115 }
00116 }
00117
00118
00119
00120
00121 std::vector<String> split(
00122 const char* delimiter,
00123 const char* delimiterKeep = NULL) const;
00124
00125 template <class T> T to()
00126 {
00127 return boost::lexical_cast<T>(*this);
00128 }
00129 };
00130 }
00131
00132 #endif