22 #include "ParserEventGeneratorKit.h"
23 #include "SGMLApplication.h"
34 # define timegm(tm) _mkgmtime(tm)
76 for (i = 0; i < source.len; i++)
78 dest += (char)(((source.ptr)[i]));
87 for (i = 0; i < source.len; i++)
89 dest += (char)(((source.ptr)[i]));
108 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
111 std::string ofxdate_whole =
112 ofxdate.substr(0, ofxdate.find_first_not_of(
"0123456789"));
114 if (ofxdate_whole.size() < 8)
116 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string " + ofxdate +
" is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
117 return std::time(NULL);
121 memset(&time, 0,
sizeof(tm));
122 time.tm_year = atoi(ofxdate_whole.substr(0, 4).c_str()) - 1900;
123 time.tm_mon = atoi(ofxdate_whole.substr(4, 2).c_str()) - 1;
124 time.tm_mday = atoi(ofxdate_whole.substr(6, 2).c_str());
126 if (ofxdate_whole.size() < 14)
128 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!");
132 time.tm_hour = atoi(ofxdate_whole.substr(8, 2).c_str());
133 time.tm_min = atoi(ofxdate_whole.substr(10, 2).c_str());
134 time.tm_sec = atoi(ofxdate_whole.substr(12, 2).c_str());
137 if (time.tm_hour + time.tm_min + time.tm_sec == 0)
142 return timegm(&time);
145 std::string::size_type startidx = ofxdate.find(
"[");
146 if (startidx != std::string::npos)
149 std::string::size_type endidx = ofxdate.find(
":", startidx) - 1;
150 std::string offset_str = ofxdate.substr(startidx, (endidx - startidx) + 1);
151 float ofx_gmt_offset = atof(offset_str.c_str());
152 std::time_t temptime = std::time(
nullptr);
153 static const double secs_per_hour = 3600.0;
154 time.tm_sec -=
static_cast<int>(ofx_gmt_offset * secs_per_hour);
155 return timegm(&time);
159 return timegm(&time);
169 std::string::size_type idx;
170 std::string tmp = ofxamount;
173 if (idx == std::string::npos)
178 if (idx != std::string::npos)
180 tmp.replace(idx, 1, 1, ((localeconv())->decimal_point)[0]);
183 return atof(tmp.c_str());
193 std::string temp_string = para_string;
194 if (temp_string.empty())
197 const char *whitespace =
" \b\f\n\r\t\v";
198 const char *abnormal_whitespace =
"\b\f\n\r\t\v";
202 i <= temp_string.size()
203 && temp_string.find_first_of(whitespace, i) == i
204 && temp_string.find_first_of(whitespace, i) != std::string::npos;
206 temp_string.erase(0, i);
208 for (i = temp_string.size() - 1;
210 && (temp_string.find_last_of(whitespace, i) == i)
211 && (temp_string.find_last_of(whitespace, i) != std::string::npos);
213 temp_string.erase(i + 1, temp_string.size() - (i + 1));
215 while ((index = temp_string.find_first_of(abnormal_whitespace)) != std::string::npos)
217 temp_string.erase(index, 1);
226 std::string get_tmp_dir()
231 var = getenv(
"TMPDIR");
235 var = getenv(
"TEMP");
244 int mkTempFileName(
const char *tmpl,
char *buffer,
unsigned int size)
247 std::string tmp_dir = get_tmp_dir();
249 strncpy(buffer, tmp_dir.c_str(), size);
250 assert((strlen(buffer) + strlen(tmpl) + 2) < size);
251 strcat(buffer, DIRSEP);
252 strcat(buffer, tmpl);
int message_out(OfxMsgType error_type, const std::string message)
Message output function.
Message IO functionality.
std::string CharStringtostring(const SGMLApplication::CharString source, std::string &dest)
Convert OpenSP CharString to a C++ STL string.
std::string AppendCharStringtostring(const SGMLApplication::CharString source, std::string &dest)
Append an OpenSP CharString to an existing C++ STL string.
std::string strip_whitespace(const std::string para_string)
Sanitize a string coming from OpenSP.
double ofxamount_to_double(const std::string ofxamount)
Convert OFX amount of money to double float.
time_t ofxdate_to_time_t(const std::string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Various simple functions for type conversion & al.