Use cstring_view in all functions in Checks::

This commit is contained in:
Alexander Karatarakis 2017-03-28 12:52:04 -07:00
parent ddf40ccdd3
commit 780ef97d1b
2 changed files with 20 additions and 20 deletions

View File

@ -20,45 +20,45 @@ namespace vcpkg::Checks
}
// Part of the reason these exist is to not include extra headers in this one to avoid circular #includes.
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage);
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage);
template <class...Args>
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs)
template <class Arg1, class...Args>
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
{
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArg1, errorMessageArgs...).c_str());
}
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage);
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const cstring_view errorMessage);
template <class...Args>
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Args&... errorMessageArgs)
template <class Arg1, class...Args>
_declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
{
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArg1, errorMessageArgs...).c_str());
}
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage);
void check_throw(const LineInfo& line_info, bool expression, const cstring_view errorMessage);
template <class...Args>
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs)
template <class Arg1, class...Args>
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
{
if (!expression)
{
// Only create the string if the expression is false
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
throw_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArg1, errorMessageArgs...).c_str());
}
}
void check_exit(const LineInfo& line_info, bool expression);
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage);
void check_exit(const LineInfo& line_info, bool expression, const cstring_view errorMessage);
template <class...Args>
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Args&... errorMessageArgs)
template <class Arg1, class...Args>
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
{
if (!expression)
{
// Only create the string if the expression is false
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArg1, errorMessageArgs...).c_str());
}
}
}

View File

@ -30,19 +30,19 @@ namespace vcpkg::Checks
::exit(exit_code);
}
__declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage)
__declspec(noreturn) void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage)
{
System::println(System::color::error, errorMessage);
exit_fail(line_info);
}
__declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage)
__declspec(noreturn) void throw_with_message(const LineInfo& line_info, const cstring_view errorMessage)
{
print_line_info_if_debug(line_info);
throw std::runtime_error(errorMessage);
}
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage)
void check_throw(const LineInfo& line_info, bool expression, const cstring_view errorMessage)
{
if (!expression)
{
@ -58,7 +58,7 @@ namespace vcpkg::Checks
}
}
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage)
void check_exit(const LineInfo& line_info, bool expression, const cstring_view errorMessage)
{
if (!expression)
{