C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2015-05-03 22:02:44 +10:00
parent 4614db6acb
commit 3f228b3f86
2 changed files with 19 additions and 8 deletions

View File

@ -250,9 +250,12 @@ namespace exprtk
inline void cleanup_escapes(std::string& s)
{
std::string::iterator itr1 = s.begin();
std::string::iterator itr2 = s.begin();
std::string::iterator end = s.end ();
typedef std::string::iterator str_itr_t;
str_itr_t itr1 = s.begin();
str_itr_t itr2 = s.begin();
str_itr_t end = s.end ();
std::size_t removal_count = 0;
while (end != itr1)
@ -270,7 +273,7 @@ namespace exprtk
case 'n' : (*itr1) = '\n'; break;
case 'r' : (*itr1) = '\r'; break;
case 't' : (*itr1) = '\t'; break;
case '0' : parse_hex(itr1,end,(*itr1));
case '0' : parse_hex(itr1, end, (*itr1));
removal_count += 3;
break;
}
@ -2505,7 +2508,7 @@ namespace exprtk
while (!is_end(s_itr_))
{
if ('\\' == *s_itr_)
if (!escaped && ('\\' == *s_itr_))
{
escaped_found = true;
escaped = true;

View File

@ -2266,7 +2266,11 @@ inline bool run_test02()
test_ab<T>("'\\0x30\\n\\0x31\\n\\0x32\\n\\0x33' == '0\\n1\\n2\\n3'" ,"","",T(1.0)),
test_ab<T>("('\\0x30' + '') == '0'" ,"","",T(1.0)),
test_ab<T>("('\\0x30' + '\\0x31\\0x32') == '012'" ,"","",T(1.0)),
test_ab<T>("('\\0x30' + '\\0x31\\0x32' + '\\0x33\\0x34\\0x35') == '012345'" ,"","",T(1.0))
test_ab<T>("('\\0x30' + '\\0x31\\0x32' + '\\0x33\\0x34\\0x35') == '012345'" ,"","",T(1.0)),
test_ab<T>("'a\\'\\\\b' == a" ,"a'\\b","",T(1.0)),
test_ab<T>("'a\\\\\\'b' == a" ,"a\\'b","",T(1.0)),
test_ab<T>("'a\\'\\\\\\\\b' == a" ,"a'\\\\b","",T(1.0)),
test_ab<T>("'a\\0x30\\'\\0x31\\\\\\0x32b' == a" ,"a0'1\\2b","",T(1.0))
};
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_ab<T>);
@ -2323,10 +2327,14 @@ inline bool run_test02()
if (not_equal(expr_result,test.result))
{
printf("run_test02() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
printf("run_test02() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\t"
"a='%s'\tb='%s'\tc='%s'\n",
test.expr.c_str(),
(double)test.result,
(double)expr_result);
(double)expr_result,
str_a.c_str(),
str_b.c_str(),
str_c.c_str());
result = false;
continue;