00001
00002
00003
00004
00005
00006
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <config.h>
00019 #include <iostream>
00020 #include <assert.h>
00021
00022 #include "ParserEventGeneratorKit.h"
00023 #include "SGMLApplication.h"
00024 #include <time.h>
00025 #include <string>
00026 #include <locale.h>
00027 #include "messages.hh"
00028 #include "ofx_utilities.hh"
00029
00030 #ifdef OS_WIN32
00031 # define DIRSEP "\\"
00032 #else
00033 # define DIRSEP "/"
00034 #endif
00035
00036
00037 using namespace std;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 string CharStringtostring(const SGMLApplication::CharString source, string &dest)
00070 {
00071 size_t i;
00072 dest.assign("");
00073
00074 for (i = 0; i < source.len; i++){
00075 dest+=(char)(((source.ptr)[i]));
00076
00077 }
00078 return dest;
00079 }
00080
00081 string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
00082 {
00083 size_t i;
00084 for (i = 0; i < source.len; i++)
00085 {
00086 dest+=(char)(((source.ptr)[i]));
00087 }
00088 return dest;
00089 }
00090
00106 time_t ofxdate_to_time_t(const string ofxdate)
00107 {
00108 struct tm time;
00109 double local_offset;
00110 float ofx_gmt_offset;
00111 char timezone[4];
00112 char exact_time_specified = false;
00113 char time_zone_specified = false;
00114
00115 time_t temptime;
00116 std::time(&temptime);
00117 local_offset = difftime(mktime(localtime(&temptime)), mktime(gmtime(&temptime)));
00118
00119 if(ofxdate.size()!=0){
00120 time.tm_year=atoi(ofxdate.substr(0,4).c_str())-1900;
00121 time.tm_mon=atoi(ofxdate.substr(4,2).c_str())-1;
00122 time.tm_mday=atoi(ofxdate.substr(6,2).c_str());
00123 if(ofxdate.size()>8) {
00124
00125 exact_time_specified = true;
00126 time.tm_hour=atoi(ofxdate.substr(8,2).c_str());
00127 time.tm_min=atoi(ofxdate.substr(10,2).c_str());
00128 time.tm_sec=atoi(ofxdate.substr(12,2).c_str());
00129 }
00130
00131
00132 string::size_type startidx = ofxdate.find("[");
00133 string::size_type endidx;
00134 if(startidx!=string::npos){
00135
00136 time_zone_specified = true;
00137 startidx++;
00138 endidx = ofxdate.find(":", startidx)-1;
00139 ofx_gmt_offset=atof(ofxdate.substr(startidx,(endidx-startidx)+1).c_str());
00140 startidx = endidx+2;
00141 strncpy(timezone,ofxdate.substr(startidx,3).c_str(),4);
00142 }
00143 else{
00144
00145 ofx_gmt_offset=0;
00146 strcpy(timezone, "GMT");
00147 }
00148
00149 if(time_zone_specified == true)
00150 {
00151
00152
00153
00154 time.tm_sec = time.tm_sec + (int)(local_offset - (ofx_gmt_offset*60*60));
00155 }
00156 else if (exact_time_specified == false)
00157 {
00158
00159 time.tm_hour=11;
00160 time.tm_min=59;
00161 time.tm_sec=0;
00162 }
00163 }
00164 else{
00165 message_out(ERROR, "ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
00166 }
00167 return mktime(&time);
00168 }
00169
00174 double ofxamount_to_double(const string ofxamount)
00175 {
00176
00177 string::size_type idx;
00178 string tmp = ofxamount;
00179
00180 idx = tmp.find(',');
00181 if(idx==string::npos){
00182 idx = tmp.find('.');
00183 }
00184
00185 if(idx!=string::npos){
00186 tmp.replace(idx,1,1,((localeconv())->decimal_point)[0]);
00187 }
00188
00189 return atof(tmp.c_str());
00190 }
00191
00195 string strip_whitespace(const string para_string)
00196 {
00197 size_t index;
00198 size_t i;
00199 string temp_string = para_string;
00200 const char *whitespace = " \b\f\n\r\t\v";
00201 const char *abnormal_whitespace = "\b\f\n\r\t\v";
00202 message_out(DEBUG4,"strip_whitespace() Before: |"+temp_string+"|");
00203 for(i=0;i<=temp_string.size()&&temp_string.find_first_of(whitespace, i)==i&&temp_string.find_first_of(whitespace, i)!=string::npos;i++);
00204 temp_string.erase(0,i);
00205 for(i=temp_string.size()-1;(i>=0)&&(temp_string.find_last_of(whitespace, i)==i)&&(temp_string.find_last_of(whitespace, i)!=string::npos);i--);
00206 temp_string.erase(i+1,temp_string.size()-(i+1));
00207
00208 while ((index = temp_string.find_first_of(abnormal_whitespace))!=string::npos)
00209 {
00210 temp_string.erase(index,1);
00211 };
00212
00213 message_out(DEBUG4,"strip_whitespace() After: |"+temp_string+"|");
00214
00215 return temp_string;
00216 }
00217
00218
00219 int mkTempFileName(const char *tmpl, char *buffer, unsigned int size) {
00220 const char *tmp_dir;
00221
00222 tmp_dir = getenv ("TMPDIR");
00223 if (!tmp_dir)
00224 tmp_dir = getenv ("TMP");
00225 if (!tmp_dir)
00226 tmp_dir = getenv ("TEMP");
00227
00228 if (!tmp_dir)
00229 {
00230 #ifdef OS_WIN32
00231 tmp_dir = "C:\\";
00232 #else
00233 tmp_dir = "/tmp";
00234 #endif
00235 }
00236
00237 strncpy(buffer, tmp_dir, size);
00238 assert((strlen(buffer)+strlen(tmpl)+2)<size);
00239 strcat(buffer, DIRSEP);
00240 strcat(buffer, tmpl);
00241 return 0;
00242 }
00243
00244
00245