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 <locale.h>
00025 #include "messages.hh"
00026 #include "ofx_utilities.hh"
00027 
00028 using namespace std;
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 
00060 string CharStringtostring(const SGMLApplication::CharString source, string &dest)
00061 {
00062   size_t i;
00063   dest.assign("");
00064   
00065   for (i = 0; i < source.len; i++){
00066     dest+=(char)(((source.ptr)[i]));  
00067     
00068   }
00069   return dest;
00070 }
00071 
00072 string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
00073 {
00074   size_t i;
00075   for (i = 0; i < source.len; i++)
00076     {
00077       dest+=(char)(((source.ptr)[i]));
00078     }
00079   return dest;
00080 }
00081 
00097 time_t ofxdate_to_time_t(const string ofxdate)
00098 {
00099   struct tm time;
00100   double local_offset; 
00101   float ofx_gmt_offset; 
00102   char timezone[4]; 
00103   char exact_time_specified = false;
00104   char time_zone_specified = false;
00105 
00106   time_t temptime;
00107   std::time(&temptime);
00108   local_offset = difftime(mktime(localtime(&temptime)), mktime(gmtime(&temptime)));
00109   
00110   if(ofxdate.size()!=0){
00111     time.tm_year=atoi(ofxdate.substr(0,4).c_str())-1900;
00112     time.tm_mon=atoi(ofxdate.substr(4,2).c_str())-1;
00113     time.tm_mday=atoi(ofxdate.substr(6,2).c_str());
00114     if(ofxdate.size()>8) {
00115     
00116 exact_time_specified = true;
00117       time.tm_hour=atoi(ofxdate.substr(8,2).c_str());
00118       time.tm_min=atoi(ofxdate.substr(10,2).c_str());
00119       time.tm_sec=atoi(ofxdate.substr(12,2).c_str());
00120     }
00121     
00122     
00123     string::size_type startidx = ofxdate.find("[");
00124     string::size_type endidx;
00125     if(startidx!=string::npos){
00126       
00127       time_zone_specified = true;
00128       startidx++;
00129       endidx = ofxdate.find(":", startidx)-1;
00130       ofx_gmt_offset=atof(ofxdate.substr(startidx,(endidx-startidx)+1).c_str());
00131       startidx = endidx+2;
00132       strncpy(timezone,ofxdate.substr(startidx,3).c_str(),4);
00133     }
00134     else{
00135       
00136       ofx_gmt_offset=0;
00137       strcpy(timezone, "GMT");
00138     }
00139 
00140     if(time_zone_specified == true)
00141       {
00142         
00143         
00144         
00145         time.tm_sec = time.tm_sec + (int)(local_offset - (ofx_gmt_offset*60*60));
00146       }
00147     else if (exact_time_specified == false)
00148       {
00149         
00150        time.tm_hour=11;
00151        time.tm_min=59;
00152        time.tm_sec=0;
00153       }
00154   }
00155   else{
00156     message_out(ERROR, "ofxdate_to_time_t():  Unable to convert time, string is 0 length!");
00157   }
00158   return mktime(&time);
00159 }
00160 
00165 double ofxamount_to_double(const string ofxamount)
00166 {
00167   
00168   string::size_type idx;
00169   string tmp = ofxamount;
00170 
00171   idx = tmp.find(',');
00172   if(idx==string::npos){
00173     idx = tmp.find('.');
00174   }
00175   
00176   if(idx!=string::npos){
00177     tmp.replace(idx,1,1,((localeconv())->decimal_point)[0]);
00178   }
00179 
00180   return atof(tmp.c_str());
00181 }
00182 
00186 string strip_whitespace(const string para_string)
00187 {
00188   size_t index;
00189   size_t i;
00190   string temp_string = para_string;
00191   char *whitespace = " \b\f\n\r\t\v";
00192   char *abnormal_whitespace = "\b\f\n\r\t\v";
00193   message_out(DEBUG4,"strip_whitespace() Before: |"+temp_string+"|");
00194   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++);
00195   temp_string.erase(0,i);
00196   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--);
00197   temp_string.erase(i+1,temp_string.size()-(i+1));
00198   
00199 while ((index = temp_string.find_first_of(abnormal_whitespace))!=string::npos)
00200   {
00201     temp_string.erase(index,1);
00202   };
00203  
00204  message_out(DEBUG4,"strip_whitespace() After:  |"+temp_string+"|");
00205  
00206  return temp_string;
00207 }