00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__String_H__
00010 #define __libutilxx__sella__util__String_H__
00011
00012 #include "../../common.h"
00013 #include "RegexException.h"
00014
00015 #include <stdarg.h>
00016
00017 #include <set>
00018 #include <list>
00019 #include <vector>
00020 #include <string>
00021
00022 #include <boost/regex.hpp>
00023
00024 namespace sella {
00025 namespace util {
00026 class String;
00027 }
00028 }
00029
00030 class sella::util::String {
00031 public:
00032 typedef const boost::regex_constants::syntax_option_type REFlag;
00033 typedef const boost::regex_constants::match_flag_type MatchFlag;
00034
00035 static REFlag DefaultREFlags = boost::regex_constants::normal;
00036 static MatchFlag DefaultMatchFlags = boost::regex_constants::match_default;
00037
00038 public:
00039 static std::string sprintf(const char* format, ...) throw ();
00040 static std::string sprintf(const std::string &format, ...) throw ();
00041 static std::string vsprintf(const char* format, va_list args) throw ();
00042 static std::string vsprintf(const std::string &format, va_list args) throw ();
00043
00044 static std::string substr_replace(const std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00045 static std::string& substr_replace(std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00046
00047 static std::string substr_ireplace(const std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00048 static std::string& substr_ireplace(std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00049
00050 LIBUTIL_API_DEPRECATED static std::string& substr_replace2(std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00051 LIBUTIL_API_DEPRECATED static std::string& substr_ireplace2(std::string &src, const std::string &search, const std::string &replace = "", bool global = true) throw ();
00052
00053 static std::string regex_replace(const std::string &src, const boost::regex ®ex, const std::string &replace = "", MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00054 static std::string regex_replace(const std::string &src, const std::string ®ex, const std::string &replace = "", REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00055 static std::string& regex_replace(std::string &src, const boost::regex ®ex, const std::string &replace = "", MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00056 static std::string& regex_replace(std::string &src, const std::string ®ex, const std::string &replace = "", REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00057
00058 static std::string regex_ireplace(const std::string &src, const boost::regex ®ex, const std::string &replace = "", MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00059 static std::string regex_ireplace(const std::string &src, const std::string ®ex, const std::string &replace = "", REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00060 static std::string& regex_ireplace(std::string &src, const boost::regex ®ex, const std::string &replace = "", MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00061 static std::string& regex_ireplace(std::string &src, const std::string ®ex, const std::string &replace = "", REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00062
00063 static bool regex_match(const std::string &src, const boost::regex ®ex, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00064 static bool regex_match(const std::string &src, const std::string ®ex, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00065 static bool regex_match(const std::string &src, const boost::regex ®ex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00066 static bool regex_match(const std::string &src, const std::string ®ex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00067 static bool regex_match(const std::string &src, const boost::regex ®ex, std::string &match, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00068 static bool regex_match(const std::string &src, const std::string ®ex, std::string &match, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00069 static bool regex_match(const std::string &src, const boost::regex ®ex, std::vector<std::string> &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00070 static bool regex_match(const std::string &src, const std::string ®ex, std::vector<std::string> &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00071
00072 static bool regex_imatch(const std::string &src, const boost::regex ®ex, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00073 static bool regex_imatch(const std::string &src, const std::string ®ex, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00074 static bool regex_imatch(const std::string &src, const boost::regex ®ex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00075 static bool regex_imatch(const std::string &src, const std::string ®ex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00076 static bool regex_imatch(const std::string &src, const boost::regex ®ex, std::string &match, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00077 static bool regex_imatch(const std::string &src, const std::string ®ex, std::string &match, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00078 static bool regex_imatch(const std::string &src, const boost::regex ®ex, std::vector<std::string> &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00079 static bool regex_imatch(const std::string &src, const std::string ®ex, std::vector<std::string> &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00080
00081 static bool regex_search(const std::string &src, const boost::regex ®ex, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00082 static bool regex_search(const std::string &src, const std::string ®ex, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00083 static bool regex_search(const std::string &src, const boost::regex ®ex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00084 static bool regex_search(const std::string &src, const std::string ®ex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00085 static bool regex_search(const std::string &src, const boost::regex ®ex, std::string &match, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00086 static bool regex_search(const std::string &src, const std::string ®ex, std::string &match, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00087 static bool regex_search(const std::string &src, const boost::regex ®ex, std::vector<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00088 static bool regex_search(const std::string &src, const std::string ®ex, std::vector<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00089
00090 static bool regex_isearch(const std::string &src, const boost::regex ®ex, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00091 static bool regex_isearch(const std::string &src, const std::string ®ex, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00092 static bool regex_isearch(const std::string &src, const boost::regex ®ex, boost::cmatch &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00093 static bool regex_isearch(const std::string &src, const std::string ®ex, boost::cmatch &matches, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00094 static bool regex_isearch(const std::string &src, const boost::regex ®ex, std::string &match, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00095 static bool regex_isearch(const std::string &src, const std::string ®ex, std::string &match, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00096 static bool regex_isearch(const std::string &src, const boost::regex ®ex, std::vector<std::string> &matches, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00097 static bool regex_isearch(const std::string &src, const boost::regex ®ex, std::vector<std::string> &matches, bool global = true, bool subexp = true, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00098 static bool regex_isearch(const std::string &src, const std::string ®ex, std::vector<std::string> &matches, bool global = true, bool subexp = true, REFlag reFlags = DefaultREFlags, MatchFlag mFlags = DefaultMatchFlags) throw (RegexException);
00099
00100 static std::vector<std::string> split(const std::string &str, const std::string &delim = " ,;:", bool exact = false, bool empty = true, size_t limit = -1) throw ();
00101 static std::vector<std::string> split(const std::string &str, char delim, bool empty = true, size_t limit = -1) throw ();
00102
00103 static std::string join(const std::vector<std::string> &src, const std::string &delim) throw ();
00104 static std::string join(const std::vector<std::string> &src, char delim = ',') throw ();
00105 static std::string join(const std::list<std::string> &src, const std::string &delim) throw ();
00106 static std::string join(const std::list<std::string> &src, char delim = ',') throw ();
00107 static std::string join(const std::set<std::string> &src, const std::string &delim) throw ();
00108 static std::string join(const std::set<std::string> &src, char delim = ',') throw ();
00109
00110 static std::string trim(const std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00111 static std::string trim(const std::string &str, char space) throw ();
00112 static std::string& trim(std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00113 static std::string& trim(std::string &str, char space) throw ();
00114 static std::string rtrim(const std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00115 static std::string rtrim(const std::string &str, char space) throw ();
00116 static std::string& rtrim(std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00117 static std::string& rtrim(std::string &str, char space) throw ();
00118 static std::string ltrim(const std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00119 static std::string ltrim(const std::string &str, char space) throw ();
00120 static std::string& ltrim(std::string &str, const std::string &space = " \t\r\n\v\f") throw ();
00121 static std::string& ltrim(std::string &str, char space) throw ();
00122
00123 static std::string lower(const std::string &src) throw ();
00124 static std::string& lower(std::string &src) throw ();
00125 static std::string upper(const std::string &src) throw ();
00126 static std::string& upper(std::string &src) throw ();
00127 static std::string ucfirst(const std::string &src) throw ();
00128 static std::string& ucfirst(std::string &src) throw ();
00129 static std::string ucword(const std::string &src) throw ();
00130 static std::string& ucword(std::string &src) throw ();
00131
00132 static std::string bandwidth(int64_t bps, int decimals = 0) throw ();
00133 static std::string bandwidth(uint64_t bps, int decimals = 0) throw ();
00134 #ifdef __LP64__
00135 static std::string bandwidth(long long bps, int decimals = 0) throw ();
00136 static std::string bandwidth(unsigned long long bps, int decimals = 0) throw ();
00137 #else
00138 static std::string bandwidth(long bps, int decimals = 0) throw ();
00139 static std::string bandwidth(unsigned long bps, int decimals = 0) throw ();
00140 #endif
00141
00142 static std::string dataSize(int64_t bytes, int decimals = 0) throw ();
00143 static std::string dataSize(uint64_t bytes, int decimals = 0) throw ();
00144 #ifdef __LP64__
00145 static std::string dataSize(long long bytes, int decimals = 0) throw ();
00146 static std::string dataSize(unsigned long long bytes, int decimals = 0) throw ();
00147 #else
00148 static std::string dataSize(long bytes, int decimals = 0) throw ();
00149 static std::string dataSize(unsigned long bytes, int decimals = 0) throw ();
00150 #endif
00151
00152 static std::string dataRate(int64_t bps, int decimals = 0) throw ();
00153 static std::string dataRate(uint64_t bps, int decimals = 0) throw ();
00154 #ifdef __LP64__
00155 static std::string dataRate(long long bps, int decimals = 0) throw ();
00156 static std::string dataRate(unsigned long long bps, int decimals = 0) throw ();
00157 #else
00158 static std::string dataRate(long bps, int decimals = 0) throw ();
00159 static std::string dataRate(unsigned long bps, int decimals = 0) throw ();
00160 #endif
00161
00162 static std::string duration(int64_t usec, int decimals = 0) throw ();
00163 static std::string duration(uint64_t usec, int decimals = 0) throw ();
00164 #ifdef __LP64__
00165 static std::string duration(long long usec, int decimals = 0) throw ();
00166 static std::string duration(unsigned long long usec, int decimals = 0) throw ();
00167 #else
00168 static std::string duration(long usec, int decimals = 0) throw ();
00169 static std::string duration(unsigned long usec, int decimals = 0) throw ();
00170 #endif
00171 };
00172
00173 #endif
00174
00175
00176
00177