Check for a minimum PipeWire version
[openal-soft.git] / al / eax_exception.cpp
blobfdeecaaa84e293d756fd73f829452d500280b2f5
1 #include "config.h"
3 #include "eax_exception.h"
5 #include <cassert>
7 #include <string>
10 EaxException::EaxException(
11 const char* context,
12 const char* message)
14 std::runtime_error{make_message(context, message)}
18 std::string EaxException::make_message(
19 const char* context,
20 const char* message)
22 const auto context_size = (context ? std::string::traits_type::length(context) : 0);
23 const auto has_contex = (context_size > 0);
25 const auto message_size = (message ? std::string::traits_type::length(message) : 0);
26 const auto has_message = (message_size > 0);
28 if (!has_contex && !has_message)
30 return std::string{};
33 static constexpr char left_prefix[] = "[";
34 const auto left_prefix_size = std::string::traits_type::length(left_prefix);
36 static constexpr char right_prefix[] = "] ";
37 const auto right_prefix_size = std::string::traits_type::length(right_prefix);
39 const auto what_size =
41 has_contex ?
42 left_prefix_size + context_size + right_prefix_size :
43 0) +
44 message_size +
47 auto what = std::string{};
48 what.reserve(what_size);
50 if (has_contex)
52 what.append(left_prefix, left_prefix_size);
53 what.append(context, context_size);
54 what.append(right_prefix, right_prefix_size);
57 if (has_message)
59 what.append(message, message_size);
62 return what;