22 #include "ParserEventGeneratorKit.h"
23 #include "SGMLApplication.h"
34 # define timegm(tm) _mkgmtime(tm)
77 for (i = 0; i < source.len; i++)
79 dest += (char)(((source.ptr)[i]));
88 for (i = 0; i < source.len; i++)
90 dest += (char)(((source.ptr)[i]));
109 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
112 string ofxdate_whole =
113 ofxdate.substr(0, ofxdate.find_first_not_of(
"0123456789"));
115 if (ofxdate_whole.size() < 8)
117 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string " + ofxdate +
" is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
118 return std::time(NULL);
122 memset(&time, 0,
sizeof(tm));
123 time.tm_year = atoi(ofxdate_whole.substr(0, 4).c_str()) - 1900;
124 time.tm_mon = atoi(ofxdate_whole.substr(4, 2).c_str()) - 1;
125 time.tm_mday = atoi(ofxdate_whole.substr(6, 2).c_str());
127 if (ofxdate_whole.size() < 14)
129 message_out(
WARNING,
"ofxdate_to_time_t(): Successfully parsed date part, but unable to parse time part of string " + ofxdate_whole +
". It is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
133 time.tm_hour = atoi(ofxdate_whole.substr(8, 2).c_str());
134 time.tm_min = atoi(ofxdate_whole.substr(10, 2).c_str());
135 time.tm_sec = atoi(ofxdate_whole.substr(12, 2).c_str());
138 if (time.tm_hour + time.tm_min + time.tm_sec == 0)
143 return timegm(&time);
146 string::size_type startidx = ofxdate.find(
"[");
147 if (startidx != string::npos)
150 string::size_type endidx = ofxdate.find(
":", startidx) - 1;
151 string offset_str = ofxdate.substr(startidx, (endidx - startidx) + 1);
152 float ofx_gmt_offset = atof(offset_str.c_str());
153 std::time_t temptime = std::time(
nullptr);
154 static const double secs_per_hour = 3600.0;
155 time.tm_sec -=
static_cast<int>(ofx_gmt_offset * secs_per_hour);
156 return timegm(&time);
160 return timegm(&time);
170 string::size_type idx;
171 string tmp = ofxamount;
174 if (idx == string::npos)
179 if (idx != string::npos)
181 tmp.replace(idx, 1, 1, ((localeconv())->decimal_point)[0]);
184 return atof(tmp.c_str());
194 string temp_string = para_string;
195 if (temp_string.empty())
198 const char *whitespace =
" \b\f\n\r\t\v";
199 const char *abnormal_whitespace =
"\b\f\n\r\t\v";
203 i <= temp_string.size()
204 && temp_string.find_first_of(whitespace, i) == i
205 && temp_string.find_first_of(whitespace, i) != string::npos;
207 temp_string.erase(0, i);
209 for (i = temp_string.size() - 1;
211 && (temp_string.find_last_of(whitespace, i) == i)
212 && (temp_string.find_last_of(whitespace, i) != string::npos);
214 temp_string.erase(i + 1, temp_string.size() - (i + 1));
216 while ((index = temp_string.find_first_of(abnormal_whitespace)) != string::npos)
218 temp_string.erase(index, 1);
227 std::string get_tmp_dir()
232 var = getenv(
"TMPDIR");
236 var = getenv(
"TEMP");
245 int mkTempFileName(
const char *tmpl,
char *buffer,
unsigned int size)
248 std::string tmp_dir = get_tmp_dir();
250 strncpy(buffer, tmp_dir.c_str(), size);
251 assert((strlen(buffer) + strlen(tmpl) + 2) < size);
252 strcat(buffer, DIRSEP);
253 strcat(buffer, tmpl);
int message_out(OfxMsgType error_type, const string message)
Message output function.
Message IO functionality.
string strip_whitespace(const string para_string)
Sanitize a string coming from OpenSP.
string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
Append an OpenSP CharString to an existing C++ STL string.
time_t ofxdate_to_time_t(const string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
string CharStringtostring(const SGMLApplication::CharString source, string &dest)
Convert OpenSP CharString to a C++ STL string.
Various simple functions for type conversion & al.