Use std::quoted

This commit is contained in:
Chris Thrasher 2022-03-14 21:00:20 -06:00 committed by Lukas Dürrenberger
parent f3d98a9ebf
commit c5f3aeca72
6 changed files with 24 additions and 18 deletions

View File

@ -3,6 +3,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network.hpp>
#include <iomanip>
#include <iostream>
@ -31,14 +32,14 @@ void runTcpServer(unsigned short port)
const char out[] = "Hi, I'm the server";
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
return;
std::cout << "Message sent to the client: \"" << out << '"' << std::endl;
std::cout << "Message sent to the client: " << std::quoted(out) << std::endl;
// Receive a message back from the client
char in[128];
std::size_t received;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return;
std::cout << "Answer received from the client: \"" << in << '"' << std::endl;
std::cout << "Answer received from the client: " << std::quoted(in) << std::endl;
}
@ -71,11 +72,11 @@ void runTcpClient(unsigned short port)
std::size_t received;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Done)
return;
std::cout << "Message received from the server: \"" << in << '"' << std::endl;
std::cout << "Message received from the server: " << std::quoted(in) << std::endl;
// Send an answer to the server
const char out[] = "Hi, I'm a client";
if (socket.send(out, sizeof(out)) != sf::Socket::Done)
return;
std::cout << "Message sent to the server: \"" << out << '"' << std::endl;
std::cout << "Message sent to the server: " << std::quoted(out) << std::endl;
}

View File

@ -3,6 +3,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network.hpp>
#include <iomanip>
#include <iostream>
@ -27,13 +28,13 @@ void runUdpServer(unsigned short port)
unsigned short senderPort;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message received from client " << sender << ": \"" << in << '"' << std::endl;
std::cout << "Message received from client " << sender << ": " << std::quoted(in) << std::endl;
// Send an answer to the client
const char out[] = "Hi, I'm the server";
if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message sent to the client: \"" << out << '"' << std::endl;
std::cout << "Message sent to the client: " << std::quoted(out) << std::endl;
}
@ -59,7 +60,7 @@ void runUdpClient(unsigned short port)
const char out[] = "Hi, I'm a client";
if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done)
return;
std::cout << "Message sent to the server: \"" << out << '"' << std::endl;
std::cout << "Message sent to the server: " << std::quoted(out) << std::endl;
// Receive an answer from anyone (but most likely from the server)
char in[128];
@ -68,5 +69,5 @@ void runUdpClient(unsigned short port)
unsigned short senderPort;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
return;
std::cout << "Message received from " << sender << ": \"" << in << '"' << std::endl;
std::cout << "Message received from " << sender << ": " << std::quoted(in) << std::endl;
}

View File

@ -34,6 +34,7 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
#include <filesystem>
#include <iomanip>
#include <iterator>
#include <ostream>
@ -318,7 +319,7 @@ bool ImageLoader::saveImageToMemory(const std::string& format, std::vector<sf::U
}
}
err() << "Failed to save image with format \"" << format << '"' << std::endl;
err() << "Failed to save image with format " << std::quoted(format) << std::endl;
return false;
}

View File

@ -35,6 +35,7 @@
#include <SFML/System/InputStream.hpp>
#include <SFML/System/Err.hpp>
#include <fstream>
#include <iomanip>
#include <vector>
#include <mutex>
#include <ostream>
@ -571,7 +572,7 @@ void Shader::setUniform(const std::string& name, const Texture& texture)
// New entry, make sure there are enough texture units
if (m_textures.size() + 1 >= getMaxTextureUnits())
{
err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl;
err() << "Impossible to use texture " << std::quoted(name) << " for shader: all available texture units are used" << std::endl;
return;
}
@ -944,7 +945,7 @@ int Shader::getUniformLocation(const std::string& name)
m_uniforms.emplace(name, location);
if (location == -1)
err() << "Uniform \"" << name << "\" not found in shader" << std::endl;
err() << "Uniform " << std::quoted(name) << " not found in shader" << std::endl;
return location;
}

View File

@ -31,6 +31,7 @@
#include <SFML/System/Err.hpp>
#include <glad/gl.h>
#include <algorithm>
#include <iomanip>
#include <memory>
#include <mutex>
#include <optional>
@ -805,7 +806,7 @@ void GlContext::initialize(const ContextSettings& requestedSettings)
!parseVersionString(version, "OpenGL ES ", m_settings.majorVersion, m_settings.minorVersion) &&
!parseVersionString(version, "", m_settings.majorVersion, m_settings.minorVersion))
{
err() << "Unable to parse OpenGL version string: \"" << version << "\", defaulting to 1.1" << std::endl;
err() << "Unable to parse OpenGL version string: " << std::quoted(version) << ", defaulting to 1.1" << std::endl;
}
}
else

View File

@ -32,6 +32,7 @@
#include <SFML/System/Time.hpp>
#include <tchar.h>
#include <regstr.h>
#include <iomanip>
#include <ostream>
#include <sstream>
#include <string>
@ -721,8 +722,8 @@ bool JoystickImpl::openDInput(unsigned int index)
if (FAILED(result))
{
err() << "Failed to get DirectInput device axis mode for device \""
<< m_identification.name.toAnsiString() << "\": " << result << std::endl;
err() << "Failed to get DirectInput device axis mode for device "
<< std::quoted(m_identification.name.toAnsiString()) << ": " << result << std::endl;
m_device->Release();
m_device = nullptr;
@ -753,8 +754,8 @@ bool JoystickImpl::openDInput(unsigned int index)
if (FAILED(result))
{
err() << "Failed to verify DirectInput device axis mode for device \""
<< m_identification.name.toAnsiString() << "\": " << result << std::endl;
err() << "Failed to verify DirectInput device axis mode for device "
<< std::quoted(m_identification.name.toAnsiString()) << ": " << result << std::endl;
m_device->Release();
m_device = nullptr;
@ -807,8 +808,8 @@ bool JoystickImpl::openDInput(unsigned int index)
}
else
{
err() << "Failed to set DirectInput device buffer size for device \""
<< m_identification.name.toAnsiString() << "\": " << result << std::endl;
err() << "Failed to set DirectInput device buffer size for device "
<< std::quoted(m_identification.name.toAnsiString()) << ": " << result << std::endl;
m_device->Release();
m_device = nullptr;