diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index 405d91ff..0a69ce6f 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -27,19 +27,12 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include #include -namespace -{ - unsigned char toLower(unsigned char character) - { - return static_cast(std::tolower(character)); - } -} - namespace sf { namespace priv @@ -47,8 +40,7 @@ namespace priv //////////////////////////////////////////////////////////// bool SoundFileWriterFlac::check(const std::string& filename) { - std::string extension = filename.substr(filename.find_last_of('.') + 1); - std::transform(extension.begin(), extension.end(), extension.begin(), toLower); + const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); return extension == "flac"; } diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index 73e2ddc1..53b19ff4 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -27,20 +27,13 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include #include #include -namespace -{ - unsigned char toLower(unsigned char character) - { - return static_cast(std::tolower(character)); - } -} - namespace sf { namespace priv @@ -48,8 +41,7 @@ namespace priv //////////////////////////////////////////////////////////// bool SoundFileWriterOgg::check(const std::string& filename) { - std::string extension = filename.substr(filename.find_last_of('.') + 1); - std::transform(extension.begin(), extension.end(), extension.begin(), toLower); + const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); return extension == "ogg"; } diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index bbdd6369..5230ba9e 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -27,8 +27,7 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include +#include #include @@ -68,11 +67,6 @@ namespace }; stream.write(reinterpret_cast(bytes), sizeof(bytes)); } - - unsigned char toLower(unsigned char character) - { - return static_cast(std::tolower(character)); - } } namespace sf @@ -82,8 +76,7 @@ namespace priv //////////////////////////////////////////////////////////// bool SoundFileWriterWav::check(const std::string& filename) { - std::string extension = filename.substr(filename.find_last_of('.') + 1); - std::transform(extension.begin(), extension.end(), extension.begin(), toLower); + const std::string extension = toLower(filename.substr(filename.find_last_of('.') + 1)); return extension == "wav"; } diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index fb9d951d..4076671e 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -28,25 +28,16 @@ #include #include #include +#include #define STB_IMAGE_IMPLEMENTATION #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include -#include #include namespace { - // Convert a string to lower case - std::string toLower(std::string str) - { - for (char& c : str) - c = static_cast(std::tolower(c)); - - return str; - } - // stb_image callbacks that operate on a sf::InputStream int read(void* user, char* data, int size) { diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 739e51e0..418cf0cd 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -27,25 +27,12 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include #include #include #include -namespace -{ - // Convert a string to lower case - std::string toLower(std::string str) - { - for (char& c : str) - c = static_cast(std::tolower(c)); - - return str; - } -} - - namespace sf { //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/Utils.hpp b/src/SFML/System/Utils.hpp new file mode 100644 index 00000000..581f9e9b --- /dev/null +++ b/src/SFML/System/Utils.hpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_UTILS_HPP +#define SFML_UTILS_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ + [[nodiscard]] inline std::string toLower(std::string str) + { + for (char& c : str) + c = static_cast(std::tolower(static_cast(c))); + return str; + } +} // namespace sf + +#endif // SFML_UTILS_HPP