diff --git a/src/CSFML/Char32.hpp b/src/CSFML/Char32.hpp deleted file mode 100644 index 5bd2af8..0000000 --- a/src/CSFML/Char32.hpp +++ /dev/null @@ -1,57 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// 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. -// -//////////////////////////////////////////////////////////// - -#pragma once - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - -#include - -#include - - -//////////////////////////////////////////////////////////// -// Ensure char32_t has the same size as sfChar32 (uint32_t) -// Identical alignment and size is required because we're type punning -// when doing sfChar32* <-> char32_t* casts -//////////////////////////////////////////////////////////// -static_assert(sizeof(sfChar32) == sizeof(char32_t)); -static_assert(alignof(sfChar32) == alignof(char32_t)); - - -//////////////////////////////////////////////////////////// -// Define utils to copy from / to sfChar32 and sf::String -//////////////////////////////////////////////////////////// -[[nodiscard]] inline sfChar32* copyToChar32(const sf::String& str) -{ - std::size_t byteCount = sizeof(sfChar32) * str.getSize(); - auto* utf32 = static_cast(malloc(byteCount + sizeof(sfChar32))); - memcpy(utf32, str.getData(), byteCount); - utf32[str.getSize()] = 0; - - return utf32; -} diff --git a/src/CSFML/Network/Ftp.cpp b/src/CSFML/Network/Ftp.cpp index 13125f5..e81de49 100644 --- a/src/CSFML/Network/Ftp.cpp +++ b/src/CSFML/Network/Ftp.cpp @@ -25,7 +25,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include @@ -35,6 +34,31 @@ #include +namespace +{ +//////////////////////////////////////////////////////////// +// Ensure char32_t has the same size as sfChar32 (uint32_t) +// Identical alignment and size is required because we're type punning +// when doing sfChar32* <-> char32_t* casts +//////////////////////////////////////////////////////////// +static_assert(sizeof(sfChar32) == sizeof(char32_t)); +static_assert(alignof(sfChar32) == alignof(char32_t)); + +//////////////////////////////////////////////////////////// +// Define utils to copy to sfChar32 +//////////////////////////////////////////////////////////// +[[nodiscard]] sfChar32* copyToChar32(const sf::String& str) +{ + const std::size_t byteCount = sizeof(sfChar32) * str.getSize(); + auto* utf32 = static_cast(std::malloc(byteCount + sizeof(sfChar32))); + std::memcpy(utf32, str.getData(), byteCount); + utf32[str.getSize()] = 0; + + return utf32; +} +} // namespace + + //////////////////////////////////////////////////////////// void sfFtpListingResponse_destroy(sfFtpListingResponse* ftpListingResponse) { @@ -125,8 +149,7 @@ const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ft const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse) { assert(ftpDirectoryResponse); - sf::String str = sf::String(ftpDirectoryResponse->This.getDirectory().c_str()); - return copyToChar32(str); + return copyToChar32(sf::String(ftpDirectoryResponse->This.getDirectory().string())); }