00001
00002
00003
00004
00005
00006
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <config.h>
00019 #include <iostream>
00020 #include "ParserEventGeneratorKit.h"
00021 #include "SGMLApplication.h"
00022 #include <time.h>
00023 #include <string>
00024 #include "messages.hh"
00025 #include "ofx_utilities.hh"
00026
00027 using namespace std;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 string CharStringtostring(const SGMLApplication::CharString source, string &dest)
00060 {
00061 size_t i;
00062 dest.assign("");
00063
00064 for (i = 0; i < source.len; i++){
00065 dest+=(char)(((source.ptr)[i]));
00066
00067 }
00068 return dest;
00069 }
00070
00071 string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
00072 {
00073 size_t i;
00074 for (i = 0; i < source.len; i++)
00075 {
00076 dest+=(char)(((source.ptr)[i]));
00077 }
00078 return dest;
00079 }
00080
00084 time_t ofxdate_to_time_t(const string ofxdate)
00085 {
00086 struct tm time;
00087 double local_offset;
00088 float ofx_gmt_offset;
00089 char timezone[4];
00090 time_t temptime;
00091 std::time(&temptime);
00092 local_offset = difftime(mktime(localtime(&temptime)), mktime(gmtime(&temptime)));
00093
00094 if(ofxdate.size()!=0){
00095 time.tm_year=atoi(ofxdate.substr(0,4).c_str())-1900;
00096 time.tm_mon=atoi(ofxdate.substr(4,2).c_str())-1;
00097 time.tm_mday=atoi(ofxdate.substr(6,2).c_str());
00098
00099 if(ofxdate.size()>8) {
00100 time.tm_hour=atoi(ofxdate.substr(8,2).c_str());
00101 time.tm_min=atoi(ofxdate.substr(10,2).c_str());
00102 time.tm_sec=atoi(ofxdate.substr(12,2).c_str());
00103 }
00104 else{
00105 time.tm_hour=12;
00106 time.tm_min=0;
00107 time.tm_sec=0;
00108 }
00109
00110
00111
00112
00113 string::size_type startidx = ofxdate.find("[");
00114 string::size_type endidx;
00115 if(startidx!=string::npos){
00116 startidx++;
00117 endidx = ofxdate.find(":", startidx)-1;
00118 ofx_gmt_offset=atof(ofxdate.substr(startidx,(endidx-startidx)+1).c_str());
00119 startidx = endidx+2;
00120 strncpy(timezone,ofxdate.substr(startidx,3).c_str(),4);
00121 }
00122 else{
00123 ofx_gmt_offset=0;
00124 strcpy(timezone, "GMT");
00125 }
00126
00127 time.tm_sec = time.tm_sec + (int)(local_offset - (ofx_gmt_offset*60*60));
00128 }
00129 else{
00130 message_out(ERROR, "ofxdate_to_time_t():Unable to convert time, string is 0 length!");
00131 }
00132 return mktime(&time);
00133 }
00134
00139 double ofxamount_to_double(const string ofxamount)
00140 {
00141
00142 string::size_type idx;
00143 string tmp = ofxamount;
00144
00145 idx = tmp.find(',');
00146 if(idx==string::npos){
00147 idx = tmp.find('.');
00148 }
00149
00150 if(idx!=string::npos){
00151 tmp.replace(idx,1,1,((localeconv())->decimal_point)[0]);
00152 }
00153
00154 return atof(tmp.c_str());
00155 }
00156
00160 string strip_whitespace(const string para_string)
00161 {
00162 size_t index;
00163 size_t i;
00164 string temp_string = para_string;
00165 char *whitespace = " \b\f\n\r\t\v";
00166 char *abnormal_whitespace = "\b\f\n\r\t\v";
00167 message_out(DEBUG4,"strip_whitespace() Before: |"+temp_string+"|");
00168 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++);
00169 temp_string.erase(0,i);
00170 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--);
00171 temp_string.erase(i+1,temp_string.size()-(i+1));
00172
00173 while ((index = temp_string.find_first_of(abnormal_whitespace))!=string::npos)
00174 {
00175 temp_string.erase(index,1);
00176 };
00177
00178 message_out(DEBUG4,"strip_whitespace() After: |"+temp_string+"|");
00179
00180 return temp_string;
00181 }