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 int local_offset;
00088 float ofx_gmt_offset;
00089 char timezone[4];
00090 time_t temptime;
00091 std::time(&temptime);
00092 local_offset = (localtime(&temptime))->tm_gmtoff;
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 + (local_offset - ((int)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
00138 double ofxamount_to_double(const string ofxamount)
00139 {
00140
00141 string::size_type idx;
00142 string tmp = ofxamount;
00143 idx = tmp.find(',');
00144 if(idx!=string::npos){
00145 tmp.replace(idx,1,1,'.');
00146 }
00147 return atof(tmp.c_str());
00148 }
00149
00153 string strip_whitespace(const string para_string)
00154 {
00155 size_t index;
00156 size_t i;
00157 string temp_string = para_string;
00158 char *whitespace = " \b\f\n\r\t\v";
00159 char *abnormal_whitespace = "\b\f\n\r\t\v";
00160 message_out(DEBUG4,"strip_whitespace() Before: |"+temp_string+"|");
00161 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++);
00162 temp_string.erase(0,i);
00163 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--);
00164 temp_string.erase(i+1,temp_string.size()-(i+1));
00165
00166 while ((index = temp_string.find_first_of(abnormal_whitespace))!=string::npos)
00167 {
00168 temp_string.erase(index,1);
00169 };
00170
00171 message_out(DEBUG4,"strip_whitespace() After: |"+temp_string+"|");
00172
00173 return temp_string;
00174 }