00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <StringLib.h>
00020 #include <ctime>
00021
00022 namespace StringLib{
00023
00024 void out(const string str, int dbg){
00025
00026 char date[100];
00027 time_t aclock;
00028 const struct tm *timeptr;
00029 string ret;
00030
00031 time(&aclock);
00032 timeptr = localtime(&aclock);
00033 strftime(date, sizeof(date), "%Y.%m.%d. %H:%M:%S", timeptr);
00034
00035 ret="[";
00036 for(int i=0; i<strlen(date); i++){
00037
00038 ret+=date[i];
00039
00040 }
00041
00042 ret+= "] " + str;
00043 cout << ret << endl;
00044
00045 }
00046
00047 string itos(const int _int){
00048
00049 static char _char[20];
00050 sprintf(_char, "%d", _int);
00051 return (string) _char;
00052
00053 }
00054
00055 vector<string> explode(const string& str, const string delimiter, const int max){
00056
00057 vector<string> retval;
00058 int x = str.find(delimiter);
00059
00060 if(x == -1){
00061 retval.push_back(str);
00062 return(retval);
00063 }
00064
00065 string temp = str.substr(0, x);
00066 retval.push_back(temp);
00067 int num = 1;
00068 int y;
00069
00070 while(1){
00071 num++;
00072 x += delimiter.size();
00073
00074 y = str.find(delimiter, x);
00075 if(y == -1 or num == max){
00076 break;
00077 }
00078
00079 temp = str.substr(x, (y-x));
00080 x += (y-x);
00081 retval.push_back(temp);
00082 }
00083
00084 temp = str.substr(x, (str.length() -1));
00085 retval.push_back(temp);
00086
00087 return (retval);
00088 }
00089
00090 void debug(const string str){
00091 #ifdef USE_DEBUG
00092 out("DEBUG: " + str, 1);
00093 #endif
00094 }
00095
00096 void error(const string str){
00097
00098 out("ERROR: " + str, -1);
00099
00100 }
00101
00102 vector<string> split(const string str, const string dels){
00103
00104 vector<string> ret;
00105
00106 int pos = 0;
00107 int start = 0;
00108
00109 int i;
00110 for(i=0; i<str.size(); i++){
00111
00112 if(str[i] == dels[pos]){
00113
00114 ret.push_back(str.substr(start, i-start));
00115 start = i;
00116 pos++;
00117
00118 }
00119
00120 }
00121
00122 if(str.substr(start, i-start) != ""){
00123
00124 ret.push_back(str.substr(start, i-start));
00125
00126 }
00127
00128 return ret;
00129
00130 }
00131
00132 string trim(string& str, const string& del){
00133
00134 string r=str.erase(str.find_last_not_of(del)+1);
00135 return r.erase(0,r.find_first_not_of(del));
00136
00137 }
00138
00139
00140 }
00141