aboutsummaryrefslogtreecommitdiff
path: root/build2/regex.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-01-31 22:08:38 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-02-03 23:57:27 +0300
commit044e2e1c1460fb060f677a366144b98905522754 (patch)
tree4cdd67e9bca323d74cf5cc514444019a70b4de95 /build2/regex.cxx
parent31a4169c67045cfe37eed138b537930e259db1e9 (diff)
Add sed builtin
Diffstat (limited to 'build2/regex.cxx')
-rw-r--r--build2/regex.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/build2/regex.cxx b/build2/regex.cxx
new file mode 100644
index 0000000..40347b5
--- /dev/null
+++ b/build2/regex.cxx
@@ -0,0 +1,42 @@
+// file : build2/regex.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <build2/regex>
+
+#if defined(_MSC_VER) && _MSC_VER <= 1910
+# include <cstring> // strstr()
+#endif
+
+#include <ostream>
+#include <sstream>
+
+namespace std
+{
+ // Currently libstdc++ just returns the name of the exception (bug #67361).
+ // So we check that the description contains at least one space character.
+ //
+ // While VC's description is meaningful, it has an undesired prefix that
+ // resembles the following: 'regex_error(error_badrepeat): '. So we skip it.
+ //
+ ostream&
+ operator<< (ostream& o, const regex_error& e)
+ {
+ const char* d (e.what ());
+
+#if defined(_MSC_VER) && _MSC_VER <= 1910
+ const char* rd (strstr (d, "): "));
+ if (rd != nullptr)
+ d = rd + 3;
+#endif
+
+ ostringstream os;
+ os << runtime_error (d); // Sanitize the description.
+
+ string s (os.str ());
+ if (s.find (' ') != string::npos)
+ o << ": " << s;
+
+ return o;
+ }
+}