blob: 4e2e26feff0de91e275a986e212689cf6ab823d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// file : libbutl/regex.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <libbutl/regex.hxx>
#if defined(_MSC_VER) && _MSC_VER <= 1910
# include <cstring> // strstr()
#endif
#include <ostream>
#include <sstream>
#include <stdexcept> // runtime_error
#include <libbutl/utility.hxx> // operator<<(ostream, exception)
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;
}
}
|