From aead42865fe79736fceba51a02c08558de4d947a Mon Sep 17 00:00:00 2001 From: Death Killer <884052+deathkiller@users.noreply.github.com> Date: Thu, 15 Feb 2024 01:53:09 +0100 Subject: [PATCH] Fixed build --- Sources/Jazz2.vcxproj | 1 + Sources/Shared/Containers/StringStl.h | 70 +++++++++++++++++++++++++++ Sources/Shared/IO/FileSystem.cpp | 2 +- cmake/ncine_headers.cmake | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Sources/Shared/Containers/StringStl.h diff --git a/Sources/Jazz2.vcxproj b/Sources/Jazz2.vcxproj index 56ae005b..327db4f6 100644 --- a/Sources/Jazz2.vcxproj +++ b/Sources/Jazz2.vcxproj @@ -616,6 +616,7 @@ + diff --git a/Sources/Shared/Containers/StringStl.h b/Sources/Shared/Containers/StringStl.h new file mode 100644 index 00000000..79fae304 --- /dev/null +++ b/Sources/Shared/Containers/StringStl.h @@ -0,0 +1,70 @@ +// Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, +// 2017, 2018, 2019, 2020, 2021, 2022, 2023 +// Vladimír Vondruš and contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#pragma once + +/** @file + @brief STL @ref std::string compatibility for @ref Death::Containers::String and @ref Death::Containers::StringView + + Including this header allows you to convert a + @ref Death::Containers::String / @ref Death::Containers::StringView from + and to a @ref std::string. +*/ + +#include + +#include "String.h" +#include "StringView.h" + +namespace Death { namespace Containers { namespace Implementation { +//###==##====#=====--==~--~=~- --- -- - - - - + + template<> struct StringConverter { + static String from(const std::string& other) { + return String{other.data(), other.size()}; + } + static std::string to(const String& other) { + return std::string{other.data(), other.size()}; + } + }; + + template<> struct StringViewConverter { + static StringView from(const std::string& other) { + return StringView{other.data(), other.size(), StringViewFlags::NullTerminated}; + } + static std::string to(StringView other) { + return std::string{other.data(), other.size()}; + } + }; + + template<> struct StringViewConverter { + static MutableStringView from(std::string& other) { + // .data() returns a const pointer until C++17, so have to use &other[0]. It's guaranteed + // to return a pointer to a single null character if the string is empty. + return MutableStringView{&other[0], other.size(), StringViewFlags::NullTerminated}; + } + static std::string to(MutableStringView other) { + return std::string{other.data(), other.size()}; + } + }; + +}}} \ No newline at end of file diff --git a/Sources/Shared/IO/FileSystem.cpp b/Sources/Shared/IO/FileSystem.cpp index f012c566..ea3917c4 100644 --- a/Sources/Shared/IO/FileSystem.cpp +++ b/Sources/Shared/IO/FileSystem.cpp @@ -1447,7 +1447,7 @@ namespace Death { namespace IO { buffer[pathLength] = '\0'; const char* baseName = ::basename(buffer); if (hidden && baseName != nullptr && baseName[0] != '.') { - String newPath = CombinePath(GetDirectoryName(nullTerminatedPath), "."_s + baseName); + String newPath = CombinePath(GetDirectoryName(nullTerminatedPath), String("."_s + baseName)); return (::rename(nullTerminatedPath.data(), newPath.data()) == 0); } else if (!hidden && baseName != nullptr && baseName[0] == '.') { std::int32_t numDots = 0; diff --git a/cmake/ncine_headers.cmake b/cmake/ncine_headers.cmake index 8d3f248b..d1c3d4c4 100644 --- a/cmake/ncine_headers.cmake +++ b/cmake/ncine_headers.cmake @@ -24,6 +24,7 @@ set(HEADERS ${NCINE_SOURCE_DIR}/Shared/Containers/StaticArray.h ${NCINE_SOURCE_DIR}/Shared/Containers/String.h ${NCINE_SOURCE_DIR}/Shared/Containers/StringConcatenable.h + ${NCINE_SOURCE_DIR}/Shared/Containers/StringStl.h ${NCINE_SOURCE_DIR}/Shared/Containers/StringStlView.h ${NCINE_SOURCE_DIR}/Shared/Containers/StringUtils.h ${NCINE_SOURCE_DIR}/Shared/Containers/StringView.h