Move EAX files to their own sub-directory
[openal-soft.git] / al / eax / exception.cpp
blob3b3196481c5cf44ba615c3832063d8376986e67d
1 #include "config.h"
3 #include "exception.h"
5 #include <cassert>
6 #include <string>
9 EaxException::EaxException(
10 const char* context,
11 const char* message)
13 std::runtime_error{make_message(context, message)}
17 std::string EaxException::make_message(
18 const char* context,
19 const char* message)
21 const auto context_size = (context ? std::string::traits_type::length(context) : 0);
22 const auto has_contex = (context_size > 0);
24 const auto message_size = (message ? std::string::traits_type::length(message) : 0);
25 const auto has_message = (message_size > 0);
27 if (!has_contex && !has_message)
29 return std::string{};
32 static constexpr char left_prefix[] = "[";
33 const auto left_prefix_size = std::string::traits_type::length(left_prefix);
35 static constexpr char right_prefix[] = "] ";
36 const auto right_prefix_size = std::string::traits_type::length(right_prefix);
38 const auto what_size =
40 has_contex ?
41 left_prefix_size + context_size + right_prefix_size :
42 0) +
43 message_size +
46 auto what = std::string{};
47 what.reserve(what_size);
49 if (has_contex)
51 what.append(left_prefix, left_prefix_size);
52 what.append(context, context_size);
53 what.append(right_prefix, right_prefix_size);
56 if (has_message)
58 what.append(message, message_size);
61 return what;