Split 'System/Utils' into header and source

This commit is contained in:
vittorioromeo 2023-04-26 15:24:43 +02:00 committed by Chris Thrasher
parent a143da5f52
commit 5f73a1514d
3 changed files with 59 additions and 18 deletions

View File

@ -22,6 +22,8 @@ set(SRC
${INCROOT}/Time.inl ${INCROOT}/Time.inl
${INCROOT}/Utf.hpp ${INCROOT}/Utf.hpp
${INCROOT}/Utf.inl ${INCROOT}/Utf.inl
${SRCROOT}/Utils.hpp
${SRCROOT}/Utils.cpp
${SRCROOT}/Vector2.cpp ${SRCROOT}/Vector2.cpp
${INCROOT}/Vector2.hpp ${INCROOT}/Vector2.hpp
${INCROOT}/Vector2.inl ${INCROOT}/Vector2.inl

52
src/SFML/System/Utils.cpp Normal file
View File

@ -0,0 +1,52 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 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.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Utils.hpp>
#include <sstream>
#include <cctype>
namespace sf
{
std::string toLower(std::string str)
{
for (char& c : str)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
return str;
}
std::string formatDebugPathInfo(const std::filesystem::path& path)
{
std::ostringstream oss;
oss << " Provided path: " << path << '\n' //
<< " Absolute path: " << std::filesystem::absolute(path);
return oss.str();
}
} // namespace sf

View File

@ -27,29 +27,16 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <filesystem> #include <SFML/System/Export.hpp>
#include <sstream>
#include <string>
#include <cctype> #include <filesystem>
#include <string>
namespace sf namespace sf
{ {
[[nodiscard]] inline std::string toLower(std::string str) [[nodiscard]] SFML_SYSTEM_API std::string toLower(std::string str);
{ [[nodiscard]] SFML_SYSTEM_API std::string formatDebugPathInfo(const std::filesystem::path& path);
for (char& c : str)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
return str;
}
[[nodiscard]] inline std::string formatDebugPathInfo(const std::filesystem::path& path)
{
std::ostringstream stream;
stream << " Provided path: " << path << '\n';
stream << " Absolute path: " << std::filesystem::absolute(path);
return stream.str();
}
// Convert byte sequence into integer // Convert byte sequence into integer
// toInteger<int>(0x12, 0x34, 0x56) == 0x563412 // toInteger<int>(0x12, 0x34, 0x56) == 0x563412