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]));
95 checked_mktime(
struct tm* timeptr)
97 int is_dst = timeptr->tm_isdst;
98 int min = timeptr->tm_min;
99 int hour = timeptr->tm_hour;
100 int mday = timeptr->tm_mday;
101 int mon = timeptr->tm_mon;
102 int year = timeptr->tm_year;
103 time_t result = mktime(timeptr);
104 if (is_dst == timeptr->tm_isdst)
108 timeptr->tm_min = min;
109 timeptr->tm_hour = hour;
110 timeptr->tm_mday = mday;
111 timeptr->tm_mon = mon;
112 timeptr->tm_year = year;
113 return mktime(timeptr);
135 float ofx_gmt_offset;
137 char exact_time_specified =
false;
138 char time_zone_specified =
false;
139 string ofxdate_whole;
142 std::time(&temptime);
143 local_offset = difftime(mktime(localtime(&temptime)), mktime(gmtime(&temptime)));
145 time.tm_isdst = daylight;
147 if (ofxdate.size() != 0)
149 ofxdate_whole = ofxdate.substr(0, ofxdate.find_first_not_of(
"0123456789"));
150 if (ofxdate_whole.size() >= 8)
152 time.tm_year = atoi(ofxdate_whole.substr(0, 4).c_str()) - 1900;
153 time.tm_mon = atoi(ofxdate_whole.substr(4, 2).c_str()) - 1;
154 time.tm_mday = atoi(ofxdate_whole.substr(6, 2).c_str());
156 if (ofxdate_whole.size() > 8)
158 if (ofxdate_whole.size() == 14)
161 exact_time_specified =
true;
162 time.tm_hour = atoi(ofxdate_whole.substr(8, 2).c_str());
163 time.tm_min = atoi(ofxdate_whole.substr(10, 2).c_str());
164 time.tm_sec = atoi(ofxdate_whole.substr(12, 2).c_str());
168 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!");
176 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string " + ofxdate +
" is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
177 return checked_mktime(&time);
182 string::size_type startidx = ofxdate.find(
"[");
183 string::size_type endidx;
184 if (startidx != string::npos)
187 time_zone_specified =
true;
189 endidx = ofxdate.find(
":", startidx) - 1;
190 ofx_gmt_offset = atof(ofxdate.substr(startidx, (endidx - startidx) + 1).c_str());
191 startidx = endidx + 2;
192 strncpy(timezone, ofxdate.substr(startidx, 3).c_str(), 4);
199 strcpy(timezone,
"GMT");
202 if (time_zone_specified ==
true)
207 time.tm_sec = time.tm_sec + (int)(local_offset - (ofx_gmt_offset * 60 * 60));
209 else if (exact_time_specified ==
false)
216 return checked_mktime(&time);
220 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
223 return checked_mktime(&time);
233 string::size_type idx;
234 string tmp = ofxamount;
237 if (idx == string::npos)
242 if (idx != string::npos)
244 tmp.replace(idx, 1, 1, ((localeconv())->decimal_point)[0]);
247 return atof(tmp.c_str());
257 string temp_string = para_string;
258 if (temp_string.empty())
261 const char *whitespace =
" \b\f\n\r\t\v";
262 const char *abnormal_whitespace =
"\b\f\n\r\t\v";
266 i <= temp_string.size()
267 && temp_string.find_first_of(whitespace, i) == i
268 && temp_string.find_first_of(whitespace, i) != string::npos;
270 temp_string.erase(0, i);
272 for (i = temp_string.size() - 1;
274 && (temp_string.find_last_of(whitespace, i) == i)
275 && (temp_string.find_last_of(whitespace, i) != string::npos);
277 temp_string.erase(i + 1, temp_string.size() - (i + 1));
279 while ((index = temp_string.find_first_of(abnormal_whitespace)) != string::npos)
281 temp_string.erase(index, 1);
290 std::string get_tmp_dir()
295 var = getenv(
"TMPDIR");
299 var = getenv(
"TEMP");
308 int mkTempFileName(
const char *tmpl,
char *buffer,
unsigned int size)
311 std::string tmp_dir = get_tmp_dir();
313 strncpy(buffer, tmp_dir.c_str(), size);
314 assert((strlen(buffer) + strlen(tmpl) + 2) < size);
315 strcat(buffer, DIRSEP);
316 strcat(buffer, tmpl);
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.
string strip_whitespace(const string para_string)
Sanitize a string coming from OpenSP.
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
int message_out(OfxMsgType error_type, const string message)
Message output function.
string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
Append an OpenSP CharString to an existing C++ STL string.
Message IO functionality.