37 sprintf(str,
"%d-%.02d-%.02d %.02d:%.02d:%.02d",
38 pTime->tm_year + 1900,
47 sprintf(str,
"0000-00-00 00:00:00");
50 return (std::string) str;
59 sTime = localtime(&Time);
70 sTime = gmtime(&Time);
77 if (str.find_first_of(
"+-.0123456789"))
return false;
82 if (*Tail)
return false;
94 Text =
new char[TextSize + 1];
97 va_start(Arguments, format);
98 Printed = vsnprintf(Text, TextSize + 1, format, Arguments);
101 while (Printed < 0 || TextSize < Printed)
105 (Printed < 0) ? TextSize *= 2 : TextSize = Printed;
106 Text =
new char[TextSize + 1];
109 va_start(Arguments, format);
110 Printed = vsnprintf(Text, TextSize + 1, format, Arguments);
114 std::string Result = Text;
122 std::string Name = name;
123 std::string::size_type len = Name.length();
125 if (len > 1 && Name[0] ==
'"' && Name[len - 1] ==
'"')
128 Name = Name.substr(1, len - 2);
131 std::string::size_type pos = Name.find(
"\\");
133 while (pos != std::string::npos)
137 pos = Name.find(
"\\", pos);
144 std::string
quote(
const std::string & name,
145 const std::string & additionalEscapes)
147 if (name.find_first_of(
" \"" + additionalEscapes) == std::string::npos)
150 #define toBeEscaped "\\\""
151 std::string Escaped(name);
152 std::string::size_type pos = Escaped.find_first_of(
toBeEscaped);
154 while (pos != std::string::npos)
156 Escaped.insert(pos,
"\\");
161 return "\"" + Escaped +
"\"";
165 bool stringReplace(std::string & str,
const std::string & target,
const std::string & replacement)
167 bool replaced =
false;
169 std::string::size_type pos = str.find(target, 0);
171 while (pos != std::string::npos)
175 str.replace(pos, target.length(), replacement, 0, std::string::npos);
176 pos = str.find(target, 0);
188 void FixSName(
const std::string &original, std::string &fixed)
193 if (original ==
"abs") {fixed =
"_abs";
return;}
195 if (original ==
"acos") {fixed =
"_acos";
return;}
197 if (original ==
"and") {fixed =
"_and";
return;}
199 if (original ==
"asin") {fixed =
"_asin";
return;}
201 if (original ==
"atan") {fixed =
"_atan";
return;}
203 if (original ==
"ceil") {fixed =
"_ceil";
return;}
205 if (original ==
"cos") {fixed =
"_cos";
return;}
207 if (original ==
"exp") {fixed =
"_exp";
return;}
209 if (original ==
"floor") {fixed =
"_floor";
return;}
211 if (original ==
"hilli") {fixed =
"_hilli";
return;}
213 if (original ==
"hillmmr") {fixed =
"_hillmmr";
return;}
215 if (original ==
"hillmr") {fixed =
"_hillmr";
return;}
217 if (original ==
"hillr") {fixed =
"_hillr";
return;}
219 if (original ==
"isouur") {fixed =
"_isouur";
return;}
221 if (original ==
"log") {fixed =
"_log";
return;}
223 if (original ==
"log10") {fixed =
"_log10";
return;}
225 if (original ==
"massi") {fixed =
"_massi";
return;}
227 if (original ==
"massr") {fixed =
"_massr";
return;}
229 if (original ==
"not") {fixed =
"_not";
return;}
231 if (original ==
"or") {fixed =
"_or";
return;}
233 if (original ==
"ordbbr") {fixed =
"_ordbbr";
return;}
235 if (original ==
"ordbur") {fixed =
"_ordbur";
return;}
237 if (original ==
"ordubr") {fixed =
"_ordubr";
return;}
239 if (original ==
"pow") {fixed =
"_pow";
return;}
241 if (original ==
"ppbr") {fixed =
"_ppbr";
return;}
243 if (original ==
"sin") {fixed =
"_sin";
return;}
245 if (original ==
"sqr") {fixed =
"_sqr";
return;}
247 if (original ==
"sqrt") {fixed =
"_sqrt";
return;}
249 if (original ==
"substance") {fixed =
"_substance";
return;}
251 if (original ==
"time") {fixed =
"_time";
return;}
253 if (original ==
"tan") {fixed =
"_tan";
return;}
255 if (original ==
"umai") {fixed =
"_umai";
return;}
257 if (original ==
"umar") {fixed =
"_umar";
return;}
259 if (original ==
"uai") {fixed =
"_uai";
return;}
261 if (original ==
"ualii") {fixed =
"_ualii";
return;}
263 if (original ==
"uar") {fixed =
"_uar";
return;}
265 if (original ==
"ucii") {fixed =
"_ucii";
return;}
267 if (original ==
"ucir") {fixed =
"_ucir";
return;}
269 if (original ==
"ucti") {fixed =
"_ucti";
return;}
271 if (original ==
"uctr") {fixed =
"_uctr";
return;}
273 if (original ==
"uhmi") {fixed =
"_uhmi";
return;}
275 if (original ==
"uhmr") {fixed =
"_uhmr";
return;}
277 if (original ==
"umi") {fixed =
"_umi";
return;}
279 if (original ==
"unii") {fixed =
"_unii";
return;}
281 if (original ==
"unir") {fixed =
"_unir";
return;}
283 if (original ==
"uuhr") {fixed =
"_uuhr";
return;}
285 if (original ==
"umr") {fixed =
"_umr";
return;}
287 if (original ==
"usii") {fixed =
"_usii";
return;}
289 if (original ==
"usir") {fixed =
"_usir";
return;}
291 if (original ==
"uuci") {fixed =
"_uuci";
return;}
293 if (original ==
"uucr") {fixed =
"_uucr";
return;}
295 if (original ==
"uui") {fixed =
"_uui";
return;}
297 if (original ==
"uur") {fixed =
"_uur";
return;}
299 if (original ==
"volume") {fixed =
"_volume";
return;}
301 if (original ==
"xor") {fixed =
"_xor";
return;}
303 len = original.length();
307 if (((original[0] <
'A') || (original[0] >
'z')) && (original[0] !=
'_'))
309 if ((original[0] >=
'0') && (original[0] <=
'9'))
310 fixed =
"_" + original;
312 {fixed = original; fixed [0] =
'_';}
317 len = fixed.length();
319 for (i = 1; i < len; i++)
320 if ((fixed [i] !=
'_') && ((fixed [i] <
'A') || (fixed [i] >
'z')) &&
321 ((fixed [i] <
'0') || (fixed [i] >
'9')))
328 double Value = std::numeric_limits<C_FLOAT64>::quiet_NaN();
335 if (str == NULL || *str == 0x0)
340 std::istringstream in;
342 in.imbue(std::locale::classic());
347 if (pTail != NULL && !isnan(Value))
349 *pTail = str + std::min< size_t >(in.tellg(), strlen(str));
357 C_INT32 Value = std::numeric_limits< C_INT32 >::quiet_NaN();
364 if (str == NULL || *str == 0x0)
369 std::istringstream in;
371 in.imbue(std::locale::classic());
376 if (pTail != NULL && !isnan(Value))
378 *pTail = str + std::min< size_t >(in.tellg(), strlen(str));
387 unsigned C_INT32 Value = std::numeric_limits< unsigned C_INT32 >::quiet_NaN();
394 if (str == NULL || *str == 0x0)
399 std::istringstream in;
401 in.imbue(std::locale::classic());
406 if (pTail != NULL && !isnan(Value))
408 *pTail = str + std::min< size_t >(in.tellg(), strlen(str));
418 sscanf(str.c_str(),
"%p", &pPointer);
427 int Printed = sprintf(String,
"%p", pVoid);
429 if (Printed < 0 || 18 < Printed)
445 std::ostringstream IdStream;
447 std::string::const_iterator it = name.begin();
448 std::string::const_iterator end = name.end();
450 if (
'0' <= *it && *it <=
'9')
455 for (; it != end; ++it)
458 if (0x80 == (*it & 0xc0))
463 if ((
'0' <= *it && *it <=
'9') ||
464 (
'a' <= *it && *it <=
'z') ||
465 (
'A' <= *it && *it <=
'Z'))
475 std::string Id = IdStream.str();
477 if (Id[Id.length() - 1] !=
'_')
482 return Id.substr(0, Id.length() - 1);
std::string unQuote(const std::string &name)
bool stringReplace(std::string &str, const std::string &target, const std::string &replacement)
std::string LocalTimeStamp()
bool isNumber(const std::string &str)
std::string nameToSbmlId(const std::string &name)
std::string ISODateTime(tm *pTime)
std::string pointerToString(const void *pVoid)
void FixSName(const std::string &original, std::string &fixed)
unsigned C_INT32 strToUnsignedInt(const char *str, char const **pTail)
std::string quote(const std::string &name, const std::string &additionalEscapes)
double strToDouble(const char *str, char const **pTail)
void * stringToPointer(const std::string str)
std::string StringPrint(const char *format,...)
std::string UTCTimeStamp()
C_INT32 strToInt(const char *str, char const **pTail)