22 #include "ParserEventGeneratorKit.h"
23 #include "SGMLApplication.h"
75 for (i = 0; i < source.len; i++)
77 dest += (char)(((source.ptr)[i]));
86 for (i = 0; i < source.len; i++)
88 dest += (char)(((source.ptr)[i]));
107 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
110 string ofxdate_whole =
111 ofxdate.substr(0, ofxdate.find_first_not_of(
"0123456789"));
113 if (ofxdate_whole.size() < 8)
115 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string " + ofxdate +
" is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
116 return std::time(NULL);
120 memset(&time, 0,
sizeof(tm));
121 time.tm_year = atoi(ofxdate_whole.substr(0, 4).c_str()) - 1900;
122 time.tm_mon = atoi(ofxdate_whole.substr(4, 2).c_str()) - 1;
123 time.tm_mday = atoi(ofxdate_whole.substr(6, 2).c_str());
125 if (ofxdate_whole.size() < 14)
127 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!");
131 time.tm_hour = atoi(ofxdate_whole.substr(8, 2).c_str());
132 time.tm_min = atoi(ofxdate_whole.substr(10, 2).c_str());
133 time.tm_sec = atoi(ofxdate_whole.substr(12, 2).c_str());
136 if (time.tm_hour + time.tm_min + time.tm_sec == 0)
141 return timegm(&time);
144 string::size_type startidx = ofxdate.find(
"[");
145 if (startidx != string::npos)
148 string::size_type endidx = ofxdate.find(
":", startidx) - 1;
149 string offset_str = ofxdate.substr(startidx, (endidx - startidx) + 1);
150 float ofx_gmt_offset = atof(offset_str.c_str());
151 std::time_t temptime = std::time(
nullptr);
152 static const double secs_per_hour = 3600.0;
153 time.tm_sec +=
static_cast<int>(ofx_gmt_offset * secs_per_hour);
154 return timegm(&time);
158 return timegm(&time);
168 string::size_type idx;
169 string tmp = ofxamount;
172 if (idx == string::npos)
177 if (idx != string::npos)
179 tmp.replace(idx, 1, 1, ((localeconv())->decimal_point)[0]);
182 return atof(tmp.c_str());
192 string temp_string = para_string;
193 if (temp_string.empty())
196 const char *whitespace =
" \b\f\n\r\t\v";
197 const char *abnormal_whitespace =
"\b\f\n\r\t\v";
201 i <= temp_string.size()
202 && temp_string.find_first_of(whitespace, i) == i
203 && temp_string.find_first_of(whitespace, i) != string::npos;
205 temp_string.erase(0, i);
207 for (i = temp_string.size() - 1;
209 && (temp_string.find_last_of(whitespace, i) == i)
210 && (temp_string.find_last_of(whitespace, i) != string::npos);
212 temp_string.erase(i + 1, temp_string.size() - (i + 1));
214 while ((index = temp_string.find_first_of(abnormal_whitespace)) != string::npos)
216 temp_string.erase(index, 1);
225 std::string get_tmp_dir()
230 var = getenv(
"TMPDIR");
234 var = getenv(
"TEMP");
243 int mkTempFileName(
const char *tmpl,
char *buffer,
unsigned int size)
246 std::string tmp_dir = get_tmp_dir();
248 strncpy(buffer, tmp_dir.c_str(), size);
249 assert((strlen(buffer) + strlen(tmpl) + 2) < size);
250 strcat(buffer, DIRSEP);
251 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.