From 9e2b4fd3bbc0c61bf6c84540c52869ec7d830718 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 6 Jan 2017 03:24:33 +0300 Subject: Make use of operator<<(ostream, exception) --- build2/test/script/parser.cxx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'build2/test/script/parser.cxx') diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index f545896..e5f634c 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -3,7 +3,7 @@ // license : MIT; see accompanying LICENSE file #include -#include // strstr(), strchr() +#include // strstr() #include @@ -26,20 +26,24 @@ namespace std // resembles the following: 'regex_error(error_badrepeat): '. So we skip it. // static ostream& - operator<< (ostream& os, const regex_error& e) + operator<< (ostream& o, const regex_error& e) { const char* d (e.what ()); - if (strchr (d, ' ') != nullptr) - { + #if defined(_MSC_VER) && _MSC_VER <= 1910 - const char* s (strstr (d, "): ")); - if (s != nullptr) - d = s + 3; + const char* rd (strstr (d, "): ")); + if (rd != nullptr) + d = rd + 3; #endif - os << ": " << d; - } - return os; + ostringstream os; + os << runtime_error (d); // Purify the description. + + string s (os.str ()); + if (s.find (' ') != string::npos) + o << ": " << s; + + return o; } } @@ -77,8 +81,7 @@ namespace build2 } catch (const io_error& e) { - fail << "unable to read testscript " << p << ": " << e.what () - << endf; + fail << "unable to read testscript " << p << ": " << e << endf; } } @@ -1054,8 +1057,7 @@ namespace build2 } catch (const io_error& e) { - fail (dl) << "unable to read testscript " << p << ": " - << e.what (); + fail (dl) << "unable to read testscript " << p << ": " << e; } } }; -- cgit v1.1