1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/url
7  
// Official repository: https://github.com/boostorg/url
8  
//
8  
//
9  

9  

10  

10  

11  
#include <boost/url/detail/config.hpp>
11  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/grammar/error.hpp>
12  
#include <boost/url/grammar/error.hpp>
13  

13  

14  
namespace boost {
14  
namespace boost {
15  
namespace urls {
15  
namespace urls {
16  
namespace grammar {
16  
namespace grammar {
17  

17  

18  
namespace detail {
18  
namespace detail {
19  

19  

20  
const char*
20  
const char*
21  
error_cat_type::
21  
error_cat_type::
22  
name() const noexcept
22  
name() const noexcept
23  
{
23  
{
24  
    return "boost.url.grammar";
24  
    return "boost.url.grammar";
25  
}
25  
}
26  

26  

27  
std::string
27  
std::string
28  
error_cat_type::
28  
error_cat_type::
29  
message(int code) const
29  
message(int code) const
30  
{
30  
{
31  
    return message(code, nullptr, 0);
31  
    return message(code, nullptr, 0);
32  
}
32  
}
33  

33  

34  
char const*
34  
char const*
35  
error_cat_type::
35  
error_cat_type::
36  
message(
36  
message(
37  
    int code,
37  
    int code,
38  
    char*,
38  
    char*,
39  
    std::size_t) const noexcept
39  
    std::size_t) const noexcept
40  
{
40  
{
41  
    switch(static_cast<error>(code))
41  
    switch(static_cast<error>(code))
42  
    {
42  
    {
43  
    default:
43  
    default:
44  
case error::need_more: return "need more";
44  
case error::need_more: return "need more";
45  
case error::mismatch: return "mismatch";
45  
case error::mismatch: return "mismatch";
46  
case error::invalid: return "invalid";
46  
case error::invalid: return "invalid";
47  
case error::end_of_range: return "end of range";
47  
case error::end_of_range: return "end of range";
48  
case error::leftover: return "leftover";
48  
case error::leftover: return "leftover";
49  
case error::out_of_range: return "out of range";
49  
case error::out_of_range: return "out of range";
50  
    }
50  
    }
51  
}
51  
}
52  

52  

53  
system::error_condition
53  
system::error_condition
54  
error_cat_type::
54  
error_cat_type::
55  
default_error_condition(
55  
default_error_condition(
56  
    int ev) const noexcept
56  
    int ev) const noexcept
57  
{
57  
{
58  
    switch(static_cast<error>(ev))
58  
    switch(static_cast<error>(ev))
59  
    {
59  
    {
60  
case error::invalid:
60  
case error::invalid:
61  
case error::out_of_range:
61  
case error::out_of_range:
62  
        return condition::fatal;
62  
        return condition::fatal;
63  
    default:
63  
    default:
64  
        return {ev, *this};
64  
        return {ev, *this};
65  
    }
65  
    }
66  
}
66  
}
67  

67  

68  
//------------------------------------------------
68  
//------------------------------------------------
69  

69  

70  
const char*
70  
const char*
71  
condition_cat_type::
71  
condition_cat_type::
72  
name() const noexcept
72  
name() const noexcept
73  
{
73  
{
74  
    return "boost.url.grammar";
74  
    return "boost.url.grammar";
75  
}
75  
}
76  

76  

77  
std::string
77  
std::string
78  
condition_cat_type::
78  
condition_cat_type::
79  
message(int code) const
79  
message(int code) const
80  
{
80  
{
81  
    return message(code, nullptr, 0);
81  
    return message(code, nullptr, 0);
82  
}
82  
}
83  

83  

84  
char const*
84  
char const*
85  
condition_cat_type::
85  
condition_cat_type::
86  
message(
86  
message(
87  
    int code, char*, std::size_t) const noexcept
87  
    int code, char*, std::size_t) const noexcept
88  
{
88  
{
89  
    switch(static_cast<condition>(code))
89  
    switch(static_cast<condition>(code))
90  
    {
90  
    {
91  
    default:
91  
    default:
92  
    case condition::fatal:
92  
    case condition::fatal:
93  
        return "fatal condition";
93  
        return "fatal condition";
94  
    }
94  
    }
95  
}
95  
}
96  

96  

97  
//-----------------------------------------------
97  
//-----------------------------------------------
98  

98  

99  
// msvc 14.0 has a bug that warns about inability
99  
// msvc 14.0 has a bug that warns about inability
100  
// to use constexpr construction here, even though
100  
// to use constexpr construction here, even though
101  
// there's no constexpr construction
101  
// there's no constexpr construction
102  
#if defined(_MSC_VER) && _MSC_VER <= 1900
102  
#if defined(_MSC_VER) && _MSC_VER <= 1900
103  
# pragma warning( push )
103  
# pragma warning( push )
104  
# pragma warning( disable : 4592 )
104  
# pragma warning( disable : 4592 )
105  
#endif
105  
#endif
106  

106  

107  
error_cat_type error_cat;
107  
error_cat_type error_cat;
108  
condition_cat_type condition_cat;
108  
condition_cat_type condition_cat;
109  

109  

110  
#if defined(_MSC_VER) && _MSC_VER <= 1900
110  
#if defined(_MSC_VER) && _MSC_VER <= 1900
111  
# pragma warning( pop )
111  
# pragma warning( pop )
112  
#endif
112  
#endif
113  

113  

114  
} // detail
114  
} // detail
115  

115  

116  
} // grammar
116  
} // grammar
117  
} // urls
117  
} // urls
118  
} // boost
118  
} // boost
119  

119