22 #include "ParserEventGeneratorKit.h"
23 #include "SGMLApplication.h"
34 # define timegm(tm) _mkgmtime(tm)
44 result.resize(source.len);
45 for (
size_t i = 0; i < source.len; i++)
47 result[i] =
static_cast<char>(source.ptr[i]);
55 dest.append(toBeAppended);
72 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string is 0 length!");
75 std::string ofxdate_whole =
76 ofxdate.substr(0, ofxdate.find_first_not_of(
"0123456789"));
78 if (ofxdate_whole.size() < 8)
80 message_out(
ERROR,
"ofxdate_to_time_t(): Unable to convert time, string " + ofxdate +
" is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!");
81 return std::time(NULL);
85 memset(&time, 0,
sizeof(tm));
86 time.tm_year = atoi(ofxdate_whole.substr(0, 4).c_str()) - 1900;
87 time.tm_mon = atoi(ofxdate_whole.substr(4, 2).c_str()) - 1;
88 time.tm_mday = atoi(ofxdate_whole.substr(6, 2).c_str());
90 if (ofxdate_whole.size() < 14)
92 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!");
96 time.tm_hour = atoi(ofxdate_whole.substr(8, 2).c_str());
97 time.tm_min = atoi(ofxdate_whole.substr(10, 2).c_str());
98 time.tm_sec = atoi(ofxdate_whole.substr(12, 2).c_str());
101 if (time.tm_hour + time.tm_min + time.tm_sec == 0)
106 return timegm(&time);
109 std::string::size_type startidx = ofxdate.find(
"[");
110 if (startidx != std::string::npos)
113 std::string::size_type endidx = ofxdate.find(
":", startidx) - 1;
114 std::string offset_str = ofxdate.substr(startidx, (endidx - startidx) + 1);
115 float ofx_gmt_offset = atof(offset_str.c_str());
116 std::time_t temptime = std::time(
nullptr);
117 static const double secs_per_hour = 3600.0;
118 time.tm_sec -=
static_cast<int>(ofx_gmt_offset * secs_per_hour);
119 return timegm(&time);
123 return timegm(&time);
133 std::string::size_type idx;
134 std::string tmp = ofxamount;
137 if (idx == std::string::npos)
142 if (idx != std::string::npos)
144 tmp.replace(idx, 1, 1, ((localeconv())->decimal_point)[0]);
147 return atof(tmp.c_str());
157 std::string temp_string = para_string;
158 if (temp_string.empty())
161 const char *whitespace =
" \b\f\n\r\t\v";
162 const char *abnormal_whitespace =
"\b\f\n\r\t\v";
166 i <= temp_string.size()
167 && temp_string.find_first_of(whitespace, i) == i
168 && temp_string.find_first_of(whitespace, i) != std::string::npos;
170 temp_string.erase(0, i);
172 for (i = temp_string.size() - 1;
174 && (temp_string.find_last_of(whitespace, i) == i)
175 && (temp_string.find_last_of(whitespace, i) != std::string::npos);
177 temp_string.erase(i + 1, temp_string.size() - (i + 1));
179 while ((index = temp_string.find_first_of(abnormal_whitespace)) != std::string::npos)
181 temp_string.erase(index, 1);
190 std::string get_tmp_dir()
195 var = getenv(
"TMPDIR");
199 var = getenv(
"TEMP");
208 int mkTempFileName(
const char *tmpl,
char *buffer,
unsigned int size)
211 std::string tmp_dir = get_tmp_dir();
213 strncpy(buffer, tmp_dir.c_str(), size);
214 assert((strlen(buffer) + strlen(tmpl) + 2) < size);
215 strcat(buffer, DIRSEP);
216 strcat(buffer, tmpl);