1
0
Fork 0

Codechange: use std::string_view for passing NetworkError strings

pull/14052/head
Rubidium 2025-04-20 12:07:19 +02:00 committed by rubidium42
parent 8aa2f6b8a6
commit 31433882a4
2 changed files with 4 additions and 4 deletions

View File

@ -29,7 +29,7 @@
* @param error The error code.
* @param message The error message. Leave empty to determine this automatically based on the error number.
*/
NetworkError::NetworkError(int error, const std::string &message) : error(error), message(message)
NetworkError::NetworkError(int error, std::string_view message) : error(error), message(message)
{
}
@ -78,7 +78,7 @@ bool NetworkError::IsConnectInProgress() const
* Get the string representation of the error message.
* @return The string representation that will get overwritten by next calls.
*/
const std::string &NetworkError::AsString() const
std::string_view NetworkError::AsString() const
{
if (this->message.empty()) {
#if defined(_WIN32)

View File

@ -23,13 +23,13 @@ private:
int error; ///< The underlying error number from errno or WSAGetLastError.
mutable std::string message; ///< The string representation of the error (set on first call to #AsString).
public:
NetworkError(int error, const std::string &message = {});
NetworkError(int error, std::string_view message = {});
bool HasError() const;
bool WouldBlock() const;
bool IsConnectionReset() const;
bool IsConnectInProgress() const;
const std::string &AsString() const;
std::string_view AsString() const;
static NetworkError GetLast();
};