diff --git a/examples/HardwareInfo/main.cpp b/examples/HardwareInfo/main.cpp index ffeb4bb86..0a328cfda 100644 --- a/examples/HardwareInfo/main.cpp +++ b/examples/HardwareInfo/main.cpp @@ -14,7 +14,7 @@ #include #include -void printCap(std::ostream& o, const Nz::String& cap, bool b); +void printCap(std::ostream& o, const std::string& cap, bool b); int main() { @@ -65,7 +65,7 @@ int main() Nz::File reportFile("HardwareInfo.txt"); if (reportFile.Open(Nz::OpenMode_Text | Nz::OpenMode_Truncate | Nz::OpenMode_WriteOnly)) { - reportFile.Write(oss.str()); // Conversion implicite en Nz::String + reportFile.Write(oss.str()); // Conversion implicite en std::string reportFile.Close(); char accentAigu = static_cast(130); // C'est crade, mais ça marche chez 95% des Windowsiens @@ -79,7 +79,7 @@ int main() return 0; } -void printCap(std::ostream& o, const Nz::String& cap, bool b) +void printCap(std::ostream& o, const std::string& cap, bool b) { if (b) o << cap << ": Oui" << std::endl; diff --git a/examples/MeshInfos/main.cpp b/examples/MeshInfos/main.cpp index 86723b77c..782747e0d 100644 --- a/examples/MeshInfos/main.cpp +++ b/examples/MeshInfos/main.cpp @@ -166,7 +166,7 @@ int main() { const Nz::ParameterList& matData = mesh->GetMaterialData(i); - Nz::String data; + std::string data; if (!matData.GetStringParameter(Nz::MaterialData::FilePath, &data)) data = ""; diff --git a/examples/RenderTest/main.cpp b/examples/RenderTest/main.cpp index 0b6004ed1..129a95031 100644 --- a/examples/RenderTest/main.cpp +++ b/examples/RenderTest/main.cpp @@ -25,7 +25,7 @@ int main() meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f)); meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV); - Nz::String windowTitle = "Render Test"; + std::string windowTitle = "Render Test"; if (!window.Create(Nz::VideoMode(800, 600, 32), windowTitle)) { std::cout << "Failed to create Window" << std::endl; @@ -341,7 +341,7 @@ int main() if (secondClock.GetMilliseconds() >= 1000) // Toutes les secondes { // Et on insère ces données dans le titre de la fenêtre - window.SetTitle(windowTitle + " - " + Nz::String::Number(fps) + " FPS"); + window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS"); /* Note: En C++11 il est possible d'insérer de l'Unicode de façon standard, quel que soit l'encodage du fichier, diff --git a/include/Nazara/Audio/OpenAL.hpp b/include/Nazara/Audio/OpenAL.hpp index 214f7a4bf..d3a88974a 100644 --- a/include/Nazara/Audio/OpenAL.hpp +++ b/include/Nazara/Audio/OpenAL.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include // Inclusion of OpenAL headers @@ -64,19 +64,19 @@ namespace Nz class NAZARA_AUDIO_API OpenAL { public: - static OpenALFunc GetEntry(const String& entryPoint); - static String GetRendererName(); - static String GetVendorName(); + static OpenALFunc GetEntry(const std::string& entryPoint); + static std::string GetRendererName(); + static std::string GetVendorName(); static unsigned int GetVersion(); static bool Initialize(bool openDevice = true); static bool IsInitialized(); - static std::size_t QueryInputDevices(std::vector& devices); - static std::size_t QueryOutputDevices(std::vector& devices); + static std::size_t QueryInputDevices(std::vector& devices); + static std::size_t QueryOutputDevices(std::vector& devices); - static bool SetDevice(const String& deviceName); + static bool SetDevice(const std::string& deviceName); static void Uninitialize(); diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index 24725ceb6..4862726d9 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -87,9 +87,7 @@ #include #include #include -#include #include -#include #include #include #include diff --git a/include/Nazara/Core/AbstractLogger.hpp b/include/Nazara/Core/AbstractLogger.hpp index 34a83f6ce..59b2ef39a 100644 --- a/include/Nazara/Core/AbstractLogger.hpp +++ b/include/Nazara/Core/AbstractLogger.hpp @@ -8,7 +8,8 @@ #define NAZARA_ABSTRACTLOGGER_HPP #include -#include +#include +#include namespace Nz { @@ -22,8 +23,8 @@ namespace Nz virtual bool IsStdReplicationEnabled() const = 0; - virtual void Write(const String& string) = 0; - virtual void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr); + virtual void Write(const std::string_view& string) = 0; + virtual void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr); }; } diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index af602556a..dec6312a4 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -8,6 +8,7 @@ #define NAZARA_ALGORITHM_CORE_HPP #include +#include #include #include #include @@ -18,7 +19,6 @@ namespace Nz { - class AbstractHash; class ByteArray; template constexpr T Align(T offset, T alignment); @@ -30,6 +30,7 @@ namespace Nz template ByteArray ComputeHash(AbstractHash* hash, const T& v); template constexpr std::size_t CountOf(T(&name)[N]) noexcept; template std::size_t CountOf(const T& c); + inline bool HashAppend(AbstractHash* hash, const std::string_view& v); template void HashCombine(std::size_t& seed, const T& v); template bool IsPowerOfTwo(T value); template T ReverseBits(T integer); diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index 7cacf36e5..3560f775c 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -192,6 +192,12 @@ namespace Nz return c.size(); } + inline bool HashAppend(AbstractHash* hash, const std::string_view& v) + { + hash->Append(reinterpret_cast(v.data()), v.size()); + return true; + } + /*! * \ingroup core * \brief Combines two hash in one diff --git a/include/Nazara/Core/Bitset.hpp b/include/Nazara/Core/Bitset.hpp index 08c8017a4..6f39486ff 100644 --- a/include/Nazara/Core/Bitset.hpp +++ b/include/Nazara/Core/Bitset.hpp @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include #include namespace Nz @@ -32,7 +32,8 @@ namespace Nz explicit Bitset(const char* bits); Bitset(const char* bits, std::size_t bitCount); Bitset(const Bitset& bitset) = default; - explicit Bitset(const String& bits); + explicit Bitset(const std::string_view& bits); + explicit Bitset(const std::string& bits); template Bitset(T value); Bitset(Bitset&& bitset) noexcept = default; ~Bitset() noexcept = default; @@ -81,7 +82,7 @@ namespace Nz bool TestNone() const; template T To() const; - String ToString() const; + std::string ToString() const; void UnboundedReset(std::size_t bit); void UnboundedSet(std::size_t bit, bool val = true); @@ -96,7 +97,7 @@ namespace Nz Bitset operator~() const; Bitset& operator=(const Bitset& bitset) = default; - Bitset& operator=(const String& bits); + Bitset& operator=(const std::string_view& bits); template Bitset& operator=(T value); Bitset& operator=(Bitset&& bitset) noexcept = default; diff --git a/include/Nazara/Core/Bitset.inl b/include/Nazara/Core/Bitset.inl index 97e51f912..be8563b95 100644 --- a/include/Nazara/Core/Bitset.inl +++ b/include/Nazara/Core/Bitset.inl @@ -98,14 +98,24 @@ namespace Nz } /*! - * \brief Constructs a Bitset object from a Nz::String + * \brief Constructs a Bitset object from a std::string_view * * \param bits String containing only '0' and '1' */ - template - Bitset::Bitset(const String& bits) : - Bitset(bits.GetConstBuffer(), bits.GetSize()) + Bitset::Bitset(const std::string_view& bits) : + Bitset(bits.data(), bits.size()) + { + } + + /*! + * \brief Constructs a Bitset object from a std::string + * + * \param bits String containing only '0' and '1' + */ + template + Bitset::Bitset(const std::string& bits) : + Bitset(bits.data(), bits.size()) { } @@ -883,9 +893,9 @@ namespace Nz */ template - String Bitset::ToString() const + std::string Bitset::ToString() const { - String str(m_bitCount, '0'); + std::string str(m_bitCount, '0'); for (std::size_t i = 0; i < m_bitCount; ++i) { @@ -991,14 +1001,14 @@ namespace Nz } /*! - * \brief Sets this bitset from a Nz::String + * \brief Sets this bitset from a std::string * \return A reference to this * * \param bits String containing only '0' and '1' */ template - Bitset& Bitset::operator=(const String& bits) + Bitset& Bitset::operator=(const std::string_view& bits) { Bitset bitset(bits); std::swap(*this, bitset); diff --git a/include/Nazara/Core/ByteArray.hpp b/include/Nazara/Core/ByteArray.hpp index 93acf5daa..9e58f7710 100644 --- a/include/Nazara/Core/ByteArray.hpp +++ b/include/Nazara/Core/ByteArray.hpp @@ -8,7 +8,8 @@ #define NAZARA_BYTEARRAY_HPP #include -#include +#include +#include #include namespace Nz @@ -88,8 +89,8 @@ namespace Nz inline void ShrinkToFit(); inline void Swap(ByteArray& other); - String ToHex() const; - inline String ToString() const; + std::string ToHex() const; + inline std::string ToString() const; // STL interface inline iterator begin() noexcept; diff --git a/include/Nazara/Core/ByteArray.inl b/include/Nazara/Core/ByteArray.inl index 738b5d924..850ff34d0 100644 --- a/include/Nazara/Core/ByteArray.inl +++ b/include/Nazara/Core/ByteArray.inl @@ -464,12 +464,12 @@ namespace Nz /*! * \brief Gives a string representation - * \return String where each byte is converted to char + * \return std::string where each byte is converted to char */ - inline String ByteArray::ToString() const + inline std::string ByteArray::ToString() const { - return String(reinterpret_cast(GetConstBuffer()), GetSize()); + return std::string(reinterpret_cast(GetConstBuffer()), GetSize()); } /*! diff --git a/include/Nazara/Core/ByteArrayPool.hpp b/include/Nazara/Core/ByteArrayPool.hpp index cb2f2ab9c..58ffb8b51 100644 --- a/include/Nazara/Core/ByteArrayPool.hpp +++ b/include/Nazara/Core/ByteArrayPool.hpp @@ -9,7 +9,6 @@ #include #include -#include #include namespace Nz diff --git a/include/Nazara/Core/Color.hpp b/include/Nazara/Core/Color.hpp index 13efb3fa3..55cd6b42f 100644 --- a/include/Nazara/Core/Color.hpp +++ b/include/Nazara/Core/Color.hpp @@ -8,8 +8,8 @@ #define NAZARA_COLOR_HPP #include -#include #include +#include namespace Nz { @@ -28,7 +28,7 @@ namespace Nz inline bool IsOpaque() const; - inline String ToString() const; + inline std::string ToString() const; inline Color operator+(const Color& angles) const; inline Color operator*(const Color& angles) const; diff --git a/include/Nazara/Core/Color.inl b/include/Nazara/Core/Color.inl index bfcd3ab1a..75a82b80e 100644 --- a/include/Nazara/Core/Color.inl +++ b/include/Nazara/Core/Color.inl @@ -2,9 +2,10 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include #include +#include #include namespace Nz @@ -83,9 +84,9 @@ namespace Nz * \return String representation of the object "Color(r, g, b[, a])" */ - inline String Color::ToString() const + inline std::string Color::ToString() const { - StringStream ss; + std::ostringstream ss; ss << "Color(" << static_cast(r) << ", " << static_cast(g) << ", " << static_cast(b); if (a != 255) @@ -93,7 +94,7 @@ namespace Nz ss << ')'; - return ss; + return ss.str(); } /*! diff --git a/include/Nazara/Core/Error.hpp b/include/Nazara/Core/Error.hpp index c2562af9a..4ff2e229f 100644 --- a/include/Nazara/Core/Error.hpp +++ b/include/Nazara/Core/Error.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG) #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION) @@ -31,20 +31,20 @@ namespace Nz ~Error() = delete; static UInt32 GetFlags(); - static String GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr); + static std::string GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr); static unsigned int GetLastSystemErrorCode(); static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode()); static void SetFlags(UInt32 flags); - static void Trigger(ErrorType type, const String& error); - static void Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function); + static void Trigger(ErrorType type, std::string error); + static void Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function); private: static const char* GetCurrentFileRelativeToEngine(const char* file); static UInt32 s_flags; - static String s_lastError; + static std::string s_lastError; static const char* s_lastErrorFunction; static const char* s_lastErrorFile; static unsigned int s_lastErrorLine; diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 2432359b7..f41c4e773 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/Core/FileLogger.hpp b/include/Nazara/Core/FileLogger.hpp index 36a1ff9ce..e92d56571 100644 --- a/include/Nazara/Core/FileLogger.hpp +++ b/include/Nazara/Core/FileLogger.hpp @@ -18,7 +18,7 @@ namespace Nz class NAZARA_CORE_API FileLogger : public AbstractLogger { public: - FileLogger(const String& logPath = "NazaraLog.log"); + FileLogger(std::filesystem::path logPath = "NazaraLog.log"); FileLogger(const FileLogger&) = default; FileLogger(FileLogger&&) = default; ~FileLogger(); @@ -29,8 +29,8 @@ namespace Nz bool IsStdReplicationEnabled() const override; bool IsTimeLoggingEnabled() const; - void Write(const String& string) override; - void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override; + void Write(const std::string_view& string) override; + void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override; FileLogger& operator=(const FileLogger&) = default; FileLogger& operator=(FileLogger&&) = default; diff --git a/include/Nazara/Core/HardwareInfo.hpp b/include/Nazara/Core/HardwareInfo.hpp index 5b3187038..aaf5ff98b 100644 --- a/include/Nazara/Core/HardwareInfo.hpp +++ b/include/Nazara/Core/HardwareInfo.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include namespace Nz { @@ -21,10 +21,10 @@ namespace Nz static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]); - static String GetProcessorBrandString(); + static std::string_view GetProcessorBrandString(); static unsigned int GetProcessorCount(); static ProcessorVendor GetProcessorVendor(); - static String GetProcessorVendorName(); + static std::string_view GetProcessorVendorName(); static UInt64 GetTotalMemory(); static bool HasCapability(ProcessorCap capability); diff --git a/include/Nazara/Core/Log.hpp b/include/Nazara/Core/Log.hpp index 8c3799756..b800b86b9 100644 --- a/include/Nazara/Core/Log.hpp +++ b/include/Nazara/Core/Log.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #ifdef NAZARA_DEBUG #define NazaraDebug(txt) NazaraNotice(txt) @@ -36,11 +36,11 @@ namespace Nz static void SetLogger(AbstractLogger* logger); - static void Write(const String& string); - static void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr); + static void Write(const std::string_view& string); + static void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr); - NazaraStaticSignal(OnLogWrite, const String& /*string*/); - NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const String& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/); + NazaraStaticSignal(OnLogWrite, const std::string_view& /*string*/); + NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const std::string_view& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/); private: static bool Initialize(); diff --git a/include/Nazara/Core/ObjectHandle.hpp b/include/Nazara/Core/ObjectHandle.hpp index 8c61ac660..5173838ad 100644 --- a/include/Nazara/Core/ObjectHandle.hpp +++ b/include/Nazara/Core/ObjectHandle.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Nz { @@ -36,7 +37,7 @@ namespace Nz ObjectHandle& Swap(ObjectHandle& handle); - Nz::String ToString() const; + std::string ToString() const; explicit operator bool() const; operator T*() const; diff --git a/include/Nazara/Core/ObjectHandle.inl b/include/Nazara/Core/ObjectHandle.inl index 32b59d81b..e94624780 100644 --- a/include/Nazara/Core/ObjectHandle.inl +++ b/include/Nazara/Core/ObjectHandle.inl @@ -3,9 +3,9 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include +#include namespace Nz { @@ -135,18 +135,12 @@ namespace Nz * \return A string representation of the object "ObjectHandle(object representation) or Null" */ template - Nz::String ObjectHandle::ToString() const + std::string ObjectHandle::ToString() const { - Nz::StringStream ss; - ss << "ObjectHandle("; - if (IsValid()) - ss << GetObject()->ToString(); - else - ss << "Null"; + std::ostringstream ss; + ss << *this; - ss << ')'; - - return ss; + return ss.str(); } /*! @@ -219,7 +213,14 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const ObjectHandle& handle) { - out << handle.ToString(); + out << "ObjectHandle("; + if (handle.IsValid()) + out << handle->ToString(); + else + out << "Null"; + + out << ')'; + return out; } diff --git a/include/Nazara/Core/ObjectLibrary.hpp b/include/Nazara/Core/ObjectLibrary.hpp index dedb4efe6..859dc82bb 100644 --- a/include/Nazara/Core/ObjectLibrary.hpp +++ b/include/Nazara/Core/ObjectLibrary.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include namespace Nz @@ -25,18 +25,18 @@ namespace Nz static void Clear(); - static ObjectRef Get(const String& name); - static bool Has(const String& name); + static ObjectRef Get(const std::string& name); + static bool Has(const std::string& name); - static void Register(const String& name, ObjectRef object); - static ObjectRef Query(const String& name); - static void Unregister(const String& name); + static void Register(const std::string& name, ObjectRef object); + static ObjectRef Query(const std::string& name); + static void Unregister(const std::string& name); private: static bool Initialize(); static void Uninitialize(); - using LibraryMap = std::unordered_map>; + using LibraryMap = std::unordered_map>; }; } diff --git a/include/Nazara/Core/ObjectLibrary.inl b/include/Nazara/Core/ObjectLibrary.inl index 767f05f5c..a39b0b7a8 100644 --- a/include/Nazara/Core/ObjectLibrary.inl +++ b/include/Nazara/Core/ObjectLibrary.inl @@ -32,7 +32,7 @@ namespace Nz * \remark Produces a NazaraError if object not found */ template - ObjectRef ObjectLibrary::Get(const String& name) + ObjectRef ObjectLibrary::Get(const std::string& name) { ObjectRef ref = Query(name); if (!ref) @@ -46,7 +46,7 @@ namespace Nz * \return true if it the case */ template - bool ObjectLibrary::Has(const String& name) + bool ObjectLibrary::Has(const std::string& name) { return Type::s_library.find(name) != Type::s_library.end(); } @@ -58,7 +58,7 @@ namespace Nz * \param object Object to stock */ template - void ObjectLibrary::Register(const String& name, ObjectRef object) + void ObjectLibrary::Register(const std::string& name, ObjectRef object) { Type::s_library.emplace(name, object); } @@ -70,7 +70,7 @@ namespace Nz * \param name Name of the object */ template - ObjectRef ObjectLibrary::Query(const String& name) + ObjectRef ObjectLibrary::Query(const std::string& name) { auto it = Type::s_library.find(name); if (it != Type::s_library.end()) @@ -85,7 +85,7 @@ namespace Nz * \param name Name of the object */ template - void ObjectLibrary::Unregister(const String& name) + void ObjectLibrary::Unregister(const std::string& name) { Type::s_library.erase(name); } diff --git a/include/Nazara/Core/ParameterList.hpp b/include/Nazara/Core/ParameterList.hpp index 0afe0f7dd..48f740944 100644 --- a/include/Nazara/Core/ParameterList.hpp +++ b/include/Nazara/Core/ParameterList.hpp @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include namespace Nz @@ -28,33 +28,33 @@ namespace Nz void Clear(); - inline void ForEach(const std::function& callback); - inline void ForEach(const std::function& callback) const; + inline void ForEach(const std::function& callback); + inline void ForEach(const std::function& callback) const; - bool GetBooleanParameter(const String& name, bool* value) const; - bool GetColorParameter(const String& name, Color* value) const; - bool GetDoubleParameter(const String& name, double* value) const; - bool GetIntegerParameter(const String& name, long long* value) const; - bool GetParameterType(const String& name, ParameterType* type) const; - bool GetPointerParameter(const String& name, void** value) const; - bool GetStringParameter(const String& name, String* value) const; - bool GetUserdataParameter(const String& name, void** value) const; + bool GetBooleanParameter(const std::string& name, bool* value) const; + bool GetColorParameter(const std::string& name, Color* value) const; + bool GetDoubleParameter(const std::string& name, double* value) const; + bool GetIntegerParameter(const std::string& name, long long* value) const; + bool GetParameterType(const std::string& name, ParameterType* type) const; + bool GetPointerParameter(const std::string& name, void** value) const; + bool GetStringParameter(const std::string& name, std::string* value) const; + bool GetUserdataParameter(const std::string& name, void** value) const; - bool HasParameter(const String& name) const; + bool HasParameter(const std::string& name) const; - void RemoveParameter(const String& name); + void RemoveParameter(const std::string& name); - void SetParameter(const String& name); - void SetParameter(const String& name, const Color& value); - void SetParameter(const String& name, const String& value); - void SetParameter(const String& name, const char* value); - void SetParameter(const String& name, bool value); - void SetParameter(const String& name, double value); - void SetParameter(const String& name, long long value); - void SetParameter(const String& name, void* value); - void SetParameter(const String& name, void* value, Destructor destructor); + void SetParameter(const std::string& name); + void SetParameter(const std::string& name, const Color& value); + void SetParameter(const std::string& name, const std::string& value); + void SetParameter(const std::string& name, const char* value); + void SetParameter(const std::string& name, bool value); + void SetParameter(const std::string& name, double value); + void SetParameter(const std::string& name, long long value); + void SetParameter(const std::string& name, void* value); + void SetParameter(const std::string& name, void* value, Destructor destructor); - String ToString() const; + std::string ToString() const; ParameterList& operator=(const ParameterList& list); ParameterList& operator=(ParameterList&&) = default; @@ -90,17 +90,17 @@ namespace Nz long long intVal; void* ptrVal; Color colorVal; - String stringVal; + std::string stringVal; UserdataValue* userdataVal; }; Value value; }; - Parameter& CreateValue(const String& name); + Parameter& CreateValue(const std::string& name); void DestroyValue(Parameter& parameter); - using ParameterMap = std::unordered_map; + using ParameterMap = std::unordered_map; ParameterMap m_parameters; }; } diff --git a/include/Nazara/Core/ParameterList.inl b/include/Nazara/Core/ParameterList.inl index 557951a46..8fcf7cb76 100644 --- a/include/Nazara/Core/ParameterList.inl +++ b/include/Nazara/Core/ParameterList.inl @@ -13,7 +13,7 @@ namespace Nz * * \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe. */ - inline void ParameterList::ForEach(const std::function& callback) + inline void ParameterList::ForEach(const std::function& callback) { for (auto it = m_parameters.begin(); it != m_parameters.end();) { @@ -31,7 +31,7 @@ namespace Nz * * \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe. */ - inline void ParameterList::ForEach(const std::function& callback) const + inline void ParameterList::ForEach(const std::function& callback) const { for (auto& pair : m_parameters) callback(*this, pair.first); diff --git a/include/Nazara/Core/ResourceManager.hpp b/include/Nazara/Core/ResourceManager.hpp index 70ad3a545..f3a388c03 100644 --- a/include/Nazara/Core/ResourceManager.hpp +++ b/include/Nazara/Core/ResourceManager.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include namespace Nz diff --git a/include/Nazara/Core/ResourceSaver.hpp b/include/Nazara/Core/ResourceSaver.hpp index a863d8763..4333106e9 100644 --- a/include/Nazara/Core/ResourceSaver.hpp +++ b/include/Nazara/Core/ResourceSaver.hpp @@ -10,9 +10,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/include/Nazara/Core/StdLogger.hpp b/include/Nazara/Core/StdLogger.hpp index 2df4d7539..931b05bc7 100644 --- a/include/Nazara/Core/StdLogger.hpp +++ b/include/Nazara/Core/StdLogger.hpp @@ -24,8 +24,8 @@ namespace Nz bool IsStdReplicationEnabled() const override; - void Write(const String& string) override; - void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override; + void Write(const std::string_view& error) override; + void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override; StdLogger& operator=(const StdLogger&) = default; StdLogger& operator=(StdLogger&&) noexcept = default; diff --git a/include/Nazara/Core/Stream.hpp b/include/Nazara/Core/Stream.hpp index 3296a8a7c..cd21c5f12 100644 --- a/include/Nazara/Core/Stream.hpp +++ b/include/Nazara/Core/Stream.hpp @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include namespace Nz { @@ -49,7 +49,7 @@ namespace Nz virtual bool SetCursorPos(UInt64 offset) = 0; bool Write(const ByteArray& byteArray); - bool Write(const String& string); + bool Write(const std::string_view& string); inline std::size_t Write(const void* buffer, std::size_t size); Stream& operator=(const Stream&) = default; diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp deleted file mode 100644 index 53617ee95..000000000 --- a/include/Nazara/Core/String.hpp +++ /dev/null @@ -1,348 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STRING_HPP -#define NAZARA_STRING_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - struct SerializationContext; - - class NAZARA_CORE_API String - { - public: - enum Flags - { - None = 0x00, // Default mode - CaseInsensitive = 0x01, // Case insensitive - HandleUtf8 = 0x02, // Considers bytes as a list of UTF-8 characters - TrimOnlyLeft = 0x04, // Trim(med), only cut the left part of the string - TrimOnlyRight = 0x08 // Trim(med), only cut the right part of the string - }; - - String(); - explicit String(char character); - String(std::size_t rep, char character); - String(std::size_t rep, const char* string); - String(std::size_t rep, const char* string, std::size_t length); - String(std::size_t rep, const String& string); - String(const char* string); - String(const char* string, std::size_t length); - String(const std::string& string); - String(const String& string) = default; - inline String(String&& string) noexcept; - ~String() = default; - - String& Append(char character); - String& Append(const char* string); - String& Append(const char* string, std::size_t length); - String& Append(const String& string); - - void Clear(bool keepBuffer = false); - - bool Contains(char character, std::intmax_t start = 0, UInt32 flags = None) const; - bool Contains(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - bool Contains(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - - unsigned int Count(char character, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int Count(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int Count(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int CountAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int CountAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - - bool EndsWith(char character, UInt32 flags = None) const; - bool EndsWith(const char* string, UInt32 flags = None) const; - bool EndsWith(const char* string, std::size_t length, UInt32 flags = None) const; - bool EndsWith(const String& string, UInt32 flags = None) const; - - std::size_t Find(char character, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t Find(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t Find(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t FindAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t FindAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t FindLast(char character, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLast(const char* string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLast(const String& string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLastAny(const char* string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLastWord(const char* string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindLastWord(const String& string, std::intmax_t start = -1, UInt32 flags = None) const; - std::size_t FindWord(const char* string, std::intmax_t start = 0, UInt32 flags = None) const; - std::size_t FindWord(const String& string, std::intmax_t start = 0, UInt32 flags = None) const; - - char* GetBuffer(); - std::size_t GetCapacity() const; - std::size_t GetCharacterPosition(std::size_t characterIndex) const; - const char* GetConstBuffer() const; - std::size_t GetLength() const; - std::size_t GetSize() const; - std::string GetUtf8String() const; - std::u16string GetUtf16String() const; - std::u32string GetUtf32String() const; - std::wstring GetWideString() const; - String GetWord(unsigned int index, UInt32 flags = None) const; - std::size_t GetWordPosition(unsigned int index, UInt32 flags = None) const; - - String& Insert(std::intmax_t pos, char character); - String& Insert(std::intmax_t pos, const char* string); - String& Insert(std::intmax_t pos, const char* string, std::size_t length); - String& Insert(std::intmax_t pos, const String& string); - - bool IsEmpty() const; - bool IsNull() const; - bool IsNumber(UInt8 radix = 10, UInt32 flags = CaseInsensitive) const; - - bool Match(const char* pattern) const; - bool Match(const String& pattern) const; - - String& Prepend(char character); - String& Prepend(const char* string); - String& Prepend(const char* string, std::size_t length); - String& Prepend(const String& string); - - unsigned int Replace(char oldCharacter, char newCharacter, std::intmax_t start = 0, UInt32 flags = None); - unsigned int Replace(const char* oldString, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None); - unsigned int Replace(const char* oldString, std::size_t oldLength, const char* replaceString, std::size_t replaceLength, std::intmax_t start = 0, UInt32 flags = None); - unsigned int Replace(const String& oldString, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None); - unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, std::intmax_t start = 0, UInt32 flags = None); - //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None); - //unsigned int ReplaceAny(const String& oldCharacters, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None); - - void Reserve(std::size_t bufferSize); - - String& Resize(std::intmax_t size, UInt32 flags = None); - String Resized(std::intmax_t size, UInt32 flags = None) const; - - String& Reverse(); - String Reversed() const; - - String& Set(char character); - String& Set(std::size_t rep, char character); - String& Set(std::size_t rep, const char* string); - String& Set(std::size_t rep, const char* string, std::size_t length); - String& Set(std::size_t rep, const String& string); - String& Set(const char* string); - String& Set(const char* string, std::size_t length); - String& Set(const std::string& string); - String& Set(const String& string); - String& Set(String&& string) noexcept; - - String Simplified(UInt32 flags = None) const; - String& Simplify(UInt32 flags = None); - - unsigned int Split(std::vector& result, char separation = ' ', std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int Split(std::vector& result, const char* separation, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int Split(std::vector& result, const char* separation, std::size_t length, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int Split(std::vector& result, const String& separation, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const char* separations, std::intmax_t start = 0, UInt32 flags = None) const; - unsigned int SplitAny(std::vector& result, const String& separations, std::intmax_t start = 0, UInt32 flags = None) const; - - bool StartsWith(char character, UInt32 flags = None) const; - bool StartsWith(const char* string, UInt32 flags = None) const; - bool StartsWith(const String& string, UInt32 flags = None) const; - - String SubString(std::intmax_t startPos, std::intmax_t endPos = -1) const; - String SubStringFrom(char character, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; - String SubStringFrom(const char* string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; - String SubStringFrom(const char* string, std::size_t length, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; - String SubStringFrom(const String& string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; - String SubStringTo(char character, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; - String SubStringTo(const char* string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; - String SubStringTo(const char* string, std::size_t length, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; - String SubStringTo(const String& string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; - - void Swap(String& str); - - bool ToBool(bool* value, UInt32 flags = None) const; - bool ToDouble(double* value) const; - bool ToInteger(long long* value, UInt8 radix = 10) const; - String ToLower(UInt32 flags = None) const; - std::string ToStdString() const; - String ToUpper(UInt32 flags = None) const; - - String& Trim(UInt32 flags = None); - String& Trim(char character, UInt32 flags = None); - String Trimmed(UInt32 flags = None) const; - String Trimmed(char character, UInt32 flags = None) const; - - // Méthodes STD - char* begin(); - const char* begin() const; - char* end(); - const char* end() const; - void push_front(char c); - void push_back(char c); - //char* rbegin(); - //const char* rbegin() const; - //char* rend(); - //const char* rend() const; - - using const_reference = const char&; - using iterator = char*; - //using reverse_iterator = char*; - using value_type = char; - // Méthodes STD - - char& operator[](std::size_t pos); - char operator[](std::size_t pos) const; - - String& operator=(char character); - String& operator=(const char* string); - String& operator=(const std::string& string); - String& operator=(const String& string); - String& operator=(String&& string) noexcept; - - String operator+(char character) const; - String operator+(const char* string) const; - String operator+(const std::string& string) const; - String operator+(const String& string) const; - - String& operator+=(char character); - String& operator+=(const char* string); - String& operator+=(const std::string& string); - String& operator+=(const String& string); - - bool operator==(char character) const; - bool operator==(const char* string) const; - bool operator==(const std::string& string) const; - - bool operator!=(char character) const; - bool operator!=(const char* string) const; - bool operator!=(const std::string& string) const; - - bool operator<(char character) const; - bool operator<(const char* string) const; - bool operator<(const std::string& string) const; - - bool operator<=(char character) const; - bool operator<=(const char* string) const; - bool operator<=(const std::string& string) const; - - bool operator>(char character) const; - bool operator>(const char* string) const; - bool operator>(const std::string& string) const; - - bool operator>=(char character) const; - bool operator>=(const char* string) const; - bool operator>=(const std::string& string) const; - - static String Boolean(bool boolean); - static int Compare(const String& first, const String& second); - static inline String Format(const char* format, ...); - static String FormatVA(const char* format, va_list arg); - static String Number(float number); - static String Number(double number); - static String Number(long double number); - static String Number(signed char number, UInt8 radix = 10); - static String Number(unsigned char number, UInt8 radix = 10); - static String Number(short number, UInt8 radix = 10); - static String Number(unsigned short number, UInt8 radix = 10); - static String Number(int number, UInt8 radix = 10); - static String Number(unsigned int number, UInt8 radix = 10); - static String Number(long number, UInt8 radix = 10); - static String Number(unsigned long number, UInt8 radix = 10); - static String Number(long long number, UInt8 radix = 10); - static String Number(unsigned long long number, UInt8 radix = 10); - static String Pointer(const void* ptr); - static String Unicode(char32_t character); - static String Unicode(const char* u8String); - static String Unicode(const char16_t* u16String); - static String Unicode(const char32_t* u32String); - static String Unicode(const wchar_t* wString); - - NAZARA_CORE_API friend std::istream& operator>>(std::istream& in, String& string); - NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& out, const String& string); - - NAZARA_CORE_API friend String operator+(char character, const String& string); - NAZARA_CORE_API friend String operator+(const char* string, const String& nstring); - NAZARA_CORE_API friend String operator+(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator==(const String& first, const String& second); - NAZARA_CORE_API friend bool operator!=(const String& first, const String& second); - NAZARA_CORE_API friend bool operator<(const String& first, const String& second); - NAZARA_CORE_API friend bool operator<=(const String& first, const String& second); - NAZARA_CORE_API friend bool operator>(const String& first, const String& second); - NAZARA_CORE_API friend bool operator>=(const String& first, const String& second); - - NAZARA_CORE_API friend bool operator==(char character, const String& nstring); - NAZARA_CORE_API friend bool operator==(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator==(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator!=(char character, const String& nstring); - NAZARA_CORE_API friend bool operator!=(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator!=(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator<(char character, const String& nstring); - NAZARA_CORE_API friend bool operator<(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator<(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator<=(char character, const String& nstring); - NAZARA_CORE_API friend bool operator<=(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator<=(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator>(char character, const String& nstring); - NAZARA_CORE_API friend bool operator>(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator>(const std::string& string, const String& nstring); - - NAZARA_CORE_API friend bool operator>=(char character, const String& nstring); - NAZARA_CORE_API friend bool operator>=(const char* string, const String& nstring); - NAZARA_CORE_API friend bool operator>=(const std::string& string, const String& nstring); - - static const std::size_t npos; - - private: - struct SharedString; - - String(std::shared_ptr&& sharedString); - - void EnsureOwnership(bool discardContent = false); - inline void ReleaseString(); - - static const std::shared_ptr& GetEmptyString(); - - std::shared_ptr m_sharedString; - - struct SharedString - { - inline SharedString(); - inline SharedString(std::size_t strSize); - inline SharedString(std::size_t strSize, std::size_t strCapacity); - - std::size_t capacity; - std::size_t size; - std::unique_ptr string; - }; - }; - - class AbstractHash; - - inline bool HashAppend(AbstractHash* hash, const String& string); - NAZARA_CORE_API bool Serialize(SerializationContext& context, const String& string, TypeTag); - NAZARA_CORE_API bool Unserialize(SerializationContext& context, String* string, TypeTag); -} - -namespace std -{ - NAZARA_CORE_API istream& getline(istream& is, Nz::String& str); - NAZARA_CORE_API istream& getline(istream& is, Nz::String& str, char delim); - NAZARA_CORE_API void swap(Nz::String& lhs, Nz::String& rhs); - - template<> - struct hash; -} - -#include - -#endif // NAZARA_STRING_HPP diff --git a/include/Nazara/Core/String.inl b/include/Nazara/Core/String.inl deleted file mode 100644 index d66eb3d29..000000000 --- a/include/Nazara/Core/String.inl +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - inline Nz::String::String(String&& string) noexcept : - m_sharedString(std::move(string.m_sharedString)) - { - string.m_sharedString = GetEmptyString(); - } - - inline String::String(std::shared_ptr&& sharedString) : - m_sharedString(std::move(sharedString)) - { - } - - /*! - * \brief Build a string using a format and returns it - * \return Formatted string - * - * \param format String format - * \param ... Format arguments - */ - String String::Format(const char* format, ...) - { - va_list args; - va_start(args, format); - String result = FormatVA(format, args); - va_end(args); - - return result; - } - - /*! - * \brief Releases the content to the string - */ - - inline void String::ReleaseString() - { - m_sharedString = GetEmptyString(); - } - - /*! - * \brief Constructs a SharedString object by default - */ - - inline String::SharedString::SharedString() : // Special case: empty string - capacity(0), - size(0) - { - } - - /*! - * \brief Constructs a SharedString object with a size - * - * \param strSize Number of characters in the string - */ - - inline String::SharedString::SharedString(std::size_t strSize) : - capacity(strSize), - size(strSize), - string(new char[strSize + 1]) - { - string[strSize] = '\0'; - } - - /*! - * \brief Constructs a SharedString object with a size and a capacity - * - * \param strSize Number of characters in the string - * \param strCapacity Capacity in characters in the string - */ - - inline String::SharedString::SharedString(std::size_t strSize, std::size_t strCapacity) : - capacity(strCapacity), - size(strSize), - string(new char[strCapacity + 1]) - { - string[strSize] = '\0'; - } - - /*! - * \brief Appends the string to the hash - * \return true if hash is successful - * - * \param hash Hash to append data of the file - * \param string String to hash - */ - - inline bool HashAppend(AbstractHash* hash, const String& string) - { - hash->Append(reinterpret_cast(string.GetConstBuffer()), string.GetSize()); - return true; - } -} - -namespace std -{ - template<> - struct hash - { - /*! - * \brief Specialisation of std to hash - * \return Result of the hash - * - * \param str String to hash - */ - size_t operator()(const Nz::String& str) const - { - // Algorithme DJB2 - // http://www.cse.yorku.ca/~oz/hash.html - - size_t h = 5381; - if (!str.IsEmpty()) - { - const char* ptr = str.GetConstBuffer(); - - do - h = ((h << 5) + h) + static_cast(*ptr); - while (*++ptr); - } - - return h; - } - }; -} - -#include diff --git a/include/Nazara/Core/StringExt.hpp b/include/Nazara/Core/StringExt.hpp index c4b314fb8..3520e67ce 100644 --- a/include/Nazara/Core/StringExt.hpp +++ b/include/Nazara/Core/StringExt.hpp @@ -9,6 +9,7 @@ #include #include +#include //< FIXME #include namespace Nz @@ -17,49 +18,70 @@ namespace Nz struct UnicodeAware {}; // std::string is assumed to contains UTF-8 - NAZARA_CORE_API std::string FromUtf16String(const char16_t* u16str); NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str); - - NAZARA_CORE_API std::string FromUtf32String(const char32_t* u32str); NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str); - - NAZARA_CORE_API std::string FromWideString(const wchar_t* wstr); NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str); - inline bool IsNumber(const char* str); - inline bool IsNumber(const std::string_view& str); + NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex); + NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware); + + inline bool IsNumber(std::string_view str); - inline bool MatchPattern(const std::string_view& str, const char* pattern); NAZARA_CORE_API bool MatchPattern(const std::string_view& str, const std::string_view& pattern); - template bool StartsWith(const std::string_view& str, const char* s, Args&&... args); + NAZARA_CORE_API std::string PointerToString(const void* ptr); + + inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to); + inline bool StartsWith(const std::string_view& str, const std::string_view& s); - NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent); - NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent, UnicodeAware); + NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent); + NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware); + NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware); template bool SplitString(const std::string_view& str, const std::string_view& token, F&& func); template bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func); - inline std::string ToLower(const char* str); - NAZARA_CORE_API std::string ToLower(const std::string_view& str); + inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs); + inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent); + NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware); + NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware); - inline std::string ToLower(const char* str, UnicodeAware); + NAZARA_CORE_API std::string ToLower(const std::string_view& str); NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware); - inline std::string ToUpper(const char* str); NAZARA_CORE_API std::string ToUpper(const std::string_view& str); - - inline std::string ToUpper(const char* str, UnicodeAware); NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware); - inline std::u16string ToUtf16String(const char* str); NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str); - - inline std::u32string ToUtf32String(const char* str); NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str); - - inline std::wstring ToWideString(const char* str); NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str); + + inline std::string_view Trim(std::string_view str); + inline std::string_view Trim(std::string_view str, char c); + inline std::string_view Trim(std::string_view str, char c, CaseIndependent); + inline std::string_view Trim(std::string_view str, Unicode::Category category); + inline std::string_view Trim(std::string_view str, UnicodeAware); + inline std::string_view Trim(std::string_view str, char32_t c, UnicodeAware); + inline std::string_view Trim(std::string_view str, char32_t c, CaseIndependent, UnicodeAware); + inline std::string_view Trim(std::string_view str, Unicode::Category category, UnicodeAware); + + NAZARA_CORE_API std::string_view TrimLeft(std::string_view str); + inline std::string_view TrimLeft(std::string_view str, char c); + inline std::string_view TrimLeft(std::string_view str, char c, CaseIndependent); + inline std::string_view TrimLeft(std::string_view str, Unicode::Category category); + NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, UnicodeAware); + NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, char32_t c, UnicodeAware); + NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, char32_t c, CaseIndependent, UnicodeAware); + NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, Unicode::Category category, UnicodeAware); + + NAZARA_CORE_API std::string_view TrimRight(std::string_view str); + inline std::string_view TrimRight(std::string_view str, char c); + inline std::string_view TrimRight(std::string_view str, char c, CaseIndependent); + inline std::string_view TrimRight(std::string_view str, Unicode::Category category); + NAZARA_CORE_API std::string_view TrimRight(std::string_view str, UnicodeAware); + NAZARA_CORE_API std::string_view TrimRight(std::string_view str, char32_t c, UnicodeAware); + NAZARA_CORE_API std::string_view TrimRight(std::string_view str, char32_t c, CaseIndependent, UnicodeAware); + NAZARA_CORE_API std::string_view TrimRight(std::string_view str, Unicode::Category category, UnicodeAware); } #include diff --git a/include/Nazara/Core/StringExt.inl b/include/Nazara/Core/StringExt.inl index 0ab5c0cff..8874b69d8 100644 --- a/include/Nazara/Core/StringExt.inl +++ b/include/Nazara/Core/StringExt.inl @@ -10,32 +10,33 @@ namespace Nz { - bool IsNumber(const char* str) + inline bool IsNumber(std::string_view str) { - std::size_t size = std::strlen(str); - return IsNumber(std::string_view(str, size)); - } - - bool IsNumber(const std::string_view& str) - { - return !str.empty() && std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end(); - } - - bool MatchPattern(const std::string_view& str, const char* pattern) - { - if (!pattern) + if (str.empty()) return false; - return MatchPattern(str, std::string_view(pattern, std::strlen(pattern))); + if (str.front() == '-') + str.remove_prefix(1); + + return std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end(); } - template bool StartsWith(const std::string_view& str, const char* s, Args&&... args) + inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to) { - std::size_t size = std::strlen(s); - return StartsWith(str, std::string_view(s, size), std::forward(args)...); + if (str.empty()) + return str; + + std::size_t startPos = 0; + while ((startPos = str.find(from, startPos)) != std::string::npos) + { + str.replace(startPos, from.length(), to); + startPos += to.length(); + } + + return str; } - bool StartsWith(const std::string_view& str, const std::string_view& s) + inline bool StartsWith(const std::string_view& str, const std::string_view& s) { //FIXME: Replace with proper C++20 value once it's available #if __cplusplus > 201703L @@ -83,48 +84,116 @@ namespace Nz return func(str.substr(previousPos)); } - inline std::string ToLower(const char* str) + inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs) { - std::size_t size = std::strlen(str); - return ToLower(std::string_view(str, size)); + return lhs == rhs; } - inline std::string ToLower(const char* str, UnicodeAware) + inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent) { - std::size_t size = std::strlen(str); - return ToLower(std::string_view(str, size), UnicodeAware{}); + if (lhs.size() != rhs.size()) + return false; + + for (std::size_t i = 0; i < lhs.size(); ++i) + { + if (std::tolower(lhs[i]) != std::tolower(rhs[i])) + return false; + } + + return true; } - inline std::string ToUpper(const char* str) + inline std::string_view Trim(std::string_view str) { - std::size_t size = std::strlen(str); - return ToUpper(std::string_view(str, size)); + return TrimRight(TrimLeft(str)); } - inline std::string ToUpper(const char* str, UnicodeAware) + inline std::string_view Trim(std::string_view str, char c) { - std::size_t size = std::strlen(str); - return ToUpper(std::string_view(str, size), UnicodeAware{}); + return TrimRight(TrimLeft(str, c), c); } - inline std::u16string ToUtf16String(const char* str) + inline std::string_view Trim(std::string_view str, char c, CaseIndependent) { - std::size_t size = std::strlen(str); - return ToUtf16String(std::string_view(str, size)); + return TrimRight(TrimLeft(str, c, CaseIndependent{}), c, CaseIndependent{}); } - inline std::u32string ToUtf32String(const char* str) + inline std::string_view Trim(std::string_view str, Unicode::Category category) { - std::size_t size = std::strlen(str); - return ToUtf32String(std::string_view(str, size)); + return TrimRight(TrimLeft(str, category), category); } - inline std::wstring ToWideString(const char* str) + inline std::string_view Trim(std::string_view str, UnicodeAware) { - std::size_t size = std::strlen(str); - return ToWideString(std::string_view(str, size)); + return TrimRight(TrimLeft(str, UnicodeAware{}), UnicodeAware{}); } + inline std::string_view Trim(std::string_view str, char32_t c, UnicodeAware) + { + return TrimRight(TrimLeft(str, c, UnicodeAware{}), c, UnicodeAware{}); + } + + inline std::string_view Trim(std::string_view str, char32_t c, CaseIndependent, UnicodeAware) + { + return TrimRight(TrimLeft(str, c, CaseIndependent{}, UnicodeAware{}), c, CaseIndependent{}, UnicodeAware{}); + } + + inline std::string_view Trim(std::string_view str, Unicode::Category category, UnicodeAware) + { + return TrimRight(TrimLeft(str, category, UnicodeAware{}), category, UnicodeAware{}); + } + + inline std::string_view TrimLeft(std::string_view str, char c) + { + while (!str.empty() && str.front() == c) + str.remove_prefix(1); + + return str; + } + + inline std::string_view TrimLeft(std::string_view str, char c, CaseIndependent) + { + c = char(std::tolower(c)); + + while (!str.empty() && std::tolower(str.front()) == c) + str.remove_prefix(1); + + return str; + } + + inline std::string_view TrimLeft(std::string_view str, Unicode::Category category) + { + while (!str.empty() && (Unicode::GetCategory(str.front()) & category) == category) + str.remove_prefix(1); + + return str; + } + + inline std::string_view TrimRight(std::string_view str, char c) + { + while (!str.empty() && str.back() == c) + str.remove_suffix(1); + + return str; + } + + inline std::string_view TrimRight(std::string_view str, char c, CaseIndependent) + { + c = char(std::tolower(c)); + + while (!str.empty() && std::tolower(str.back()) == c) + str.remove_suffix(1); + + return str; + } + + inline std::string_view TrimRight(std::string_view str, Unicode::Category category) + { + while (!str.empty() && (Unicode::GetCategory(str.back()) & category) == category) + str.remove_suffix(1); + + return str; + } } #include diff --git a/include/Nazara/Core/StringStream.hpp b/include/Nazara/Core/StringStream.hpp deleted file mode 100644 index 22864f0a1..000000000 --- a/include/Nazara/Core/StringStream.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_STRINGSTREAM_HPP -#define NAZARA_STRINGSTREAM_HPP - -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_CORE_API StringStream - { - public: - StringStream() = default; - StringStream(String str); - StringStream(const StringStream&) = default; - StringStream(StringStream&&) noexcept = default; - - void Clear(); - - std::size_t GetBufferSize() const; - - String ToString() const; - - StringStream& operator=(const StringStream&) = default; - StringStream& operator=(StringStream&&) noexcept = default; - - StringStream& operator<<(bool boolean); - StringStream& operator<<(short number); - StringStream& operator<<(unsigned short number); - StringStream& operator<<(int number); - StringStream& operator<<(unsigned int number); - StringStream& operator<<(long number); - StringStream& operator<<(unsigned long number); - StringStream& operator<<(long long number); - StringStream& operator<<(unsigned long long number); - StringStream& operator<<(float number); - StringStream& operator<<(double number); - StringStream& operator<<(long double number); - StringStream& operator<<(char character); - StringStream& operator<<(unsigned char character); - StringStream& operator<<(const char* string); - StringStream& operator<<(const std::string& string); - StringStream& operator<<(const String& string); - StringStream& operator<<(const void* ptr); - - operator String() const; - - private: - String m_result; - }; -} - -#endif // NAZARA_STRINGSTREAM_HPP diff --git a/include/Nazara/Graphics.hpp b/include/Nazara/Graphics.hpp new file mode 100644 index 000000000..dfdcd7991 --- /dev/null +++ b/include/Nazara/Graphics.hpp @@ -0,0 +1,36 @@ +// This file was automatically generated + +/* + Nazara Engine - Graphics module + + Copyright (C) 2020 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + + 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 + +#ifndef NAZARA_GLOBAL_GRAPHICS_HPP +#define NAZARA_GLOBAL_GRAPHICS_HPP + +#include +#include +#include + +#endif // NAZARA_GLOBAL_GRAPHICS_HPP diff --git a/include/Nazara/Math/Algorithm.hpp b/include/Nazara/Math/Algorithm.hpp index 0ba481f7f..7c22947b9 100644 --- a/include/Nazara/Math/Algorithm.hpp +++ b/include/Nazara/Math/Algorithm.hpp @@ -9,9 +9,9 @@ #define NAZARA_ALGORITHM_MATH_HPP #include -#include #include #include +#include #ifndef M_PI #define M_PI 3.141592653589793238462643 @@ -59,9 +59,9 @@ namespace Nz template constexpr T NormalizeAngle(T angle); template constexpr bool NumberEquals(T a, T b); template constexpr bool NumberEquals(T a, T b, T maxDifference); - String NumberToString(long long number, UInt8 radix = 10); + inline std::string NumberToString(long long number, UInt8 radix = 10); template constexpr T RadianToDegree(T radians); - long long StringToNumber(String str, UInt8 radix = 10, bool* ok = nullptr); + inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr); template constexpr T ToDegrees(T angle); template constexpr T ToRadians(T angle); } diff --git a/include/Nazara/Math/Algorithm.inl b/include/Nazara/Math/Algorithm.inl index 6b06196fa..d480f60f8 100644 --- a/include/Nazara/Math/Algorithm.inl +++ b/include/Nazara/Math/Algorithm.inl @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include @@ -571,20 +570,18 @@ namespace Nz * \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior * \remark With NAZARA_MATH_SAFE, a NazaraError is produced and String() is returned */ - inline String NumberToString(long long number, UInt8 radix) + inline std::string NumberToString(long long number, UInt8 radix) { #if NAZARA_MATH_SAFE if (radix < 2 || radix > 36) { NazaraError("Base must be between 2 and 36"); - return String(); + return {}; } #endif if (number == 0) - return String('0'); - - static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return "0"; bool negative; if (number < 0) @@ -595,20 +592,23 @@ namespace Nz else negative = false; - String str; - str.Reserve(GetNumberLength(number)); // Prends en compte le signe négatif + std::string str; + + const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; do { - str.Append(symbols[number % radix]); + str.push_back(symbols[number % radix]); number /= radix; } while (number > 0); if (negative) - str.Append('-'); + str.push_back('-'); - return str.Reverse(); + std::reverse(str.begin(), str.end()); + + return str; } /*! @@ -636,7 +636,7 @@ namespace Nz * \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior * \remark With NAZARA_MATH_SAFE, a NazaraError is produced and 0 is returned */ - inline long long StringToNumber(String str, UInt8 radix, bool* ok) + inline long long StringToNumber(const std::string_view& str, UInt8 radix, bool* ok) { #if NAZARA_MATH_SAFE if (radix < 2 || radix > 36) @@ -650,15 +650,19 @@ namespace Nz } #endif - static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if (str.empty()) + { + if (ok) + *ok = false; - str.Simplify(); - if (radix > 10) - str = str.ToUpper(); + return 0; + } - bool negative = str.StartsWith('-'); + const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char* digit = &str[(negative) ? 1 : 0]; + bool negative = (str.front() == '-'); + + const char* digit = &str[(negative) ? 1 : 0]; unsigned long long total = 0; do { diff --git a/include/Nazara/Math/Angle.hpp b/include/Nazara/Math/Angle.hpp index 7afb54dcc..46c1d30ab 100644 --- a/include/Nazara/Math/Angle.hpp +++ b/include/Nazara/Math/Angle.hpp @@ -7,10 +7,11 @@ #ifndef NAZARA_ANGLE_HPP #define NAZARA_ANGLE_HPP -#include +#include #include #include #include +#include #include #include @@ -50,7 +51,7 @@ namespace Nz Quaternion ToQuaternion() const; T ToRadians() const; Angle ToRadianAngle() const; - String ToString() const; + std::string ToString() const; Angle& operator=(const Angle&) = default; diff --git a/include/Nazara/Math/Angle.inl b/include/Nazara/Math/Angle.inl index 6b04f12c3..d18e07ca9 100644 --- a/include/Nazara/Math/Angle.inl +++ b/include/Nazara/Math/Angle.inl @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef NAZARA_PLATFORM_POSIX #include //< sincos @@ -51,11 +52,6 @@ namespace Nz return DegreeToRadian(degrees); } - template static String ToString(T value) - { - return "Angle(" + String::Number(value) + "deg)"; - } - template static std::ostream& ToString(std::ostream& out, T value) { return out << "Angle(" << value << "deg)"; @@ -95,11 +91,6 @@ namespace Nz return radians; } - template static String ToString(T value) - { - return "Angle(" + String::Number(value) + "rad)"; - } - template static std::ostream& ToString(std::ostream& out, T value) { return out << "Angle(" << value << "rad)"; @@ -358,9 +349,12 @@ namespace Nz * \return String representation of the angle */ template - String Angle::ToString() const + std::string Angle::ToString() const { - return Detail::AngleUtils::ToString(value); + std::ostringstream oss; + Detail::AngleUtils::ToString(oss, value); + + return oss.str(); } /*! diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp index 1daf84281..1134de93e 100644 --- a/include/Nazara/Math/BoundingVolume.hpp +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -5,12 +5,12 @@ #ifndef NAZARA_BOUNDINGVOLUME_HPP #define NAZARA_BOUNDINGVOLUME_HPP -#include #include #include #include #include #include +#include namespace Nz { @@ -47,7 +47,7 @@ namespace Nz BoundingVolume& Set(const Vector3& vec1, const Vector3& vec2); template BoundingVolume& Set(const BoundingVolume& volume); - String ToString() const; + std::string ToString() const; void Update(const Matrix4& transformMatrix); void Update(const Vector3& translation); diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index 12dbf8ed8..2600897e2 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -3,15 +3,13 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { @@ -361,23 +359,12 @@ namespace Nz */ template - String BoundingVolume::ToString() const + std::string BoundingVolume::ToString() const { - switch (extend) - { - case Extend_Finite: - return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')'; + std::ostringstream ss; + ss << *this; - case Extend_Infinite: - return "BoundingVolume(Infinite)"; - - case Extend_Null: - return "BoundingVolume(Null)"; - } - - // Si nous arrivons ici c'est que l'extend est invalide - NazaraError("Invalid extend type (0x" + String::Number(extend, 16) + ')'); - return "BoundingVolume(ERROR)"; + return ss.str(); } /*! @@ -510,17 +497,17 @@ namespace Nz BoundingVolume BoundingVolume::Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Null(); } #endif - if (NumberEquals(interpolation, F(0.0))) + if (NumberEquals(interpolation, T(0.0))) return from; - if (NumberEquals(interpolation, F(1.0))) + if (NumberEquals(interpolation, T(1.0))) return to; switch (to.extend) @@ -545,7 +532,7 @@ namespace Nz } // If we arrive here, the extend is invalid - NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')'); + NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')'); return Null(); } @@ -557,7 +544,7 @@ namespace Nz switch (from.extend) { case Extend_Finite: - return from.obb * (F(1.0) - interpolation); + return from.obb * (T(1.0) - interpolation); case Extend_Infinite: return Infinite(); @@ -567,13 +554,13 @@ namespace Nz } // If we arrive here, the extend is invalid - NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')'); + NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')'); return Null(); } } // If we arrive here, the extend is invalid - NazaraError("Invalid extend type (To) (0x" + String::Number(to.extend, 16) + ')'); + NazaraError("Invalid extend type (To) (0x" + NumberToString(to.extend, 16) + ')'); return Null(); } @@ -659,10 +646,22 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume& volume) { - out << volume.ToString(); + switch (volume.extend) + { + case Nz::Extend_Finite: + out << "BoundingVolume(localBox=" << volume.obb.localBox << ')'; + break; + + case Nz::Extend_Infinite: + out << "BoundingVolume(Infinite)"; + break; + + case Nz::Extend_Null: + out << "BoundingVolume(Null)"; + break; + } + return out; } -#undef F - #include diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index d43378ce7..e14245eb9 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -7,12 +7,12 @@ #ifndef NAZARA_BOX_HPP #define NAZARA_BOX_HPP -#include #include #include #include #include #include +#include namespace Nz { @@ -68,7 +68,7 @@ namespace Nz Box& Set(const Vector3& vec1, const Vector3& vec2); template Box& Set(const Box& box); - String ToString() const; + std::string ToString() const; Box& Transform(const Matrix4& matrix, bool applyTranslation = true); Box& Translate(const Vector3& translation); diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 5dc03837c..9fedec598 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -3,14 +3,12 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -261,7 +259,7 @@ namespace Nz template Vector3 Box::GetCenter() const { - return GetPosition() + GetLengths() / F(2.0); + return GetPosition() + GetLengths() / T(2.0); } /*! @@ -303,7 +301,7 @@ namespace Nz return Vector3(x + width, y + height, z + depth); } - NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')'); + NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')'); return Vector3(); } @@ -358,13 +356,13 @@ namespace Nz { Vector3 neg(GetPosition()); - if (normal.x < F(0.0)) + if (normal.x < T(0.0)) neg.x += width; - if (normal.y < F(0.0)) + if (normal.y < T(0.0)) neg.y += height; - if (normal.z < F(0.0)) + if (normal.z < T(0.0)) neg.z += depth; return neg; @@ -397,13 +395,13 @@ namespace Nz { Vector3 pos(GetPosition()); - if (normal.x > F(0.0)) + if (normal.x > T(0.0)) pos.x += width; - if (normal.y > F(0.0)) + if (normal.y > T(0.0)) pos.y += height; - if (normal.z > F(0.0)) + if (normal.z > T(0.0)) pos.z += depth; return pos; @@ -442,7 +440,7 @@ namespace Nz T Box::GetSquaredRadius() const { Vector3 size(GetLengths()); - size /= F(2.0); // The size only depends on the lengths and not the center + size /= T(2.0); // The size only depends on the lengths and not the center return size.GetSquaredLength(); } @@ -494,7 +492,7 @@ namespace Nz template bool Box::IsValid() const { - return width > F(0.0) && height > F(0.0) && depth > F(0.0); + return width > T(0.0) && height > T(0.0) && depth > T(0.0); } /*! @@ -507,12 +505,12 @@ namespace Nz template Box& Box::MakeZero() { - x = F(0.0); - y = F(0.0); - z = F(0.0); - width = F(0.0); - height = F(0.0); - depth = F(0.0); + x = T(0.0); + y = T(0.0); + z = T(0.0); + width = T(0.0); + height = T(0.0); + depth = T(0.0); return *this; } @@ -531,9 +529,9 @@ namespace Nz template Box& Box::Set(T Width, T Height, T Depth) { - x = F(0.0); - y = F(0.0); - z = F(0.0); + x = T(0.0); + y = T(0.0); + z = T(0.0); width = Width; height = Height; depth = Depth; @@ -599,10 +597,10 @@ namespace Nz { x = rect.x; y = rect.y; - z = F(0.0); + z = T(0.0); width = rect.width; height = rect.height; - depth = F(1.0); + depth = T(1.0); return *this; } @@ -655,12 +653,12 @@ namespace Nz template Box& Box::Set(const Box& box) { - x = F(box.x); - y = F(box.y); - z = F(box.z); - width = F(box.width); - height = F(box.height); - depth = F(box.depth); + x = T(box.x); + y = T(box.y); + z = T(box.z); + width = T(box.width); + height = T(box.height); + depth = T(box.depth); return *this; } @@ -671,11 +669,12 @@ namespace Nz */ template - String Box::ToString() const + std::string Box::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Box(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')'; + return ss.str(); } /*! @@ -689,8 +688,8 @@ namespace Nz template Box& Box::Transform(const Matrix4& matrix, bool applyTranslation) { - Vector3 center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Value multiplying the translation - Vector3 halfSize = GetLengths() / F(2.0); + Vector3 center = matrix.Transform(GetCenter(), (applyTranslation) ? T(1.0) : T(0.0)); // Value multiplying the translation + Vector3 halfSize = GetLengths() / T(2.0); halfSize.Set(std::abs(matrix(0,0)) * halfSize.x + std::abs(matrix(1,0)) * halfSize.y + std::abs(matrix(2,0)) * halfSize.z, std::abs(matrix(0,1)) * halfSize.x + std::abs(matrix(1,1)) * halfSize.y + std::abs(matrix(2,1)) * halfSize.z, @@ -855,9 +854,9 @@ namespace Nz Box Box::Lerp(const Box& from, const Box& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Zero(); } #endif @@ -963,9 +962,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Box& box) { - return out << box.ToString(); + return out << "Box(" << box.x << ", " << box.y << ", " << box.z << ", " << box.width << ", " << box.height << ", " << box.depth << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/EulerAngles.hpp b/include/Nazara/Math/EulerAngles.hpp index 85ed23ebb..4e13e0b8c 100644 --- a/include/Nazara/Math/EulerAngles.hpp +++ b/include/Nazara/Math/EulerAngles.hpp @@ -7,10 +7,10 @@ #ifndef NAZARA_EULERANGLES_HPP #define NAZARA_EULERANGLES_HPP -#include #include #include #include +#include namespace Nz { @@ -43,7 +43,7 @@ namespace Nz //Matrix3 ToRotationMatrix() const; Quaternion ToQuaternion() const; - String ToString() const; + std::string ToString() const; EulerAngles operator+(const EulerAngles& angles) const; EulerAngles operator-(const EulerAngles& angles) const; diff --git a/include/Nazara/Math/EulerAngles.inl b/include/Nazara/Math/EulerAngles.inl index 210407646..67aa909d5 100644 --- a/include/Nazara/Math/EulerAngles.inl +++ b/include/Nazara/Math/EulerAngles.inl @@ -4,16 +4,14 @@ #include #include -#include #include #include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { @@ -96,7 +94,7 @@ namespace Nz template void EulerAngles::MakeZero() { - Set(F(0.0), F(0.0), F(0.0)); + Set(T(0.0), T(0.0), T(0.0)); } /*! @@ -194,9 +192,9 @@ namespace Nz template EulerAngles& EulerAngles::Set(const EulerAngles& angles) { - pitch = F(angles.pitch); - yaw = F(angles.yaw); - roll = F(angles.roll); + pitch = T(angles.pitch); + yaw = T(angles.yaw); + roll = T(angles.roll); return *this; } @@ -210,13 +208,13 @@ namespace Nz Quaternion EulerAngles::ToQuaternion() const { // XYZ - T c1 = std::cos(ToRadians(yaw) / F(2.0)); - T c2 = std::cos(ToRadians(roll) / F(2.0)); - T c3 = std::cos(ToRadians(pitch) / F(2.0)); + T c1 = std::cos(ToRadians(yaw) / T(2.0)); + T c2 = std::cos(ToRadians(roll) / T(2.0)); + T c3 = std::cos(ToRadians(pitch) / T(2.0)); - T s1 = std::sin(ToRadians(yaw) / F(2.0)); - T s2 = std::sin(ToRadians(roll) / F(2.0)); - T s3 = std::sin(ToRadians(pitch) / F(2.0)); + T s1 = std::sin(ToRadians(yaw) / T(2.0)); + T s2 = std::sin(ToRadians(roll) / T(2.0)); + T s3 = std::sin(ToRadians(pitch) / T(2.0)); return Quaternion(c1 * c2 * c3 - s1 * s2 * s3, s1 * s2 * c3 + c1 * c2 * s3, @@ -230,11 +228,12 @@ namespace Nz */ template - String EulerAngles::ToString() const + std::string EulerAngles::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')'; + return ss.str(); } /*! @@ -401,9 +400,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles) { - return out << angles.ToString(); + return out << "EulerAngles(" << angles.pitch << ", " << angles.yaw << ", " << angles.roll << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index 9e893a091..dce528dc1 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -7,7 +7,6 @@ #ifndef NAZARA_FRUSTUM_HPP #define NAZARA_FRUSTUM_HPP -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace Nz { @@ -54,7 +54,7 @@ namespace Nz template Frustum& Set(const Frustum& frustum); - String ToString() const; + std::string ToString() const; template friend bool Serialize(SerializationContext& context, const Frustum& frustum, TypeTag>); diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 51203b751..3dfab07a1 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -7,13 +7,11 @@ // http://www.lighthouse3d.com/tutorials/view-frustum-culling/ #include -#include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { @@ -55,9 +53,9 @@ namespace Nz Frustum& Frustum::Build(T angle, T ratio, T zNear, T zFar, const Vector3& eye, const Vector3& target, const Vector3& up) { #if NAZARA_MATH_ANGLE_RADIAN - angle /= F(2.0); + angle /= T(2.0); #else - angle = DegreeToRadian(angle/F(2.0)); + angle = DegreeToRadian(angle / T(2.0)); #endif T tangent = std::tan(angle); @@ -128,7 +126,7 @@ namespace Nz return false; } - NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')'); + NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')'); return false; } @@ -139,7 +137,7 @@ namespace Nz return false; } - NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')'); + NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')'); return false; } @@ -156,7 +154,7 @@ namespace Nz // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ for (unsigned int i = 0; i <= FrustumPlane_Max; i++) { - if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) + if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0)) return false; } @@ -173,7 +171,7 @@ namespace Nz template bool Frustum::Contains(const OrientedBox& orientedbox) const { - return Contains(&orientedbox[0], 8); + return Contains(orientedbox.GetCorners(), 8); } /*! @@ -207,7 +205,7 @@ namespace Nz { for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) { - if (m_planes[i].Distance(point) < F(0.0)) + if (m_planes[i].Distance(point) < T(0.0)) return false; } @@ -230,7 +228,7 @@ namespace Nz unsigned int j; for (j = 0; j < pointCount; j++ ) { - if (m_planes[i].Distance(points[j]) > F(0.0)) + if (m_planes[i].Distance(points[j]) > T(0.0)) break; } @@ -264,7 +262,7 @@ namespace Nz plane[3] = clipMatrix[15] - clipMatrix[12]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -279,7 +277,7 @@ namespace Nz plane[3] = clipMatrix[15] + clipMatrix[12]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -294,7 +292,7 @@ namespace Nz plane[3] = clipMatrix[15] + clipMatrix[13]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -309,7 +307,7 @@ namespace Nz plane[3] = clipMatrix[15] - clipMatrix[13]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -324,7 +322,7 @@ namespace Nz plane[3] = clipMatrix[15] - clipMatrix[14]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -339,7 +337,7 @@ namespace Nz plane[3] = clipMatrix[15] + clipMatrix[14]; // Normalize the result - invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); + invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]); plane[0] *= invLength; plane[1] *= invLength; plane[2] *= invLength; @@ -356,56 +354,56 @@ namespace Nz Vector4 corner; // FarLeftBottom - corner.Set(F(-1.0), F(-1.0), F(1.0)); + corner.Set(T(-1.0), T(-1.0), T(1.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_FarLeftBottom] = Vector3(corner.x, corner.y, corner.z); // FarLeftTop - corner.Set(F(-1.0), F(1.0), F(1.0)); + corner.Set(T(-1.0), T(1.0), T(1.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_FarLeftTop] = Vector3(corner.x, corner.y, corner.z); // FarRightBottom - corner.Set(F(1.0), F(-1.0), F(1.0)); + corner.Set(T(1.0), T(-1.0), T(1.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_FarRightBottom] = Vector3(corner.x, corner.y, corner.z); // FarRightTop - corner.Set(F(1.0), F(1.0), F(1.0)); + corner.Set(T(1.0), T(1.0), T(1.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_FarRightTop] = Vector3(corner.x, corner.y, corner.z); // NearLeftBottom - corner.Set(F(-1.0), F(-1.0), F(0.0)); + corner.Set(T(-1.0), T(-1.0), T(0.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_NearLeftBottom] = Vector3(corner.x, corner.y, corner.z); // NearLeftTop - corner.Set(F(-1.0), F(1.0), F(0.0)); + corner.Set(T(-1.0), T(1.0), T(0.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_NearLeftTop] = Vector3(corner.x, corner.y, corner.z); // NearRightBottom - corner.Set(F(1.0), F(-1.0), F(0.0)); + corner.Set(T(1.0), T(-1.0), T(0.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); m_corners[BoxCorner_NearRightBottom] = Vector3(corner.x, corner.y, corner.z); // NearRightTop - corner.Set(F(1.0), F(1.0), F(0.0)); + corner.Set(T(1.0), T(1.0), T(0.0)); corner = invClipMatrix.Transform(corner); corner.Normalize(); @@ -448,7 +446,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (corner > BoxCorner_Max) { - NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')'); + NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')'); static Vector3 dummy; return dummy; @@ -473,7 +471,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (plane > FrustumPlane_Max) { - NazaraError("Frustum plane not handled (0x" + String::Number(plane, 16) + ')'); + NazaraError("Frustum plane not handled (0x" + NumberToString(plane, 16) + ')'); static Plane dummy; return dummy; @@ -515,7 +513,7 @@ namespace Nz return IntersectionSide_Outside; } - NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')'); + NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')'); return IntersectionSide_Outside; } @@ -526,7 +524,7 @@ namespace Nz return IntersectionSide_Outside; } - NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')'); + NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')'); return IntersectionSide_Outside; } @@ -545,9 +543,9 @@ namespace Nz for (unsigned int i = 0; i <= FrustumPlane_Max; i++) { - if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) + if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0)) return IntersectionSide_Outside; - else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < F(0.0)) + else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < T(0.0)) side = IntersectionSide_Intersecting; } @@ -564,7 +562,7 @@ namespace Nz template IntersectionSide Frustum::Intersect(const OrientedBox& orientedbox) const { - return Intersect(&orientedbox[0], 8); + return Intersect(orientedbox.GetCorners(), 8); } /*! @@ -610,7 +608,7 @@ namespace Nz unsigned int j; for (j = 0; j < pointCount; j++ ) { - if (m_planes[i].Distance(points[j]) > F(0.0)) + if (m_planes[i].Distance(points[j]) > T(0.0)) break; } @@ -649,16 +647,12 @@ namespace Nz */ template - String Frustum::ToString() const + std::string Frustum::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Frustum(Bottom: " << m_planes[FrustumPlane_Bottom].ToString() << "\n" - << " Far: " << m_planes[FrustumPlane_Far].ToString() << "\n" - << " Left: " << m_planes[FrustumPlane_Left].ToString() << "\n" - << " Near: " << m_planes[FrustumPlane_Near].ToString() << "\n" - << " Right: " << m_planes[FrustumPlane_Right].ToString() << "\n" - << " Top: " << m_planes[FrustumPlane_Top].ToString() << ")\n"; + return ss.str(); } /*! @@ -723,9 +717,12 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Frustum& frustum) { - return out << frustum.ToString(); + return out << "Frustum(Bottom: " << frustum.GetPlane(Nz::FrustumPlane_Bottom) << ",\n" + << " Far: " << frustum.GetPlane(Nz::FrustumPlane_Far) << ",\n" + << " Left: " << frustum.GetPlane(Nz::FrustumPlane_Left) << ",\n" + << " Near: " << frustum.GetPlane(Nz::FrustumPlane_Near) << ",\n" + << " Right: " << frustum.GetPlane(Nz::FrustumPlane_Right) << ",\n" + << " Top: " << frustum.GetPlane(Nz::FrustumPlane_Top) << ")\n"; } -#undef F - #include diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index bcb51c378..f2c0be4ca 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -9,8 +9,9 @@ ///FIXME: Matrices column-major, difficile de bosser avec (Tout passer en row-major et transposer dans les shaders ?) -#include +#include #include +#include namespace Nz { @@ -90,7 +91,7 @@ namespace Nz Matrix4& SetScale(const Vector3& scale); Matrix4& SetTranslation(const Vector3& translation); - String ToString() const; + std::string ToString() const; Vector2 Transform(const Vector2& vector, T z = 0.0, T w = 1.0) const; Vector3 Transform(const Vector3& vector, T w = 1.0) const; diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index a74391437..e1482511c 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include @@ -14,11 +13,10 @@ #include #include #include +#include #include #include -#define F(a) static_cast(a) - namespace Nz { @@ -202,22 +200,22 @@ namespace Nz return Set(m11*matrix.m11 + m12*matrix.m21 + m13*matrix.m31, m11*matrix.m12 + m12*matrix.m22 + m13*matrix.m32, m11*matrix.m13 + m12*matrix.m23 + m13*matrix.m33, - F(0.0), + T(0.0), m21*matrix.m11 + m22*matrix.m21 + m23*matrix.m31, m21*matrix.m12 + m22*matrix.m22 + m23*matrix.m32, m21*matrix.m13 + m22*matrix.m23 + m23*matrix.m33, - F(0.0), + T(0.0), m31*matrix.m11 + m32*matrix.m21 + m33*matrix.m31, m31*matrix.m12 + m32*matrix.m22 + m33*matrix.m32, m31*matrix.m13 + m32*matrix.m23 + m33*matrix.m33, - F(0.0), + T(0.0), m41*matrix.m11 + m42*matrix.m21 + m43*matrix.m31 + matrix.m41, m41*matrix.m12 + m42*matrix.m22 + m43*matrix.m32 + matrix.m42, m41*matrix.m13 + m42*matrix.m23 + m43*matrix.m33 + matrix.m43, - F(1.0)); + T(1.0)); } template @@ -257,10 +255,10 @@ namespace Nz #if NAZARA_MATH_SAFE if (column > 3) { - String error("Column out of range: (" + String::Number(column) + ") > 3"); + std::string error("Column out of range: (" + std::to_string(column) + ") > 3"); NazaraError(error); - throw std::out_of_range(error.ToStdString()); + throw std::out_of_range(error); } #endif @@ -466,7 +464,7 @@ namespace Nz m31 * m12 * m23 - m31 * m13 * m22; - T invDet = F(1.0) / det; + T invDet = T(1.0) / det; for (unsigned int i = 0; i < 16; ++i) inv[i] *= invDet; @@ -508,7 +506,7 @@ namespace Nz #endif T det = GetDeterminantAffine(); - if (det != F(0.0)) + if (det != T(0.0)) { // http://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix T inv[16]; @@ -521,7 +519,7 @@ namespace Nz inv[2] = m12 * m23 - m22 * m13; - inv[3] = F(0.0); + inv[3] = T(0.0); inv[4] = -m21 * m33 + m31 * m23; @@ -532,7 +530,7 @@ namespace Nz inv[6] = -m11 * m23 + m21 * m13; - inv[7] = F(0.0); + inv[7] = T(0.0); inv[8] = m21 * m32 - m31 * m22; @@ -543,7 +541,7 @@ namespace Nz inv[10] = m11 * m22 - m21 * m12; - inv[11] = F(0.0); + inv[11] = T(0.0); inv[12] = -m21 * m32 * m43 + m21 * m33 * m42 + @@ -566,11 +564,11 @@ namespace Nz m41 * m12 * m23 + m41 * m13 * m22; - T invDet = F(1.0) / det; + T invDet = T(1.0) / det; for (unsigned int i = 0; i < 16; ++i) inv[i] *= invDet; - inv[15] = F(1.0); + inv[15] = T(1.0); *dest = inv; return true; @@ -591,10 +589,10 @@ namespace Nz Quaternion quat; T trace = m11 + m22 + m33; - if (trace > F(0.0)) + if (trace > T(0.0)) { - T s = F(0.5) / std::sqrt(trace + F(1.0)); - quat.w = F(0.25) / s; + T s = T(0.5) / std::sqrt(trace + T(1.0)); + quat.w = T(0.25) / s; quat.x = (m23 - m32) * s; quat.y = (m31 - m13) * s; quat.z = (m12 - m21) * s; @@ -603,30 +601,30 @@ namespace Nz { if (m11 > m22 && m11 > m33) { - T s = F(2.0) * std::sqrt(F(1.0) + m11 - m22 - m33); + T s = T(2.0) * std::sqrt(T(1.0) + m11 - m22 - m33); quat.w = (m23 - m32) / s; - quat.x = F(0.25) * s; + quat.x = T(0.25) * s; quat.y = (m21 + m12) / s; quat.z = (m31 + m13) / s; } else if (m22 > m33) { - T s = F(2.0) * std::sqrt(F(1.0) + m22 - m11 - m33); + T s = T(2.0) * std::sqrt(T(1.0) + m22 - m11 - m33); quat.w = (m31 - m13) / s; quat.x = (m21 + m12) / s; - quat.y = F(0.25) * s; + quat.y = T(0.25) * s; quat.z = (m32 + m23) / s; } else { - T s = F(2.0) * std::sqrt(F(1.0) + m33 - m11 - m22); + T s = T(2.0) * std::sqrt(T(1.0) + m33 - m11 - m22); quat.w = (m12 - m21) / s; quat.x = (m31 + m13) / s; quat.y = (m32 + m23) / s; - quat.z = F(0.25) * s; + quat.z = T(0.25) * s; } } @@ -651,10 +649,10 @@ namespace Nz #if NAZARA_MATH_SAFE if (row > 3) { - String error("Row out of range: (" + String::Number(row) + ") > 3"); + std::string error("Row out of range: (" + NumberToString(row) + ") > 3"); NazaraError(error); - throw std::out_of_range(error.ToStdString()); + throw std::out_of_range(error); } #endif @@ -740,7 +738,7 @@ namespace Nz template bool Matrix4::HasNegativeScale() const { - return GetDeterminant() < F(0.0); + return GetDeterminant() < T(0.0); } /*! @@ -754,15 +752,15 @@ namespace Nz bool Matrix4::HasScale() const { T t = m11*m11 + m21*m21 + m31*m31; - if (!NumberEquals(t, F(1.0))) + if (!NumberEquals(t, T(1.0))) return true; t = m12*m12 + m22*m22 + m32*m32; - if (!NumberEquals(t, F(1.0))) + if (!NumberEquals(t, T(1.0))) return true; t = m13*m13 + m23*m23 + m33*m33; - if (!NumberEquals(t, F(1.0))) + if (!NumberEquals(t, T(1.0))) return true; return false; @@ -814,7 +812,7 @@ namespace Nz template bool Matrix4::IsAffine() const { - return NumberEquals(m14, F(0.0)) && NumberEquals(m24, F(0.0)) && NumberEquals(m34, F(0.0)) && NumberEquals(m44, F(1.0)); + return NumberEquals(m14, T(0.0)) && NumberEquals(m24, T(0.0)) && NumberEquals(m34, T(0.0)) && NumberEquals(m44, T(1.0)); } /*! @@ -825,10 +823,10 @@ namespace Nz template bool Matrix4::IsIdentity() const { - return (NumberEquals(m11, F(1.0)) && NumberEquals(m12, F(0.0)) && NumberEquals(m13, F(0.0)) && NumberEquals(m14, F(0.0)) && - NumberEquals(m21, F(0.0)) && NumberEquals(m22, F(1.0)) && NumberEquals(m23, F(0.0)) && NumberEquals(m24, F(0.0)) && - NumberEquals(m31, F(0.0)) && NumberEquals(m32, F(0.0)) && NumberEquals(m33, F(1.0)) && NumberEquals(m34, F(0.0)) && - NumberEquals(m41, F(0.0)) && NumberEquals(m42, F(0.0)) && NumberEquals(m43, F(0.0)) && NumberEquals(m44, F(1.0))); + return (NumberEquals(m11, T(1.0)) && NumberEquals(m12, T(0.0)) && NumberEquals(m13, T(0.0)) && NumberEquals(m14, T(0.0)) && + NumberEquals(m21, T(0.0)) && NumberEquals(m22, T(1.0)) && NumberEquals(m23, T(0.0)) && NumberEquals(m24, T(0.0)) && + NumberEquals(m31, T(0.0)) && NumberEquals(m32, T(0.0)) && NumberEquals(m33, T(1.0)) && NumberEquals(m34, T(0.0)) && + NumberEquals(m41, T(0.0)) && NumberEquals(m42, T(0.0)) && NumberEquals(m43, T(0.0)) && NumberEquals(m44, T(1.0))); } /*! @@ -841,10 +839,10 @@ namespace Nz template Matrix4& Matrix4::MakeIdentity() { - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); + Set(T(1.0), T(0.0), T(0.0), T(0.0), + T(0.0), T(1.0), T(0.0), T(0.0), + T(0.0), T(0.0), T(1.0), T(0.0), + T(0.0), T(0.0), T(0.0), T(1.0)); return *this; } @@ -893,10 +891,10 @@ namespace Nz Matrix4& Matrix4::MakeOrtho(T left, T right, T top, T bottom, T zNear, T zFar) { // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204942(v=vs.85).aspx - Set(F(2.0) / (right - left), F(0.0), F(0.0), F(0.0), - F(0.0), F(2.0) / (top - bottom), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0) / (zNear - zFar), F(0.0), - (left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), F(1.0)); + Set(T(2.0) / (right - left), T(0.0), T(0.0), T(0.0), + T(0.0), T(2.0) / (top - bottom), T(0.0), T(0.0), + T(0.0), T(0.0), T(1.0) / (zNear - zFar), T(0.0), + (left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), T(1.0)); return *this; } @@ -918,17 +916,17 @@ namespace Nz { // http://msdn.microsoft.com/en-us/library/windows/desktop/bb204945(v=vs.85).aspx #if NAZARA_MATH_ANGLE_RADIAN - angle /= F(2.0); + angle /= T(2.0); #else - angle = DegreeToRadian(angle/F(2.0)); + angle = DegreeToRadian(angle / T(2.0)); #endif T yScale = std::tan(static_cast(M_PI_2) - angle); - Set(yScale / ratio, F(0.0), F(0.0), F(0.0), - F(0.0), yScale, F(0.0), F(0.0), - F(0.0), F(0.0), - (zFar + zNear) / (zFar - zNear), F(-1.0), - F(0.0), F(0.0), F(-2.0) * (zNear * zFar) / (zFar - zNear), F(0.0)); + Set(yScale / ratio, T(0.0), T(0.0), T(0.0), + T(0.0), yScale, T(0.0), T(0.0), + T(0.0), T(0.0), - (zFar + zNear) / (zFar - zNear), T(-1.0), + T(0.0), T(0.0), T(-2.0) * (zNear * zFar) / (zFar - zNear), T(0.0)); return *this; } @@ -948,13 +946,13 @@ namespace Nz SetRotation(rotation); // We complete the matrix - m14 = F(0.0); - m24 = F(0.0); - m34 = F(0.0); - m41 = F(0.0); - m42 = F(0.0); - m43 = F(0.0); - m44 = F(1.0); + m14 = T(0.0); + m24 = T(0.0); + m34 = T(0.0); + m41 = T(0.0); + m42 = T(0.0); + m43 = T(0.0); + m44 = T(1.0); return *this; } @@ -971,10 +969,10 @@ namespace Nz template Matrix4& Matrix4::MakeScale(const Vector3& scale) { - Set(scale.x, F(0.0), F(0.0), F(0.0), - F(0.0), scale.y, F(0.0), F(0.0), - F(0.0), F(0.0), scale.z, F(0.0), - F(0.0), F(0.0), F(0.0), F(1.0)); + Set(scale.x, T(0.0), T(0.0), T(0.0), + T(0.0), scale.y, T(0.0), T(0.0), + T(0.0), T(0.0), scale.z, T(0.0), + T(0.0), T(0.0), T(0.0), T(1.0)); return *this; } @@ -991,10 +989,10 @@ namespace Nz template Matrix4& Matrix4::MakeTranslation(const Vector3& translation) { - Set(F(1.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(1.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(1.0), F(0.0), - translation.x, translation.y, translation.z, F(1.0)); + Set(T(1.0), T(0.0), T(0.0), T(0.0), + T(0.0), T(1.0), T(0.0), T(0.0), + T(0.0), T(0.0), T(1.0), T(0.0), + translation.x, translation.y, translation.z, T(1.0)); return *this; } @@ -1019,10 +1017,10 @@ namespace Nz SetTranslation(translation); // We complete the matrix (the transformations are affine) - m14 = F(0.0); - m24 = F(0.0); - m34 = F(0.0); - m44 = F(1.0); + m14 = T(0.0); + m24 = T(0.0); + m34 = T(0.0); + m44 = T(1.0); return *this; } @@ -1078,10 +1076,10 @@ namespace Nz template Matrix4& Matrix4::MakeZero() { - Set(F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0), - F(0.0), F(0.0), F(0.0), F(0.0)); + Set(T(0.0), T(0.0), T(0.0), T(0.0), + T(0.0), T(0.0), T(0.0), T(0.0), + T(0.0), T(0.0), T(0.0), T(0.0), + T(0.0), T(0.0), T(0.0), T(0.0)); return *this; } @@ -1130,10 +1128,10 @@ namespace Nz template Matrix4& Matrix4::Set(const Matrix4& matrix) { - Set(F(matrix[ 0]), F(matrix[ 1]), F(matrix[ 2]), F(matrix[ 3]), - F(matrix[ 4]), F(matrix[ 5]), F(matrix[ 6]), F(matrix[ 7]), - F(matrix[ 8]), F(matrix[ 9]), F(matrix[10]), F(matrix[11]), - F(matrix[12]), F(matrix[13]), F(matrix[14]), F(matrix[15])); + Set(T(matrix[ 0]), T(matrix[ 1]), T(matrix[ 2]), T(matrix[ 3]), + T(matrix[ 4]), T(matrix[ 5]), T(matrix[ 6]), T(matrix[ 7]), + T(matrix[ 8]), T(matrix[ 9]), T(matrix[10]), T(matrix[11]), + T(matrix[12]), T(matrix[13]), T(matrix[14]), T(matrix[15])); return *this; } @@ -1159,17 +1157,17 @@ namespace Nz T qy2 = qy * qy; T qz2 = qz * qz; - m11 = F(1.0) - F(2.0) * qy2 - F(2.0) * qz2; - m21 = F(2.0) * qx * qy - F(2.0) * qz * qw; - m31 = F(2.0) * qx * qz + F(2.0) * qy * qw; + m11 = T(1.0) - T(2.0) * qy2 - T(2.0) * qz2; + m21 = T(2.0) * qx * qy - T(2.0) * qz * qw; + m31 = T(2.0) * qx * qz + T(2.0) * qy * qw; - m12 = F(2.0) * qx * qy + F(2.0) * qz * qw; - m22 = F(1.0) - F(2.0) * qx2 - F(2.0) * qz2; - m32 = F(2.0) * qy * qz - F(2.0) * qx * qw; + m12 = T(2.0) * qx * qy + T(2.0) * qz * qw; + m22 = T(1.0) - T(2.0) * qx2 - T(2.0) * qz2; + m32 = T(2.0) * qy * qz - T(2.0) * qx * qw; - m13 = F(2.0) * qx * qz - F(2.0) * qy * qw; - m23 = F(2.0) * qy * qz + F(2.0) * qx * qw; - m33 = F(1.0) - F(2.0) * qx2 - F(2.0) * qy2; + m13 = T(2.0) * qx * qz - T(2.0) * qy * qw; + m23 = T(2.0) * qy * qz + T(2.0) * qx * qw; + m33 = T(1.0) - T(2.0) * qx2 - T(2.0) * qy2; return *this; } @@ -1218,13 +1216,12 @@ namespace Nz */ template - String Matrix4::ToString() const + std::string Matrix4::ToString() const { - StringStream ss; - return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n" - << " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n" - << " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n" - << " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')'; + std::ostringstream ss; + ss << *this; + + return ss.str(); } /*! @@ -1335,10 +1332,10 @@ namespace Nz #if NAZARA_MATH_SAFE if (x > 3 || y > 3) { - String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)"); + std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)"); NazaraError(error); - throw std::out_of_range(error.ToStdString()); + throw std::out_of_range(error); } #endif @@ -1359,10 +1356,10 @@ namespace Nz #if NAZARA_MATH_SAFE if (x > 3 || y > 3) { - String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)"); + std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)"); NazaraError(error); - throw std::out_of_range(error.ToStdString()); + throw std::out_of_range(error); } #endif @@ -1801,7 +1798,10 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Matrix4& matrix) { - return out << matrix.ToString(); + return out << "Matrix4(" << matrix.m11 << ", " << matrix.m12 << ", " << matrix.m13 << ", " << matrix.m14 << ",\n" + << " " << matrix.m21 << ", " << matrix.m22 << ", " << matrix.m23 << ", " << matrix.m24 << ",\n" + << " " << matrix.m31 << ", " << matrix.m32 << ", " << matrix.m33 << ", " << matrix.m34 << ",\n" + << " " << matrix.m41 << ", " << matrix.m42 << ", " << matrix.m43 << ", " << matrix.m44 << ')'; } /*! @@ -1818,6 +1818,4 @@ Nz::Matrix4 operator*(T scale, const Nz::Matrix4& matrix) return matrix * scale; } -#undef F - #include diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp index ffa15782c..4a73f1cb8 100644 --- a/include/Nazara/Math/OrientedBox.hpp +++ b/include/Nazara/Math/OrientedBox.hpp @@ -7,10 +7,11 @@ #ifndef NAZARA_ORIENTEDBOX_HPP #define NAZARA_ORIENTEDBOX_HPP -#include #include +#include #include #include +#include namespace Nz { @@ -29,6 +30,7 @@ namespace Nz ~OrientedBox() = default; const Vector3& GetCorner(BoxCorner corner) const; + const Vector3* GetCorners() const; bool IsValid() const; @@ -39,14 +41,11 @@ namespace Nz OrientedBox& Set(const Vector3& vec1, const Vector3& vec2); template OrientedBox& Set(const OrientedBox& orientedBox); - String ToString() const; + std::string ToString() const; void Update(const Matrix4& transformMatrix); void Update(const Vector3& transformMatrix); - operator Vector3* (); - operator const Vector3* () const; - Vector3& operator()(unsigned int i); Vector3 operator()(unsigned int i) const; diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index ee1eab23a..5eae2124f 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -3,15 +3,13 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include +#include #include ///DOC: Pour que les coins soient valides, la méthode Update doit être appelée -#define F(a) static_cast(a) - namespace Nz { /*! @@ -93,7 +91,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (corner > BoxCorner_Max) { - NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')'); + NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')'); static Vector3 dummy; return dummy; @@ -103,6 +101,12 @@ namespace Nz return m_corners[corner]; } + template + const Vector3* OrientedBox::GetCorners() const + { + return &m_corners[0]; + } + /*! * \brief Checks whether this oriented box is valid * \return true if the oriented box has a strictly positive width, height and depth @@ -205,18 +209,12 @@ namespace Nz */ template - String OrientedBox::ToString() const + std::string OrientedBox::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "OrientedBox(FLB: " << m_corners[BoxCorner_FarLeftBottom].ToString() << "\n" - << " FLT: " << m_corners[BoxCorner_FarLeftTop].ToString() << "\n" - << " FRB: " << m_corners[BoxCorner_FarRightBottom].ToString() << "\n" - << " FRT: " << m_corners[BoxCorner_FarRightTop].ToString() << "\n" - << " NLB: " << m_corners[BoxCorner_NearLeftBottom].ToString() << "\n" - << " NLT: " << m_corners[BoxCorner_NearLeftTop].ToString() << "\n" - << " NRB: " << m_corners[BoxCorner_NearRightBottom].ToString() << "\n" - << " NRT: " << m_corners[BoxCorner_NearRightTop].ToString() << ")\n"; + return ss.str(); } /*! @@ -245,32 +243,6 @@ namespace Nz m_corners[i] = localBox.GetCorner(static_cast(i)) + translation; } - /*! - * \brief Converts oriented box to pointer of Vector3 to its own corners - * \return A pointer to the own corners - * - * \remark Access to index greather than BoxCorner_Max is undefined behavior - */ - - template - OrientedBox::operator Vector3* () - { - return &m_corners[0]; - } - - /*! - * \brief Converts oriented box to pointer of Vector3 to its own corners - * \return A const pointer to the own corners - * - * \remark Access to index greather than BoxCorner_Max is undefined behavior - */ - - template - OrientedBox::operator const Vector3* () const - { - return &m_corners[0]; - } - /*! * \brief Gets the ith corner of the oriented box * \return A reference to this corner @@ -285,11 +257,11 @@ namespace Nz #if NAZARA_MATH_SAFE if (i > BoxCorner_Max) { - StringStream ss; + std::ostringstream ss; ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")"; - NazaraError(ss); - throw std::out_of_range(ss.ToString().ToStdString()); + NazaraError(ss.str()); + throw std::out_of_range(ss.str()); } #endif @@ -307,16 +279,16 @@ namespace Nz template Vector3 OrientedBox::operator()(unsigned int i) const { - #if NAZARA_MATH_SAFE +#if NAZARA_MATH_SAFE if (i > BoxCorner_Max) { - StringStream ss; + std::ostringstream ss; ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")"; - NazaraError(ss); - throw std::out_of_range(ss.ToString().ToStdString()); + NazaraError(ss.str()); + throw std::out_of_range(ss.str()); } - #endif +#endif return m_corners[i]; } @@ -465,9 +437,15 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox& orientedBox) { - return out << orientedBox.ToString(); + return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftBottom) << ",\n" + << " FLT: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftTop) << ",\n" + << " FRB: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightBottom) << ",\n" + << " FRT: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightTop) << ",\n" + << " NLB: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftBottom) << ",\n" + << " NLT: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftTop) << ",\n" + << " NRB: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightBottom) << ",\n" + << " NRT: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightTop) << ")\n"; } -#undef F - #include +#include "OrientedBox.hpp" diff --git a/include/Nazara/Math/Plane.hpp b/include/Nazara/Math/Plane.hpp index 24ddf7be5..c74495714 100644 --- a/include/Nazara/Math/Plane.hpp +++ b/include/Nazara/Math/Plane.hpp @@ -7,8 +7,8 @@ #ifndef NAZARA_PLANE_HPP #define NAZARA_PLANE_HPP -#include #include +#include namespace Nz { @@ -42,7 +42,7 @@ namespace Nz Plane& Set(const Vector3& point1, const Vector3& point2, const Vector3& point3); template Plane& Set(const Plane& plane); - String ToString() const; + std::string ToString() const; Plane& operator=(const Plane& other) = default; diff --git a/include/Nazara/Math/Plane.inl b/include/Nazara/Math/Plane.inl index 4a71f7f84..47bae6ee6 100644 --- a/include/Nazara/Math/Plane.inl +++ b/include/Nazara/Math/Plane.inl @@ -3,13 +3,11 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -148,7 +146,7 @@ namespace Nz template Plane& Plane::MakeXY() { - return Set(F(0.0), F(0.0), F(1.0), F(0.0)); + return Set(T(0.0), T(0.0), T(1.0), T(0.0)); } /*! @@ -161,7 +159,7 @@ namespace Nz template Plane& Plane::MakeXZ() { - return Set(F(0.0), F(1.0), F(0.0), F(0.0)); + return Set(T(0.0), T(1.0), T(0.0), T(0.0)); } /*! @@ -174,7 +172,7 @@ namespace Nz template Plane& Plane::MakeYZ() { - return Set(F(1.0), F(0.0), F(0.0), F(0.0)); + return Set(T(1.0), T(0.0), T(0.0), T(0.0)); } /*! @@ -282,7 +280,7 @@ namespace Nz Plane& Plane::Set(const Plane& plane) { normal.Set(plane.normal); - distance = F(plane.distance); + distance = T(plane.distance); return *this; } @@ -293,11 +291,12 @@ namespace Nz */ template - String Plane::ToString() const + std::string Plane::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Plane(Normal: " << normal.ToString() << "; Distance: " << distance << ')'; + return ss.str(); } /*! @@ -348,9 +347,9 @@ namespace Nz Plane Plane::Lerp(const Plane& from, const Plane& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Plane(); } #endif @@ -461,9 +460,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Plane& plane) { - return out << plane.ToString(); + return out << "Plane(Normal: " << plane.normal << "; Distance: " << plane.distance << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index e26149573..96af1dbfd 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -7,8 +7,8 @@ #ifndef NAZARA_QUATERNION_HPP #define NAZARA_QUATERNION_HPP -#include #include +#include namespace Nz { @@ -63,7 +63,7 @@ namespace Nz RadianAngle To2DAngle() const; EulerAngles ToEulerAngles() const; //Matrix3 ToRotationMatrix() const; - String ToString() const; + std::string ToString() const; Quaternion& operator=(const Quaternion& quat) = default; diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index 130604814..abba22e7c 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -4,17 +4,15 @@ #include #include -#include #include #include #include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -119,10 +117,10 @@ namespace Nz template Quaternion& Quaternion::ComputeW() { - T t = F(1.0) - SquaredMagnitude(); + T t = T(1.0) - SquaredMagnitude(); - if (t < F(0.0)) - w = F(0.0); + if (t < T(0.0)) + w = T(0.0); else w = -std::sqrt(t); @@ -230,9 +228,9 @@ namespace Nz Quaternion& Quaternion::Inverse() { T norm = SquaredMagnitude(); - if (norm > F(0.0)) + if (norm > T(0.0)) { - T invNorm = F(1.0) / std::sqrt(norm); + T invNorm = T(1.0) / std::sqrt(norm); w *= invNorm; x *= -invNorm; @@ -253,7 +251,7 @@ namespace Nz template Quaternion& Quaternion::MakeIdentity() { - return Set(F(1.0), F(0.0), F(0.0), F(0.0)); + return Set(T(1.0), T(0.0), T(0.0), T(0.0)); } /*! @@ -288,7 +286,7 @@ namespace Nz template Quaternion& Quaternion::MakeZero() { - return Set(F(0.0), F(0.0), F(0.0), F(0.0)); + return Set(T(0.0), T(0.0), T(0.0), T(0.0)); } /*! @@ -319,9 +317,9 @@ namespace Nz Quaternion& Quaternion::Normalize(T* length) { T norm = std::sqrt(SquaredMagnitude()); - if (norm > F(0.0)) + if (norm > T(0.0)) { - T invNorm = F(1.0) / norm; + T invNorm = T(1.0) / norm; w *= invNorm; x *= invNorm; y *= invNorm; @@ -399,7 +397,7 @@ namespace Nz angle = DegreeToRadian(angle); #endif - angle /= F(2.0); + angle /= T(2.0); Vector3 normalizedAxis = axis.GetNormal(); @@ -442,10 +440,10 @@ namespace Nz template Quaternion& Quaternion::Set(const Quaternion& quat) { - w = F(quat.w); - x = F(quat.x); - y = F(quat.y); - z = F(quat.z); + w = T(quat.w); + x = T(quat.x); + y = T(quat.y); + z = T(quat.z); return *this; } @@ -488,17 +486,17 @@ namespace Nz EulerAngles Quaternion::ToEulerAngles() const { T test = x * y + z * w; - if (test > F(0.499)) + if (test > T(0.499)) // singularity at north pole - return EulerAngles(F(0.0), FromRadians(F(2.0) * std::atan2(x, w)), FromDegrees(F(90.0))); + return EulerAngles(T(0.0), FromRadians(T(2.0) * std::atan2(x, w)), FromDegrees(T(90.0))); - if (test < F(-0.499)) + if (test < T(-0.499)) // singularity at south pole - return EulerAngles(F(0.0), FromRadians(F(-2.0) * std::atan2(x, w)), FromDegrees(F(-90.0))); + return EulerAngles(T(0.0), FromRadians(T(-2.0) * std::atan2(x, w)), FromDegrees(T(-90.0))); - return EulerAngles(FromRadians(std::atan2(F(2.0) * x * w - F(2.0) * y * z, F(1.0) - F(2.0) * x * x - F(2.0) * z * z)), - FromRadians(std::atan2(F(2.0) * y * w - F(2.0) * x * z, F(1.0) - F(2.0) * y * y - F(2.0) * z * z)), - FromRadians(std::asin(F(2.0) * test))); + return EulerAngles(FromRadians(std::atan2(T(2.0) * x * w - T(2.0) * y * z, T(1.0) - T(2.0) * x * x - T(2.0) * z * z)), + FromRadians(std::atan2(T(2.0) * y * w - T(2.0) * x * z, T(1.0) - T(2.0) * y * y - T(2.0) * z * z)), + FromRadians(std::asin(T(2.0) * test))); } /*! @@ -507,11 +505,12 @@ namespace Nz */ template - String Quaternion::ToString() const + std::string Quaternion::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')'; + return ss.str(); } /*! @@ -565,8 +564,8 @@ namespace Nz Vector3 quatVec(x, y, z); Vector3 uv = quatVec.CrossProduct(vec); Vector3 uuv = quatVec.CrossProduct(uv); - uv *= F(2.0) * w; - uuv *= F(2.0); + uv *= T(2.0) * w; + uuv *= T(2.0); return vec + uv + uuv; } @@ -715,9 +714,9 @@ namespace Nz Quaternion Quaternion::Lerp(const Quaternion& from, const Quaternion& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Zero(); } #endif @@ -784,9 +783,9 @@ namespace Nz Quaternion Quaternion::Slerp(const Quaternion& from, const Quaternion& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Zero(); } #endif @@ -794,7 +793,7 @@ namespace Nz Quaternion q; T cosOmega = from.DotProduct(to); - if (cosOmega < F(0.0)) + if (cosOmega < T(0.0)) { // We invert everything q.Set(-to.w, -to.x, -to.y, -to.z); @@ -804,21 +803,21 @@ namespace Nz q.Set(to); T k0, k1; - if (cosOmega > F(0.9999)) + if (cosOmega > T(0.9999)) { // Linear interpolation to avoid division by zero - k0 = F(1.0) - interpolation; + k0 = T(1.0) - interpolation; k1 = interpolation; } else { - T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega); + T sinOmega = std::sqrt(T(1.0) - cosOmega*cosOmega); T omega = std::atan2(sinOmega, cosOmega); // To avoid two divisions - sinOmega = F(1.0)/sinOmega; + sinOmega = T(1.0)/sinOmega; - k0 = std::sin((F(1.0) - interpolation) * omega) * sinOmega; + k0 = std::sin((T(1.0) - interpolation) * omega) * sinOmega; k1 = std::sin(interpolation*omega) * sinOmega; } @@ -905,9 +904,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat) { - return out << quat.ToString(); + return out << "Quaternion(" << quat.w << " | " << quat.x << ", " << quat.y << ", " << quat.z << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/Ray.hpp b/include/Nazara/Math/Ray.hpp index 8429e7dc8..0daf83e79 100644 --- a/include/Nazara/Math/Ray.hpp +++ b/include/Nazara/Math/Ray.hpp @@ -7,7 +7,6 @@ #ifndef NAZARA_RAY_HPP #define NAZARA_RAY_HPP -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace Nz { @@ -57,7 +57,7 @@ namespace Nz template Ray& Set(const Ray& ray); template Ray& Set(const Vector3& origin, const Vector3& direction); - String ToString() const; + std::string ToString() const; Vector3 operator*(T lambda) const; Ray& operator=(const Ray& other) = default; diff --git a/include/Nazara/Math/Ray.inl b/include/Nazara/Math/Ray.inl index 1f98a17ad..f0c19fca3 100644 --- a/include/Nazara/Math/Ray.inl +++ b/include/Nazara/Math/Ray.inl @@ -3,12 +3,10 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -166,7 +164,7 @@ namespace Nz case Extend_Infinite: { if (closestHit) - *closestHit = F(0.0); + *closestHit = T(0.0); if (furthestHit) *furthestHit = std::numeric_limits::infinity(); @@ -178,7 +176,7 @@ namespace Nz return false; } - NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')'); + NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')'); return false; } @@ -197,7 +195,7 @@ namespace Nz bool Ray::Intersect(const Box& box, T* closestHit, T* furthestHit) const { // http://www.gamedev.net/topic/429443-obb-ray-and-obb-plane-intersection/ - T tfirst = F(0.0); + T tfirst = T(0.0); T tlast = std::numeric_limits::infinity(); Vector3 boxMin = box.GetMinimum(); @@ -210,7 +208,7 @@ namespace Nz T max = boxMax[i]; T min = boxMin[i]; - if (NumberEquals(dir, F(0.0))) + if (NumberEquals(dir, T(0.0))) { if (ori < max && ori > min) continue; @@ -256,7 +254,7 @@ namespace Nz { // http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/ // Intersection method from Real-Time Rendering and Essential Mathematics for Games - T tMin = F(0.0); + T tMin = T(0.0); T tMax = std::numeric_limits::infinity(); Vector3 boxMin = box.GetMinimum(); @@ -270,7 +268,7 @@ namespace Nz T e = axis.DotProduct(delta); T f = direction.DotProduct(axis); - if (!NumberEquals(f, F(0.0))) + if (!NumberEquals(f, T(0.0))) { T t1 = (e + boxMin[i]) / f; // Intersection with the "left" plane T t2 = (e + boxMax[i]) / f; // Intersection with the "right" plane @@ -296,7 +294,7 @@ namespace Nz } else // Rare case : the ray is almost parallel to the planes, so they don't have any "intersection" - if (-e + boxMin[i] > F(0.0) || -e + boxMax[i] < F(0.0)) + if (-e + boxMin[i] > T(0.0) || -e + boxMax[i] < T(0.0)) return false; } @@ -334,7 +332,7 @@ namespace Nz Matrix4 matrix(width.x, height.x, depth.x, corner.x, width.y, height.y, depth.y, corner.y, width.z, height.z, depth.z, corner.z, - F(0.0), F(0.0), F(0.0), F(1.0)); + T(0.0), T(0.0), T(0.0), T(1.0)); matrix.InverseAffine(); @@ -361,11 +359,11 @@ namespace Nz bool Ray::Intersect(const Plane& plane, T* hit) const { T divisor = plane.normal.DotProduct(direction); - if (NumberEquals(divisor, F(0.0))) + if (NumberEquals(divisor, T(0.0))) return false; // Perpendicular T lambda = -(plane.normal.DotProduct(origin) - plane.distance) / divisor; // The plane is ax + by + cz = d - if (lambda < F(0.0)) + if (lambda < T(0.0)) return false; // The plane is 'behind' the ray. if (hit) @@ -391,7 +389,7 @@ namespace Nz Vector3 sphereRay = sphere.GetPosition() - origin; T length = sphereRay.DotProduct(direction); - if (length < F(0.0)) + if (length < T(0.0)) return false; // ray is perpendicular to the vector origin - center T squaredDistance = sphereRay.GetSquaredLength() - length * length; @@ -436,21 +434,21 @@ namespace Nz Vector3 P = Vector3::CrossProduct(direction, secondEdge); const T divisor = firstEdge.DotProduct(P); - if (NumberEquals(divisor, F(0.0))) + if (NumberEquals(divisor, T(0.0))) return false; // Ray lies in plane of triangle Vector3 directionToPoint = origin - firstPoint; T u = directionToPoint.DotProduct(P) / divisor; - if (u < F(0.0) || u > F(1.0)) + if (u < T(0.0) || u > T(1.0)) return 0; // The intersection lies outside of the triangle Vector3 Q = Vector3::CrossProduct(directionToPoint, firstEdge); T v = directionToPoint.DotProduct(Q) / divisor; - if (v < F(0.0) || u + v > F(1.0)) + if (v < T(0.0) || u + v > T(1.0)) return 0; // The intersection lies outside of the triangle T t = secondEdge.DotProduct(Q) / divisor; - if (t > F(0.0)) + if (t > T(0.0)) { if (hit) *hit = t; @@ -574,16 +572,16 @@ namespace Nz T det = termOne * termFour - termTwo * termTwo; #if NAZARA_MATH_SAFE - if (NumberEquals(det, F(0.0))) + if (NumberEquals(det, T(0.0))) { - String error("Planes are parallel"); + std::string error("Planes are parallel"); NazaraError(error); - throw std::domain_error(error.ToStdString()); + throw std::domain_error(error); } #endif - T invdet = F(1.0) / det; + T invdet = T(1.0) / det; T fc0 = (termFour * -planeOne.distance + termTwo * planeTwo.distance) * invdet; T fc1 = (termOne * -planeTwo.distance + termTwo * planeOne.distance) * invdet; @@ -634,11 +632,12 @@ namespace Nz */ template - String Ray::ToString() const + std::string Ray::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Ray(origin: " << origin.ToString() << ", direction: " << direction.ToString() << ")"; + return ss.str(); } /*! @@ -799,9 +798,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Ray& ray) { - return out << ray.ToString(); + return out << "Ray(origin: " << ray.origin << ", direction: " << ray.direction << ")"; } -#undef F - #include diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index 0934d2968..a3aabc4b2 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -7,9 +7,9 @@ #ifndef NAZARA_RECT_HPP #define NAZARA_RECT_HPP -#include #include #include +#include namespace Nz { @@ -59,7 +59,7 @@ namespace Nz Rect& Set(const Vector2& vec1, const Vector2& vec2); template Rect& Set(const Rect& rect); - String ToString() const; + std::string ToString() const; Rect& Translate(const Vector2& translation); diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 18411fbd9..f56aca63f 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -3,14 +3,12 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -224,7 +222,7 @@ namespace Nz template Vector2 Rect::GetCenter() const { - return GetPosition() + GetLengths() / F(2.0); + return GetPosition() + GetLengths() / T(2.0); } /*! @@ -254,7 +252,7 @@ namespace Nz return Vector2(x + width, y); } - NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')'); + NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')'); return Vector2(); } @@ -309,10 +307,10 @@ namespace Nz { Vector2 neg(GetPosition()); - if (normal.x < F(0.0)) + if (normal.x < T(0.0)) neg.x += width; - if (normal.y < F(0.0)) + if (normal.y < T(0.0)) neg.y += height; return neg; @@ -345,10 +343,10 @@ namespace Nz { Vector2 pos(GetPosition()); - if (normal.x > F(0.0)) + if (normal.x > T(0.0)) pos.x += width; - if (normal.y > F(0.0)) + if (normal.y > T(0.0)) pos.y += height; return pos; @@ -394,7 +392,7 @@ namespace Nz template bool Rect::IsValid() const { - return width > F(0.0) && height > F(0.0); + return width > T(0.0) && height > T(0.0); } /*! @@ -407,10 +405,10 @@ namespace Nz template Rect& Rect::MakeZero() { - x = F(0.0); - y = F(0.0); - width = F(0.0); - height = F(0.0); + x = T(0.0); + y = T(0.0); + width = T(0.0); + height = T(0.0); return *this; } @@ -428,8 +426,8 @@ namespace Nz template Rect& Rect::Set(T Width, T Height) { - x = F(0.0); - y = F(0.0); + x = T(0.0); + y = T(0.0); width = Width; height = Height; @@ -521,10 +519,10 @@ namespace Nz template Rect& Rect::Set(const Rect& rect) { - x = F(rect.x); - y = F(rect.y); - width = F(rect.width); - height = F(rect.height); + x = T(rect.x); + y = T(rect.y); + width = T(rect.width); + height = T(rect.height); return *this; } @@ -535,11 +533,12 @@ namespace Nz */ template - String Rect::ToString() const + std::string Rect::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Rect(" << x << ", " << y << ", " << width << ", " << height << ')'; + return ss.str(); } /*! @@ -753,9 +752,9 @@ namespace Nz Rect Rect::Lerp(const Rect& from, const Rect& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Zero(); } #endif @@ -847,9 +846,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Rect& rect) { - return out << rect.ToString(); + return out << "Rect(" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index f07eb8f4a..ed4d9f395 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -7,8 +7,8 @@ #ifndef NAZARA_SPHERE_HPP #define NAZARA_SPHERE_HPP -#include #include +#include namespace Nz { @@ -57,7 +57,7 @@ namespace Nz Sphere& Set(const T sphere[4]); template Sphere& Set(const Sphere& sphere); - String ToString() const; + std::string ToString() const; T& operator[](std::size_t i); T operator[](std::size_t i) const; diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 39f5a1433..52bb5ede4 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -3,15 +3,13 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include #include +#include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -306,7 +304,7 @@ namespace Nz template bool Sphere::IsValid() const { - return radius > F(0.0); + return radius > T(0.0); } /*! @@ -319,10 +317,10 @@ namespace Nz template Sphere& Sphere::MakeUnit() { - x = F(0.0); - y = F(0.0); - z = F(0.0); - radius = F(1.0); + x = T(0.0); + y = T(0.0); + z = T(0.0); + radius = T(1.0); return *this; } @@ -337,10 +335,10 @@ namespace Nz template Sphere& Sphere::MakeZero() { - x = F(0.0); - y = F(0.0); - z = F(0.0); - radius = F(0.0); + x = T(0.0); + y = T(0.0); + z = T(0.0); + radius = T(0.0); return *this; } @@ -390,7 +388,7 @@ namespace Nz { x = circle.x; y = circle.y; - z = F(0.0); + z = T(0.0); radius = circle.radius; return *this; @@ -426,10 +424,10 @@ namespace Nz template Sphere& Sphere::Set(const Sphere& sphere) { - x = F(sphere.x); - y = F(sphere.y); - z = F(sphere.z); - radius = F(sphere.radius); + x = T(sphere.x); + y = T(sphere.y); + z = T(sphere.z); + radius = T(sphere.radius); return *this; } @@ -440,11 +438,12 @@ namespace Nz */ template - String Sphere::ToString() const + std::string Sphere::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Sphere(" << x << ", " << y << ", " << z << "; " << radius << ')'; + return ss.str(); } /*! @@ -568,9 +567,9 @@ namespace Nz Sphere Sphere::Lerp(const Sphere& from, const Sphere& to, T interpolation) { #ifdef NAZARA_DEBUG - if (interpolation < F(0.0) || interpolation > F(1.0)) + if (interpolation < T(0.0) || interpolation > T(1.0)) { - NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')'); + NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')'); return Zero(); } #endif @@ -662,9 +661,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere) { - return out << sphere.ToString(); + return out << "Sphere(" << sphere.x << ", " << sphere.y << ", " << sphere.z << "; " << sphere.radius << ')'; } -#undef F - #include diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 75e86f709..bc0d6c9fb 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -7,8 +7,10 @@ #ifndef NAZARA_VECTOR2_HPP #define NAZARA_VECTOR2_HPP -#include +#include +#include #include +#include namespace Nz { @@ -61,7 +63,7 @@ namespace Nz T SquaredDistance(const Vector2& vec) const; - String ToString() const; + std::string ToString() const; T& operator[](std::size_t i); T operator[](std::size_t i) const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 22eb72566..1ecb7cebf 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -3,15 +3,13 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include +#include #include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -212,7 +210,7 @@ namespace Nz template Vector2& Vector2::MakeUnit() { - return Set(F(1.0), F(1.0)); + return Set(T(1.0), T(1.0)); } /*! @@ -225,7 +223,7 @@ namespace Nz template Vector2& Vector2::MakeUnitX() { - return Set(F(1.0), F(0.0)); + return Set(T(1.0), T(0.0)); } /*! @@ -238,7 +236,7 @@ namespace Nz template Vector2& Vector2::MakeUnitY() { - return Set(F(0.0), F(1.0)); + return Set(T(0.0), T(1.0)); } /*! @@ -251,7 +249,7 @@ namespace Nz template Vector2& Vector2::MakeZero() { - return Set(F(0.0), F(0.0)); + return Set(T(0.0), T(0.0)); } /*! @@ -311,9 +309,9 @@ namespace Nz Vector2& Vector2::Normalize(T* length) { T norm = GetLength(); - if (norm > F(0.0)) + if (norm > T(0.0)) { - T invNorm = F(1.0) / norm; + T invNorm = T(1.0) / norm; x *= invNorm; y *= invNorm; } @@ -383,8 +381,8 @@ namespace Nz template Vector2& Vector2::Set(const Vector2& vec) { - x = F(vec.x); - y = F(vec.y); + x = T(vec.x); + y = T(vec.y); return *this; } @@ -442,11 +440,12 @@ namespace Nz */ template - String Vector2::ToString() const + std::string Vector2::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Vector2(" << x << ", " << y << ')'; + return ss.str(); } /*! @@ -550,24 +549,11 @@ namespace Nz * \return A vector where components are the quotient of this vector and the other one * * \param vec The other vector to divide components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector2 Vector2::operator/(const Vector2& vec) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector2(x / vec.x, y / vec.y); } @@ -576,24 +562,11 @@ namespace Nz * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector2 Vector2::operator/(T scale) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector2(x / scale, y / scale); } @@ -666,24 +639,11 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the other one * * \param vec The other vector to multiply components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector2& Vector2::operator/=(const Vector2& vec) { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - x /= vec.x; y /= vec.y; @@ -695,24 +655,11 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector2& Vector2::operator/=(T scale) { - #if NAZARA_MATH_SAFE - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - x /= scale; y /= scale; @@ -990,7 +937,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Vector2& vec) { - return out << vec.ToString(); + return out << "Vector2(" << vec.x << ", " << vec.y << ')'; } /*! @@ -1011,24 +958,11 @@ Nz::Vector2 operator*(T scale, const Nz::Vector2& vec) * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with -* -* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined -* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Nz::Vector2 operator/(T scale, const Nz::Vector2& vec) { - #if NAZARA_MATH_SAFE - if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0))) - { - Nz::String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Nz::Vector2(scale / vec.x, scale / vec.y); } @@ -1054,7 +988,5 @@ namespace std } }; } - -#undef F #include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 4fd965484..9f02cffd7 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -7,8 +7,10 @@ #ifndef NAZARA_VECTOR3_HPP #define NAZARA_VECTOR3_HPP -#include +#include +#include #include +#include namespace Nz { @@ -72,7 +74,7 @@ namespace Nz T SquaredDistance(const Vector3& vec) const; - String ToString() const; + std::string ToString() const; T& operator[](std::size_t i); T operator[](std::size_t i) const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index f9585d91e..5c73a33d0 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -3,15 +3,13 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include #include +#include #include #include -#define F(a) static_cast(a) - namespace Nz { /*! @@ -126,17 +124,17 @@ namespace Nz T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength()); #if NAZARA_MATH_SAFE - if (NumberEquals(divisor, F(0.0))) + if (NumberEquals(divisor, T(0.0))) { - String error("Division by zero"); + std::string error("Division by zero"); NazaraError(error); - throw std::domain_error(error.ToStdString()); + throw std::domain_error(std::move(error)); } #endif T alpha = DotProduct(vec) / divisor; - return FromRadians(std::acos(Clamp(alpha, F(-1.0), F(1.0)))); + return FromRadians(std::acos(Clamp(alpha, T(-1.0), T(1.0)))); } /*! @@ -244,7 +242,7 @@ namespace Nz template Vector3& Vector3::MakeBackward() { - return Set(F(0.0), F(0.0), F(1.0)); + return Set(T(0.0), T(0.0), T(1.0)); } /*! @@ -256,7 +254,7 @@ namespace Nz template Vector3& Vector3::MakeDown() { - return Set(F(0.0), F(-1.0), F(0.0)); + return Set(T(0.0), T(-1.0), T(0.0)); } /*! @@ -268,7 +266,7 @@ namespace Nz template Vector3& Vector3::MakeForward() { - return Set(F(0.0), F(0.0), F(-1.0)); + return Set(T(0.0), T(0.0), T(-1.0)); } /*! @@ -280,7 +278,7 @@ namespace Nz template Vector3& Vector3::MakeLeft() { - return Set(F(-1.0), F(0.0), F(0.0)); + return Set(T(-1.0), T(0.0), T(0.0)); } /*! @@ -292,7 +290,7 @@ namespace Nz template Vector3& Vector3::MakeRight() { - return Set(F(1.0), F(0.0), F(0.0)); + return Set(T(1.0), T(0.0), T(0.0)); } /*! @@ -304,7 +302,7 @@ namespace Nz template Vector3& Vector3::MakeUnit() { - return Set(F(1.0), F(1.0), F(1.0)); + return Set(T(1.0), T(1.0), T(1.0)); } /*! @@ -316,7 +314,7 @@ namespace Nz template Vector3& Vector3::MakeUnitX() { - return Set(F(1.0), F(0.0), F(0.0)); + return Set(T(1.0), T(0.0), T(0.0)); } /*! @@ -328,7 +326,7 @@ namespace Nz template Vector3& Vector3::MakeUnitY() { - return Set(F(0.0), F(1.0), F(0.0)); + return Set(T(0.0), T(1.0), T(0.0)); } /*! @@ -340,7 +338,7 @@ namespace Nz template Vector3& Vector3::MakeUnitZ() { - return Set(F(0.0), F(0.0), F(1.0)); + return Set(T(0.0), T(0.0), T(1.0)); } /*! @@ -352,7 +350,7 @@ namespace Nz template Vector3& Vector3::MakeUp() { - return Set(F(0.0), F(1.0), F(0.0)); + return Set(T(0.0), T(1.0), T(0.0)); } /*! @@ -364,7 +362,7 @@ namespace Nz template Vector3& Vector3::MakeZero() { - return Set(F(0.0), F(0.0), F(0.0)); + return Set(T(0.0), T(0.0), T(0.0)); } /*! @@ -427,9 +425,9 @@ namespace Nz Vector3& Vector3::Normalize(T* length) { T norm = GetLength(); - if (norm > F(0.0)) + if (norm > T(0.0)) { - T invNorm = F(1.0) / norm; + T invNorm = T(1.0) / norm; x *= invNorm; y *= invNorm; z *= invNorm; @@ -533,9 +531,9 @@ namespace Nz template Vector3& Vector3::Set(const Vector3& vec) { - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); + x = T(vec.x); + y = T(vec.y); + z = T(vec.z); return *this; } @@ -575,11 +573,12 @@ namespace Nz * \return A string representation of the object: "Vector3(x, y, z)" */ template - String Vector3::ToString() const + std::string Vector3::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Vector3(" << x << ", " << y << ", " << z <<')'; + return ss.str(); } /*! @@ -677,23 +676,10 @@ namespace Nz * \return A vector where components are the quotient of this vector and the other one * * \param vec The other vector to divide components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector3 Vector3::operator/(const Vector3& vec) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector3(x / vec.x, y / vec.y, z / vec.z); } @@ -702,23 +688,10 @@ namespace Nz * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector3 Vector3::operator/(T scale) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector3(x / scale, y / scale, z / scale); } @@ -791,21 +764,10 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the other one * * \param vec The other vector to multiply components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector3& Vector3::operator/=(const Vector3& vec) { - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - x /= vec.x; y /= vec.y; z /= vec.z; @@ -818,21 +780,10 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector3& Vector3::operator/=(T scale) { - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - x /= scale; y /= scale; z /= scale; @@ -1253,7 +1204,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Vector3& vec) { - return out << vec.ToString(); + return out << "Vector3(" << vec.x << ", " << vec.y << ", " << vec.z << ')'; } /*! @@ -1274,24 +1225,11 @@ Nz::Vector3 operator*(T scale, const Nz::Vector3& vec) * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with -* -* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined -* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Nz::Vector3 operator/(T scale, const Nz::Vector3& vec) { - #if NAZARA_MATH_SAFE - if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)) || Nz::NumberEquals(vec.z, F(0.0))) - { - Nz::String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Nz::Vector3(scale / vec.x, scale / vec.y, scale / vec.z); } @@ -1320,6 +1258,4 @@ namespace std }; } -#undef F - #include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 5c5c9721f..bae99933b 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -7,8 +7,10 @@ #ifndef NAZARA_VECTOR4_HPP #define NAZARA_VECTOR4_HPP -#include +#include +#include #include +#include namespace Nz { @@ -59,7 +61,7 @@ namespace Nz Vector4& Set(const Vector3& vec, T W = 1.0); template Vector4& Set(const Vector4& vec); - String ToString() const; + std::string ToString() const; T& operator[](std::size_t i); T operator[](std::size_t i) const; diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index dfc39aafe..03fa1b0c1 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -3,16 +3,14 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include #include #include +#include #include #include ///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D -#define F(a) static_cast(a) - namespace Nz { @@ -188,7 +186,7 @@ namespace Nz template Vector4& Vector4::MakeUnitX() { - return Set(F(1.0), F(0.0), F(0.0), F(1.0)); + return Set(T(1.0), T(0.0), T(0.0), T(1.0)); } /*! @@ -201,7 +199,7 @@ namespace Nz template Vector4& Vector4::MakeUnitY() { - return Set(F(0.0), F(1.0), F(0.0), F(1.0)); + return Set(T(0.0), T(1.0), T(0.0), T(1.0)); } /*! @@ -214,7 +212,7 @@ namespace Nz template Vector4& Vector4::MakeUnitZ() { - return Set(F(0.0), F(0.0), F(1.0), F(1.0)); + return Set(T(0.0), T(0.0), T(1.0), T(1.0)); } /*! @@ -227,7 +225,7 @@ namespace Nz template Vector4& Vector4::MakeZero() { - return Set(F(0.0), F(0.0), F(0.0), F(1.0)); + return Set(T(0.0), T(0.0), T(0.0), T(1.0)); } /*! @@ -296,7 +294,7 @@ namespace Nz template Vector4& Vector4::Normalize(T* length) { - T invLength = F(1.0)/w; + T invLength = T(1.0)/w; x *= invLength; // Warning, change this logic will break Frustum::Extract y *= invLength; z *= invLength; @@ -304,7 +302,7 @@ namespace Nz if (length) *length = w; - w = F(1.0); + w = T(1.0); return *this; } @@ -472,10 +470,10 @@ namespace Nz template Vector4& Vector4::Set(const Vector4& vec) { - x = F(vec.x); - y = F(vec.y); - z = F(vec.z); - w = F(vec.w); + x = T(vec.x); + y = T(vec.y); + z = T(vec.z); + w = T(vec.w); return *this; } @@ -486,11 +484,12 @@ namespace Nz */ template - String Vector4::ToString() const + std::string Vector4::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << *this; - return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')'; + return ss.str(); } /*! @@ -594,24 +593,11 @@ namespace Nz * \return A vector where components are the quotient of this vector and the other one * * \param vec The other vector to divide components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector4 Vector4::operator/(const Vector4& vec) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w); } @@ -620,24 +606,11 @@ namespace Nz * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector4 Vector4::operator/(T scale) const { - #if NAZARA_MATH_SAFE - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Vector4(x / scale, y / scale, z / scale, w / scale); } @@ -718,24 +691,11 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the other one * * \param vec The other vector to multiply components with - * - * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ template Vector4& Vector4::operator/=(const Vector4& vec) { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - x /= vec.x; y /= vec.y; z /= vec.z; @@ -749,24 +709,11 @@ namespace Nz * \return A reference to this vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with - * - * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined - * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Vector4& Vector4::operator/=(T scale) { - #if NAZARA_MATH_SAFE - if (NumberEquals(scale, F(0.0))) - { - String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - x /= scale; y /= scale; z /= scale; @@ -1062,7 +1009,7 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Nz::Vector4& vec) { - return out << vec.ToString(); + return out << "Vector4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')'; } /*! @@ -1084,24 +1031,11 @@ Nz::Vector4 operator*(T scale, const Nz::Vector4& vec) * \return A vector where components are the quotient of this vector and the scalar * * \param scale The scalar to divide components with -* -* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined -* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ template Nz::Vector4 operator/(T scale, const Nz::Vector4& vec) { - #if NAZARA_MATH_SAFE - if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0))) - { - Nz::String error("Division by zero"); - - NazaraError(error); - throw std::domain_error(error.ToStdString()); - } - #endif - return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); } @@ -1130,6 +1064,4 @@ namespace std }; } -#undef F - #include diff --git a/include/Nazara/Network/IpAddress.hpp b/include/Nazara/Network/IpAddress.hpp index f0ac6652d..0974b4027 100644 --- a/include/Nazara/Network/IpAddress.hpp +++ b/include/Nazara/Network/IpAddress.hpp @@ -8,11 +8,12 @@ #define NAZARA_IPADDRESS_HPP #include -#include #include #include #include #include +#include +#include namespace Nz { @@ -30,12 +31,13 @@ namespace Nz inline IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port = 0); inline IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port = 0); inline explicit IpAddress(const char* address); - inline explicit IpAddress(const String& address); + inline explicit IpAddress(const std::string& address); IpAddress(const IpAddress&) = default; IpAddress(IpAddress&&) noexcept = default; ~IpAddress() = default; bool BuildFromAddress(const char* address); + inline bool BuildFromAddress(const std::string& address); inline UInt16 GetPort() const; inline NetProtocol GetProtocol() const; diff --git a/include/Nazara/Network/IpAddress.inl b/include/Nazara/Network/IpAddress.inl index 46e831eb3..ee31cd405 100644 --- a/include/Nazara/Network/IpAddress.inl +++ b/include/Nazara/Network/IpAddress.inl @@ -78,7 +78,8 @@ namespace Nz * \param address Hostname or textual IP address */ - inline IpAddress::IpAddress(const char* address) + inline IpAddress::IpAddress(const char* address) : + IpAddress() { BuildFromAddress(address); } @@ -88,17 +89,21 @@ namespace Nz * * \param address Hostname or textual IP address */ - - inline IpAddress::IpAddress(const String& address) + inline IpAddress::IpAddress(const std::string& address) : + IpAddress() { - BuildFromAddress(address.GetConstBuffer()); + BuildFromAddress(address); + } + + inline bool IpAddress::BuildFromAddress(const std::string& address) + { + return BuildFromAddress(address.c_str()); } /*! * \brief Gets the port * \return Port attached to the IP address */ - inline UInt16 IpAddress::GetPort() const { return m_port; diff --git a/include/Nazara/Network/RUdpConnection.inl b/include/Nazara/Network/RUdpConnection.inl index 1441572b8..d1b1e0705 100644 --- a/include/Nazara/Network/RUdpConnection.inl +++ b/include/Nazara/Network/RUdpConnection.inl @@ -191,7 +191,7 @@ namespace Nz return false; } - NazaraError("PacketReliability not handled (0x" + String::Number(reliability, 16) + ')'); + NazaraError("PacketReliability not handled (0x" + NumberToString(reliability, 16) + ')'); return false; } diff --git a/include/Nazara/OpenGLRenderer/Utils.hpp b/include/Nazara/OpenGLRenderer/Utils.hpp index 71c23106c..81c1eebe9 100644 --- a/include/Nazara/OpenGLRenderer/Utils.hpp +++ b/include/Nazara/OpenGLRenderer/Utils.hpp @@ -8,7 +8,6 @@ #define NAZARA_UTILS_OPENGL_HPP #include -#include #include #include #include diff --git a/include/Nazara/OpenGLRenderer/Utils.inl b/include/Nazara/OpenGLRenderer/Utils.inl index 61f446590..bd44b5e13 100644 --- a/include/Nazara/OpenGLRenderer/Utils.inl +++ b/include/Nazara/OpenGLRenderer/Utils.inl @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace Nz @@ -20,7 +20,7 @@ namespace Nz default: break; } - NazaraError("Unhandled PixelFormat 0x" + String::Number(UnderlyingCast(pixelFormat), 16)); + NazaraError("Unhandled PixelFormat 0x" + NumberToString(UnderlyingCast(pixelFormat), 16)); return {}; } @@ -40,7 +40,7 @@ namespace Nz case BlendFunc_Zero: return GL_ZERO; } - NazaraError("Unhandled BlendFunc 0x" + String::Number(UnderlyingCast(blendFunc), 16)); + NazaraError("Unhandled BlendFunc 0x" + NumberToString(UnderlyingCast(blendFunc), 16)); return {}; } @@ -56,7 +56,7 @@ namespace Nz case FaceSide_FrontAndBack: return GL_FRONT_AND_BACK; } - NazaraError("Unhandled FaceSide 0x" + String::Number(UnderlyingCast(filter), 16)); + NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(filter), 16)); return {}; } @@ -74,7 +74,7 @@ namespace Nz case RendererComparison_NotEqual: return GL_NOTEQUAL; } - NazaraError("Unhandled RendererComparison 0x" + String::Number(UnderlyingCast(comparison), 16)); + NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16)); return {}; } @@ -86,7 +86,7 @@ namespace Nz case SamplerFilter::SamplerFilter_Nearest: return GL_NEAREST; } - NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(filter), 16)); + NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(filter), 16)); return {}; } @@ -102,7 +102,7 @@ namespace Nz case SamplerMipmapMode_Nearest: return GL_LINEAR_MIPMAP_NEAREST; } - NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(mipmapFilter), 16)); + NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16)); return {}; } @@ -114,12 +114,12 @@ namespace Nz case SamplerMipmapMode_Nearest: return GL_NEAREST_MIPMAP_NEAREST; } - NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(mipmapFilter), 16)); + NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16)); return {}; } } - NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(minFilter), 16)); + NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(minFilter), 16)); return {}; } @@ -132,7 +132,7 @@ namespace Nz case SamplerWrap::SamplerWrap_Repeat: return GL_REPEAT; } - NazaraError("Unhandled SamplerWrap 0x" + String::Number(UnderlyingCast(wrapMode), 16)); + NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(wrapMode), 16)); return {}; } @@ -144,7 +144,7 @@ namespace Nz case ShaderStageType::Vertex: return GL_VERTEX_SHADER; } - NazaraError("Unhandled ShaderStageType 0x" + String::Number(UnderlyingCast(stageType), 16)); + NazaraError("Unhandled ShaderStageType 0x" + NumberToString(UnderlyingCast(stageType), 16)); return {}; } @@ -162,7 +162,7 @@ namespace Nz case StencilOperation_Zero: return GL_ZERO; } - NazaraError("Unhandled StencilOperation 0x" + String::Number(UnderlyingCast(stencilOp), 16)); + NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16)); return {}; } @@ -180,7 +180,7 @@ namespace Nz case GL::BufferTarget::Uniform: return GL_UNIFORM_BUFFER; } - NazaraError("Unhandled GL::BufferTarget 0x" + String::Number(UnderlyingCast(bufferTarget), 16)); + NazaraError("Unhandled GL::BufferTarget 0x" + NumberToString(UnderlyingCast(bufferTarget), 16)); return {}; } @@ -194,7 +194,7 @@ namespace Nz case GL::TextureTarget::Target3D: return GL_TEXTURE_3D; } - NazaraError("Unhandled GL::TextureTarget 0x" + String::Number(UnderlyingCast(textureTarget), 16)); + NazaraError("Unhandled GL::TextureTarget 0x" + NumberToString(UnderlyingCast(textureTarget), 16)); return {}; } } diff --git a/include/Nazara/Physics3D/PhysWorld3D.hpp b/include/Nazara/Physics3D/PhysWorld3D.hpp index 190b37aa4..76b46803f 100644 --- a/include/Nazara/Physics3D/PhysWorld3D.hpp +++ b/include/Nazara/Physics3D/PhysWorld3D.hpp @@ -9,10 +9,10 @@ #include #include -#include #include #include #include +#include #include class NewtonBody; @@ -36,13 +36,13 @@ namespace Nz PhysWorld3D(PhysWorld3D&&) noexcept = default; ~PhysWorld3D(); - int CreateMaterial(String name = String()); + int CreateMaterial(std::string name = {}); void ForEachBodyInAABB(const Boxf& box, const BodyIterator& iterator); Vector3f GetGravity() const; NewtonWorld* GetHandle() const; - int GetMaterial(const String& name); + int GetMaterial(const std::string& name); std::size_t GetMaxStepCount() const; float GetStepSize() const; unsigned int GetThreadCount() const; @@ -75,7 +75,7 @@ namespace Nz static void ProcessContact(const NewtonJoint* const contact, float timestep, int threadIndex); std::unordered_map> m_callbacks; - std::unordered_map m_materialIds; + std::unordered_map m_materialIds; std::size_t m_maxStepCount; MovablePtr m_world; Vector3f m_gravity; diff --git a/include/Nazara/Physics3D/RigidBody3D.hpp b/include/Nazara/Physics3D/RigidBody3D.hpp index fb47b5888..6b9bce67c 100644 --- a/include/Nazara/Physics3D/RigidBody3D.hpp +++ b/include/Nazara/Physics3D/RigidBody3D.hpp @@ -67,7 +67,7 @@ namespace Nz void SetLinearVelocity(const Vector3f& velocity); void SetMass(float mass); void SetMassCenter(const Vector3f& center); - void SetMaterial(const String& materialName); + void SetMaterial(const std::string& materialName); void SetMaterial(int materialIndex); void SetPosition(const Vector3f& position); void SetRotation(const Quaternionf& rotation); diff --git a/include/Nazara/Platform/Joystick.hpp b/include/Nazara/Platform/Joystick.hpp index 45cb5d10f..33ff64872 100644 --- a/include/Nazara/Platform/Joystick.hpp +++ b/include/Nazara/Platform/Joystick.hpp @@ -8,7 +8,7 @@ #define NAZARA_JOYSTICK_HPP #include -#include +#include namespace Nz { diff --git a/include/Nazara/Platform/Keyboard.hpp b/include/Nazara/Platform/Keyboard.hpp index 5c84a45c9..87619807d 100644 --- a/include/Nazara/Platform/Keyboard.hpp +++ b/include/Nazara/Platform/Keyboard.hpp @@ -10,8 +10,8 @@ #define NAZARA_KEYBOARD_HPP #include -#include #include +#include namespace Nz { @@ -319,8 +319,8 @@ namespace Nz Keyboard() = delete; ~Keyboard() = delete; - static String GetKeyName(Scancode scancode); - static String GetKeyName(VKey key); + static std::string GetKeyName(Scancode scancode); + static std::string GetKeyName(VKey key); static bool IsKeyPressed(Scancode scancode); static bool IsKeyPressed(VKey key); static void StartTextInput(); diff --git a/include/Nazara/Platform/Window.hpp b/include/Nazara/Platform/Window.hpp index 192a56433..eebbabe0c 100644 --- a/include/Nazara/Platform/Window.hpp +++ b/include/Nazara/Platform/Window.hpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -38,7 +37,7 @@ namespace Nz public: Window(); - inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default); + inline Window(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default); inline explicit Window(void* handle); Window(const Window&) = delete; Window(Window&& window); @@ -46,7 +45,7 @@ namespace Nz inline void Close(); - bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default); + bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default); bool Create(void* handle); void Destroy(); @@ -66,7 +65,7 @@ namespace Nz Vector2ui GetSize() const; WindowStyleFlags GetStyle() const; WindowHandle GetSystemHandle() const; - String GetTitle() const; + std::string GetTitle() const; bool HasFocus() const; @@ -97,7 +96,7 @@ namespace Nz void SetSize(const Vector2i& size); void SetSize(unsigned int width, unsigned int height); void SetStayOnTop(bool stayOnTop); - void SetTitle(const String& title); + void SetTitle(const std::string& title); void SetVisible(bool visible); NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system") diff --git a/include/Nazara/Platform/Window.inl b/include/Nazara/Platform/Window.inl index cdfbc85c8..d6ab61579 100644 --- a/include/Nazara/Platform/Window.inl +++ b/include/Nazara/Platform/Window.inl @@ -12,7 +12,7 @@ namespace Nz * \class Nz::Window */ - inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) : + inline Window::Window(VideoMode mode, const std::string& title, WindowStyleFlags style) : Window() { ErrorFlags flags(ErrorFlag_ThrowException, true); diff --git a/include/Nazara/Renderer/RenderDeviceInfo.hpp b/include/Nazara/Renderer/RenderDeviceInfo.hpp index fd4924253..5e6853ca0 100644 --- a/include/Nazara/Renderer/RenderDeviceInfo.hpp +++ b/include/Nazara/Renderer/RenderDeviceInfo.hpp @@ -8,7 +8,6 @@ #define NAZARA_RENDERDEVICE_HPP #include -#include #include namespace Nz @@ -16,7 +15,7 @@ namespace Nz struct RenderDeviceInfo { RenderDeviceType type; - String name; + std::string name; }; } diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index 6adcf3d66..d02e37323 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -25,11 +25,11 @@ namespace Nz { public: inline RenderWindow(); - inline RenderWindow(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters()); + inline RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters()); inline explicit RenderWindow(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); inline ~RenderWindow(); - inline bool Create(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters()); + inline bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters()); inline bool Create(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); void Display(); diff --git a/include/Nazara/Renderer/RenderWindow.inl b/include/Nazara/Renderer/RenderWindow.inl index 95b61dd8b..9179ef577 100644 --- a/include/Nazara/Renderer/RenderWindow.inl +++ b/include/Nazara/Renderer/RenderWindow.inl @@ -12,7 +12,7 @@ namespace Nz { } - inline RenderWindow::RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters) : + inline RenderWindow::RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) : RenderWindow() { ErrorFlags errFlags(ErrorFlag_ThrowException, true); @@ -32,7 +32,7 @@ namespace Nz Destroy(); } - inline bool RenderWindow::Create(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters) + inline bool RenderWindow::Create(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) { m_parameters = parameters; diff --git a/include/Nazara/Shader/ShaderExpressionType.inl b/include/Nazara/Shader/ShaderExpressionType.inl index 15f602a5b..8f72fb376 100644 --- a/include/Nazara/Shader/ShaderExpressionType.inl +++ b/include/Nazara/Shader/ShaderExpressionType.inl @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -17,7 +18,7 @@ namespace Nz else if constexpr (std::is_same_v) return false; else - static_assert(AlwaysFalse::value, "non-exhaustive visitor"); + static_assert(AlwaysFalse::value, "non-exhaustive visitor"); }, type); } @@ -98,7 +99,7 @@ namespace Nz else if constexpr (std::is_same_v) return true; else - static_assert(AlwaysFalse::value, "non-exhaustive visitor"); + static_assert(AlwaysFalse::value, "non-exhaustive visitor"); }, type); } diff --git a/include/Nazara/Utility/Animation.hpp b/include/Nazara/Utility/Animation.hpp index db4d4488e..0bb90f548 100644 --- a/include/Nazara/Utility/Animation.hpp +++ b/include/Nazara/Utility/Animation.hpp @@ -17,9 +17,9 @@ #include #include #include -#include #include #include +#include namespace Nz { @@ -67,23 +67,23 @@ namespace Nz std::size_t GetFrameCount() const; std::size_t GetJointCount() const; - Sequence* GetSequence(const String& sequenceName); + Sequence* GetSequence(const std::string& sequenceName); Sequence* GetSequence(std::size_t index); - const Sequence* GetSequence(const String& sequenceName) const; + const Sequence* GetSequence(const std::string& sequenceName) const; const Sequence* GetSequence(std::size_t index) const; std::size_t GetSequenceCount() const; - std::size_t GetSequenceIndex(const String& sequenceName) const; + std::size_t GetSequenceIndex(const std::string& sequenceName) const; SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0); const SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0) const; AnimationType GetType() const; - bool HasSequence(const String& sequenceName) const; + bool HasSequence(const std::string& sequenceName) const; bool HasSequence(std::size_t index = 0) const; bool IsLoopPointInterpolationEnabled() const; bool IsValid() const; - void RemoveSequence(const String& sequenceName); + void RemoveSequence(const std::string& sequenceName); void RemoveSequence(std::size_t index); template static AnimationRef New(Args&&... args); diff --git a/include/Nazara/Utility/Font.hpp b/include/Nazara/Utility/Font.hpp index 9ba2f5a6e..534afb016 100644 --- a/include/Nazara/Utility/Font.hpp +++ b/include/Nazara/Utility/Font.hpp @@ -64,18 +64,18 @@ namespace Nz const std::shared_ptr& GetAtlas() const; std::size_t GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style, float outlineThickness) const; std::size_t GetCachedGlyphCount() const; - String GetFamilyName() const; + std::string GetFamilyName() const; int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const; const Glyph& GetGlyph(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const; unsigned int GetGlyphBorder() const; unsigned int GetMinimumStepSize() const; const SizeInfo& GetSizeInfo(unsigned int characterSize) const; - String GetStyleName() const; + std::string GetStyleName() const; bool IsValid() const; bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const; - bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const String& characterSet) const; + bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const std::string& characterSet) const; void SetAtlas(const std::shared_ptr& atlas); void SetGlyphBorder(unsigned int borderSize); diff --git a/include/Nazara/Utility/FontData.hpp b/include/Nazara/Utility/FontData.hpp index 35039da2c..3f8c539a7 100644 --- a/include/Nazara/Utility/FontData.hpp +++ b/include/Nazara/Utility/FontData.hpp @@ -8,9 +8,9 @@ #define NAZARA_FONTDATA_HPP #include -#include #include #include +#include namespace Nz { @@ -24,8 +24,8 @@ namespace Nz virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, float outlineThickness, FontGlyph* dst) = 0; - virtual String GetFamilyName() const = 0; - virtual String GetStyleName() const = 0; + virtual std::string GetFamilyName() const = 0; + virtual std::string GetStyleName() const = 0; virtual bool HasKerning() const = 0; diff --git a/include/Nazara/Utility/Formats/MD5AnimParser.hpp b/include/Nazara/Utility/Formats/MD5AnimParser.hpp index e1915e6ad..bb013429d 100644 --- a/include/Nazara/Utility/Formats/MD5AnimParser.hpp +++ b/include/Nazara/Utility/Formats/MD5AnimParser.hpp @@ -35,7 +35,7 @@ namespace Nz { Int32 parent; Quaternionf bindOrient; - String name; + std::string name; Vector3f bindPos; UInt32 flags; UInt32 index; @@ -57,12 +57,12 @@ namespace Nz private: bool Advance(bool required = true); - void Error(const String& message); + void Error(const std::string& message); bool ParseBaseframe(); bool ParseBounds(); bool ParseFrame(); bool ParseHierarchy(); - void Warning(const String& message); + void Warning(const std::string& message); void UnrecognizedLine(bool error = false); std::vector m_animatedComponents; @@ -70,7 +70,7 @@ namespace Nz std::vector m_joints; Stream& m_stream; StreamOptionFlags m_streamFlags; - String m_currentLine; + std::string m_currentLine; bool m_keepLastLine; unsigned int m_frameIndex; unsigned int m_frameRate; diff --git a/include/Nazara/Utility/Formats/MD5MeshParser.hpp b/include/Nazara/Utility/Formats/MD5MeshParser.hpp index 0d1e5641d..ca993c70e 100644 --- a/include/Nazara/Utility/Formats/MD5MeshParser.hpp +++ b/include/Nazara/Utility/Formats/MD5MeshParser.hpp @@ -8,11 +8,11 @@ #define NAZARA_FORMATS_MD5MESHPARSER_HPP #include -#include #include #include #include #include +#include #include namespace Nz @@ -22,9 +22,9 @@ namespace Nz public: struct Joint { + std::string name; Int32 parent; Quaternionf bindOrient; - String name; Vector3f bindPos; }; diff --git a/include/Nazara/Utility/Formats/MTLParser.hpp b/include/Nazara/Utility/Formats/MTLParser.hpp index cd56a2693..c22b90300 100644 --- a/include/Nazara/Utility/Formats/MTLParser.hpp +++ b/include/Nazara/Utility/Formats/MTLParser.hpp @@ -68,7 +68,7 @@ namespace Nz std::unordered_map m_materials; mutable Stream* m_currentStream; std::string m_currentLine; - mutable StringStream m_outputStream; + mutable std::ostringstream m_outputStream; bool m_keepLastLine; unsigned int m_lineCount; }; diff --git a/include/Nazara/Utility/Formats/MTLParser.inl b/include/Nazara/Utility/Formats/MTLParser.inl index 03e4b2c35..728af9923 100644 --- a/include/Nazara/Utility/Formats/MTLParser.inl +++ b/include/Nazara/Utility/Formats/MTLParser.inl @@ -35,7 +35,7 @@ namespace Nz void MTLParser::Emit(const T& text) const { m_outputStream << text; - if (m_outputStream.GetBufferSize() > 1024 * 1024) + if (m_outputStream.rdbuf()->str().size() > 1024 * 1024) Flush(); } @@ -58,8 +58,8 @@ namespace Nz inline void MTLParser::Flush() const { - m_currentStream->Write(m_outputStream); - m_outputStream.Clear(); + m_currentStream->Write(std::move(m_outputStream).str()); + m_outputStream.str({}); } inline void MTLParser::Warning(const std::string& message) diff --git a/include/Nazara/Utility/Formats/OBJParser.hpp b/include/Nazara/Utility/Formats/OBJParser.hpp index de0dcf1cb..a41217eec 100644 --- a/include/Nazara/Utility/Formats/OBJParser.hpp +++ b/include/Nazara/Utility/Formats/OBJParser.hpp @@ -94,7 +94,7 @@ namespace Nz mutable Stream* m_currentStream; std::string m_currentLine; std::filesystem::path m_mtlLib; - mutable StringStream m_outputStream; + mutable std::ostringstream m_outputStream; bool m_keepLastLine; unsigned int m_lineCount; unsigned int m_errorCount; diff --git a/include/Nazara/Utility/Formats/OBJParser.inl b/include/Nazara/Utility/Formats/OBJParser.inl index da4a6abc0..e12612d93 100644 --- a/include/Nazara/Utility/Formats/OBJParser.inl +++ b/include/Nazara/Utility/Formats/OBJParser.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include @@ -135,7 +136,7 @@ namespace Nz void OBJParser::Emit(const T& text) const { m_outputStream << text; - if (m_outputStream.GetBufferSize() > 1024 * 1024) + if (m_outputStream.rdbuf()->str().size() > 1024 * 1024) Flush(); } @@ -158,8 +159,8 @@ namespace Nz inline void OBJParser::Flush() const { - m_currentStream->Write(m_outputStream); - m_outputStream.Clear(); + m_currentStream->Write(std::move(m_outputStream).str()); + m_outputStream.str({}); } inline void OBJParser::Warning(const std::string& message) diff --git a/include/Nazara/Utility/Joint.hpp b/include/Nazara/Utility/Joint.hpp index 760062350..e4d73b501 100644 --- a/include/Nazara/Utility/Joint.hpp +++ b/include/Nazara/Utility/Joint.hpp @@ -8,9 +8,9 @@ #define NAZARA_JOINT_HPP #include -#include #include #include +#include namespace Nz { @@ -26,13 +26,13 @@ namespace Nz void EnsureSkinningMatrixUpdate() const; const Matrix4f& GetInverseBindMatrix() const; - String GetName() const; + const std::string& GetName() const; Skeleton* GetSkeleton(); const Skeleton* GetSkeleton() const; const Matrix4f& GetSkinningMatrix() const; void SetInverseBindMatrix(const Matrix4f& matrix); - void SetName(const String& name); + void SetName(std::string name); private: void InvalidateNode() override; @@ -40,7 +40,7 @@ namespace Nz Matrix4f m_inverseBindMatrix; mutable Matrix4f m_skinningMatrix; - String m_name; + std::string m_name; Skeleton* m_skeleton; mutable bool m_skinningMatrixUpdated; }; diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 7e4a7965b..0cc867624 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index bb150680a..52b51da28 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -25,9 +24,9 @@ namespace Nz { inline PixelFormatDescription(); inline PixelFormatDescription(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); - inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); - inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType); - inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0); + inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); + inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType); + inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0); inline void Clear(); @@ -38,6 +37,7 @@ namespace Nz inline bool Validate() const; + std::string name; // Warning: Masks bit order is reversed Bitset<> redMask; Bitset<> greenMask; @@ -48,7 +48,6 @@ namespace Nz PixelFormatSubType greenType; PixelFormatSubType blueType; PixelFormatSubType alphaType; - String name; UInt8 bitsPerPixel; }; @@ -71,7 +70,7 @@ namespace Nz static inline PixelFormatContent GetContent(PixelFormat format); static inline UInt8 GetBytesPerPixel(PixelFormat format); static inline const PixelFormatDescription& GetInfo(PixelFormat format); - static inline const String& GetName(PixelFormat format); + static inline const std::string& GetName(PixelFormat format); static inline bool HasAlpha(PixelFormat format); diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index 82bc3cb91..6f0170607 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -25,23 +25,24 @@ namespace Nz { } - inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : + inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : + name(formatName), content(formatContent), redType(subType), greenType(subType), blueType(subType), alphaType(subType), - name(formatName), bitsPerPixel(bpp) { } - inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) : + inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) : PixelFormatDescription(formatName, formatContent, subType, rMask, subType, gMask, subType, bMask, subType, aMask) { } - inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) : + inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) : + name(formatName), redMask(rMask), greenMask(gMask), blueMask(bMask), @@ -50,8 +51,7 @@ namespace Nz redType(rType), greenType(gType), blueType(bType), - alphaType(aType), - name(formatName) + alphaType(aType) { redMask.Reverse(); greenMask.Reverse(); @@ -69,7 +69,7 @@ namespace Nz blueMask.Clear(); greenMask.Clear(); redMask.Clear(); - name.Clear(); + name.clear(); } inline bool PixelFormatDescription::IsCompressed() const @@ -245,7 +245,7 @@ namespace Nz return s_pixelFormatInfos[format]; } - inline const String& PixelFormatInfo::GetName(PixelFormat format) + inline const std::string& PixelFormatInfo::GetName(PixelFormat format) { return s_pixelFormatInfos[format].name; } diff --git a/include/Nazara/Utility/RichTextDrawer.hpp b/include/Nazara/Utility/RichTextDrawer.hpp index 3d9bfce88..56166ebd6 100644 --- a/include/Nazara/Utility/RichTextDrawer.hpp +++ b/include/Nazara/Utility/RichTextDrawer.hpp @@ -8,10 +8,10 @@ #define NAZARA_RICHTEXTDRAWER_HPP #include -#include #include #include #include +#include #include namespace Nz @@ -26,7 +26,7 @@ namespace Nz RichTextDrawer(RichTextDrawer&& drawer); ~RichTextDrawer(); - BlockRef AppendText(const String& str, bool forceNewBlock = false); + BlockRef AppendText(const std::string& str, bool forceNewBlock = false); void Clear() override; @@ -43,7 +43,7 @@ namespace Nz inline const Color& GetBlockOutlineColor(std::size_t index) const; inline float GetBlockOutlineThickness(std::size_t index) const; inline TextStyleFlags GetBlockStyle(std::size_t index) const; - inline const String& GetBlockText(std::size_t index) const; + inline const std::string& GetBlockText(std::size_t index) const; inline BlockRef GetBlock(std::size_t index); const Rectf& GetBounds() const override; @@ -77,7 +77,7 @@ namespace Nz inline void SetBlockOutlineColor(std::size_t index, const Color& color); inline void SetBlockOutlineThickness(std::size_t index, float thickness); inline void SetBlockStyle(std::size_t index, TextStyleFlags style); - inline void SetBlockText(std::size_t index, String str); + inline void SetBlockText(std::size_t index, std::string str); inline void SetDefaultCharacterSize(unsigned int characterSize); inline void SetDefaultCharacterSpacingOffset(float offset); @@ -104,7 +104,7 @@ namespace Nz inline void ConnectFontSlots(); inline void DisconnectFontSlots(); bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font* font, const Color& color, TextStyleFlags style, float lineSpacingOffset, unsigned int characterSize, int renderOrder, int* advance) const; - void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const String& text) const; + void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const std::string& text) const; inline float GetLineHeight(const Block& block) const; inline float GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const; inline std::size_t HandleFontAddition(const FontRef& font); @@ -124,9 +124,9 @@ namespace Nz { std::size_t fontIndex; std::size_t glyphIndex; + std::string text; Color color; Color outlineColor; - String text; TextStyleFlags style; float characterSpacingOffset; float lineSpacingOffset; @@ -184,7 +184,7 @@ namespace Nz inline Color GetOutlineColor() const; inline float GetOutlineThickness() const; inline TextStyleFlags GetStyle() const; - inline const String& GetText() const; + inline const std::string& GetText() const; inline void SetCharacterSpacingOffset(float offset); inline void SetCharacterSize(unsigned int size); @@ -194,7 +194,7 @@ namespace Nz inline void SetOutlineColor(Color color); inline void SetOutlineThickness(float thickness); inline void SetStyle(TextStyleFlags style); - inline void SetText(const String& text); + inline void SetText(std::string text); BlockRef& operator=(const BlockRef&) = default; BlockRef& operator=(BlockRef&&) = default; diff --git a/include/Nazara/Utility/RichTextDrawer.inl b/include/Nazara/Utility/RichTextDrawer.inl index cc132391f..977565287 100644 --- a/include/Nazara/Utility/RichTextDrawer.inl +++ b/include/Nazara/Utility/RichTextDrawer.inl @@ -118,7 +118,7 @@ namespace Nz return m_blocks[index].style; } - inline const String& RichTextDrawer::GetBlockText(std::size_t index) const + inline const std::string& RichTextDrawer::GetBlockText(std::size_t index) const { NazaraAssert(index < m_blocks.size(), "Invalid block index"); return m_blocks[index].text; @@ -341,15 +341,15 @@ namespace Nz InvalidateGlyphs(); } - inline void RichTextDrawer::SetBlockText(std::size_t index, String str) + inline void RichTextDrawer::SetBlockText(std::size_t index, std::string str) { NazaraAssert(index < m_blocks.size(), "Invalid block index"); - std::size_t previousLength = m_blocks[index].text.GetLength(); + std::size_t previousLength = m_blocks[index].text.size(); //< FIXME: Count Unicode glyphs m_blocks[index].text = std::move(str); - std::size_t newLength = m_blocks[index].text.GetLength(); + std::size_t newLength = m_blocks[index].text.size(); //< FIXME: Count Unicode glyphs if (newLength != previousLength) { std::size_t delta = newLength - previousLength; //< Underflow allowed @@ -523,7 +523,7 @@ namespace Nz * * \see GetCharacterSize, GetColor, GetFont, GetStyle, SetText */ - inline const String& RichTextDrawer::BlockRef::GetText() const + inline const std::string& RichTextDrawer::BlockRef::GetText() const { return m_drawer.GetBlockText(m_blockIndex); } @@ -622,9 +622,9 @@ namespace Nz * * \see GetText, SetCharacterSize, SetColor, SetFont, SetStyle */ - inline void RichTextDrawer::BlockRef::SetText(const String& text) + inline void RichTextDrawer::BlockRef::SetText(std::string text) { - m_drawer.SetBlockText(m_blockIndex, text); + m_drawer.SetBlockText(m_blockIndex, std::move(text)); } } diff --git a/include/Nazara/Utility/Sequence.hpp b/include/Nazara/Utility/Sequence.hpp index a5c27702a..6aa5becb7 100644 --- a/include/Nazara/Utility/Sequence.hpp +++ b/include/Nazara/Utility/Sequence.hpp @@ -7,15 +7,15 @@ #ifndef NAZARA_SEQUENCE_HPP #define NAZARA_SEQUENCE_HPP -#include #include #include +#include namespace Nz { struct Sequence { - String name; + std::string name; UInt32 firstFrame; UInt32 frameCount; UInt32 frameRate; diff --git a/include/Nazara/Utility/SimpleTextDrawer.hpp b/include/Nazara/Utility/SimpleTextDrawer.hpp index deca360a2..d1d1027dc 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.hpp +++ b/include/Nazara/Utility/SimpleTextDrawer.hpp @@ -8,7 +8,6 @@ #define NAZARA_SIMPLETEXTDRAWER_HPP #include -#include #include #include #include @@ -24,7 +23,7 @@ namespace Nz inline SimpleTextDrawer(SimpleTextDrawer&& drawer); ~SimpleTextDrawer() = default; - inline void AppendText(const String& str); + inline void AppendText(const std::string_view& str); void Clear() override; @@ -45,7 +44,7 @@ namespace Nz inline const Color& GetOutlineColor() const; inline float GetOutlineThickness() const; inline TextStyleFlags GetStyle() const; - inline const String& GetText() const; + inline const std::string& GetText() const; inline void SetCharacterSpacingOffset(float offset); inline void SetCharacterSize(unsigned int characterSize); @@ -56,15 +55,15 @@ namespace Nz inline void SetOutlineColor(const Color& color); inline void SetOutlineThickness(float thickness); inline void SetStyle(TextStyleFlags style); - inline void SetText(const String& str); + inline void SetText(std::string str); inline SimpleTextDrawer& operator=(const SimpleTextDrawer& drawer); inline SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer); - static inline SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White); - static inline SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); - static inline SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White); - static inline SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); + static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White); + static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); + static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White); + static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); private: inline void AppendNewLine() const; @@ -76,7 +75,7 @@ namespace Nz inline void DisconnectFontSlots(); bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, Nz::Color color, int renderOrder, int* advance) const; - void GenerateGlyphs(const String& text) const; + void GenerateGlyphs(const std::string_view& text) const; inline float GetLineHeight(const Font::SizeInfo& sizeInfo) const; @@ -102,11 +101,11 @@ namespace Nz mutable std::size_t m_lastSeparatorGlyph; mutable std::vector m_glyphs; mutable std::vector m_lines; + std::string m_text; Color m_color; Color m_outlineColor; FontRef m_font; mutable Rectf m_bounds; - String m_text; TextStyleFlags m_style; mutable UInt32 m_previousCharacter; mutable Vector2f m_drawPos; diff --git a/include/Nazara/Utility/SimpleTextDrawer.inl b/include/Nazara/Utility/SimpleTextDrawer.inl index 4caa05b0b..0bc38edda 100644 --- a/include/Nazara/Utility/SimpleTextDrawer.inl +++ b/include/Nazara/Utility/SimpleTextDrawer.inl @@ -23,9 +23,9 @@ namespace Nz } inline SimpleTextDrawer::SimpleTextDrawer(const SimpleTextDrawer& drawer) : + m_text(drawer.m_text), m_color(drawer.m_color), m_outlineColor(drawer.m_outlineColor), - m_text(drawer.m_text), m_style(drawer.m_style), m_colorUpdated(false), m_glyphUpdated(false), @@ -43,9 +43,9 @@ namespace Nz operator=(std::move(drawer)); } - inline void SimpleTextDrawer::AppendText(const String& str) + inline void SimpleTextDrawer::AppendText(const std::string_view& str) { - m_text.Append(str); + m_text.append(str); if (m_glyphUpdated) GenerateGlyphs(str); } @@ -96,7 +96,7 @@ namespace Nz return m_style; } - inline const String& SimpleTextDrawer::GetText() const + inline const std::string& SimpleTextDrawer::GetText() const { return m_text; } @@ -200,11 +200,11 @@ namespace Nz } } - inline void SimpleTextDrawer::SetText(const String& str) + inline void SimpleTextDrawer::SetText(std::string str) { if (m_text != str) { - m_text = str; + m_text = std::move(str); InvalidateGlyphs(); } @@ -257,7 +257,7 @@ namespace Nz return *this; } - inline SimpleTextDrawer SimpleTextDrawer::Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color) + inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color) { SimpleTextDrawer drawer; drawer.SetCharacterSize(characterSize); @@ -268,7 +268,7 @@ namespace Nz return drawer; } - inline SimpleTextDrawer SimpleTextDrawer::Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) + inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) { SimpleTextDrawer drawer; drawer.SetCharacterSize(characterSize); @@ -281,7 +281,7 @@ namespace Nz return drawer; } - inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color) + inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color) { SimpleTextDrawer drawer; drawer.SetCharacterSize(characterSize); @@ -293,7 +293,7 @@ namespace Nz return drawer; } - inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) + inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) { SimpleTextDrawer drawer; drawer.SetCharacterSize(characterSize); diff --git a/include/Nazara/Utility/Skeleton.hpp b/include/Nazara/Utility/Skeleton.hpp index 3ef9091bc..535fc9f7d 100644 --- a/include/Nazara/Utility/Skeleton.hpp +++ b/include/Nazara/Utility/Skeleton.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace Nz { @@ -41,14 +42,14 @@ namespace Nz void Destroy(); const Boxf& GetAABB() const; - Joint* GetJoint(const String& jointName); + Joint* GetJoint(const std::string& jointName); Joint* GetJoint(std::size_t index); - const Joint* GetJoint(const String& jointName) const; + const Joint* GetJoint(const std::string& jointName) const; const Joint* GetJoint(std::size_t index) const; Joint* GetJoints(); const Joint* GetJoints() const; std::size_t GetJointCount() const; - int GetJointIndex(const String& jointName) const; + int GetJointIndex(const std::string& jointName) const; void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation); void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, std::size_t* indices, std::size_t indiceCount); diff --git a/include/Nazara/VulkanRenderer/Utils.hpp b/include/Nazara/VulkanRenderer/Utils.hpp index 173589965..c1267da83 100644 --- a/include/Nazara/VulkanRenderer/Utils.hpp +++ b/include/Nazara/VulkanRenderer/Utils.hpp @@ -8,7 +8,6 @@ #define NAZARA_UTILS_VULKAN_HPP #include -#include #include #include #include diff --git a/include/Nazara/VulkanRenderer/Utils.inl b/include/Nazara/VulkanRenderer/Utils.inl index 616680324..242e7c6e0 100644 --- a/include/Nazara/VulkanRenderer/Utils.inl +++ b/include/Nazara/VulkanRenderer/Utils.inl @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace Nz @@ -19,7 +19,7 @@ namespace Nz case BufferType_Uniform: return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; } - NazaraError("Unhandled BufferType 0x" + String::Number(bufferType, 16)); + NazaraError("Unhandled BufferType 0x" + NumberToString(bufferType, 16)); return 0; } @@ -43,7 +43,7 @@ namespace Nz case ComponentType_Quaternion: return VK_FORMAT_R32G32B32A32_SFLOAT; } - NazaraError("Unhandled ComponentType 0x" + String::Number(componentType, 16)); + NazaraError("Unhandled ComponentType 0x" + NumberToString(componentType, 16)); return VK_FORMAT_UNDEFINED; } @@ -57,7 +57,7 @@ namespace Nz case FaceSide_FrontAndBack: return VK_CULL_MODE_FRONT_AND_BACK; } - NazaraError("Unhandled FaceSide 0x" + String::Number(faceSide, 16)); + NazaraError("Unhandled FaceSide 0x" + NumberToString(faceSide, 16)); return VK_CULL_MODE_BACK_BIT; } @@ -70,7 +70,7 @@ namespace Nz case FaceFilling_Point: return VK_POLYGON_MODE_POINT; } - NazaraError("Unhandled FaceFilling 0x" + String::Number(faceFilling, 16)); + NazaraError("Unhandled FaceFilling 0x" + NumberToString(faceFilling, 16)); return VK_POLYGON_MODE_FILL; } @@ -86,7 +86,7 @@ namespace Nz case PrimitiveMode_TriangleFan: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; } - NazaraError("Unhandled FaceFilling 0x" + String::Number(primitiveMode, 16)); + NazaraError("Unhandled FaceFilling 0x" + NumberToString(primitiveMode, 16)); return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; } @@ -104,7 +104,7 @@ namespace Nz case RendererComparison_Always: return VK_COMPARE_OP_ALWAYS; } - NazaraError("Unhandled RendererComparison 0x" + String::Number(comparison, 16)); + NazaraError("Unhandled RendererComparison 0x" + NumberToString(comparison, 16)); return VK_COMPARE_OP_NEVER; } @@ -116,7 +116,7 @@ namespace Nz case SamplerFilter_Nearest: return VK_FILTER_NEAREST; } - NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(samplerFilter), 16)); + NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(samplerFilter), 16)); return VK_FILTER_NEAREST; } @@ -128,7 +128,7 @@ namespace Nz case SamplerMipmapMode_Nearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST; } - NazaraError("Unhandled SamplerMipmapMode 0x" + String::Number(UnderlyingCast(samplerMipmap), 16)); + NazaraError("Unhandled SamplerMipmapMode 0x" + NumberToString(UnderlyingCast(samplerMipmap), 16)); return VK_SAMPLER_MIPMAP_MODE_NEAREST; } @@ -141,7 +141,7 @@ namespace Nz case SamplerWrap_Repeat: return VK_SAMPLER_ADDRESS_MODE_REPEAT; } - NazaraError("Unhandled SamplerWrap 0x" + String::Number(UnderlyingCast(samplerWrap), 16)); + NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(samplerWrap), 16)); return VK_SAMPLER_ADDRESS_MODE_REPEAT; } @@ -153,7 +153,7 @@ namespace Nz case ShaderBindingType::UniformBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; } - NazaraError("Unhandled ShaderBindingType 0x" + String::Number(UnderlyingCast(bindingType), 16)); + NazaraError("Unhandled ShaderBindingType 0x" + NumberToString(UnderlyingCast(bindingType), 16)); return VK_DESCRIPTOR_TYPE_SAMPLER; } @@ -165,7 +165,7 @@ namespace Nz case ShaderStageType::Vertex: return VK_SHADER_STAGE_VERTEX_BIT; } - NazaraError("Unhandled ShaderStageType 0x" + String::Number(UnderlyingCast(stageType), 16)); + NazaraError("Unhandled ShaderStageType 0x" + NumberToString(UnderlyingCast(stageType), 16)); return {}; } @@ -198,7 +198,7 @@ namespace Nz case StencilOperation_Zero: return VK_STENCIL_OP_ZERO; } - NazaraError("Unhandled RendererComparison 0x" + String::Number(stencilOp, 16)); + NazaraError("Unhandled RendererComparison 0x" + NumberToString(stencilOp, 16)); return VK_STENCIL_OP_KEEP; } @@ -210,7 +210,7 @@ namespace Nz case VertexInputRate::Vertex: return VK_VERTEX_INPUT_RATE_VERTEX; } - NazaraError("Unhandled VertexInputRate 0x" + String::Number(UnderlyingCast(inputRate), 16)); + NazaraError("Unhandled VertexInputRate 0x" + NumberToString(UnderlyingCast(inputRate), 16)); return VK_VERTEX_INPUT_RATE_VERTEX; } } diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.inl b/include/Nazara/VulkanRenderer/Wrapper/Device.inl index e3552e199..308bf442d 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.inl @@ -90,7 +90,7 @@ namespace Nz { PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name); if (!func) - NazaraError("Failed to get " + String(name) + " address"); + NazaraError("Failed to get " + std::string(name) + " address"); return func; } diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl index 1fcc219b5..7d8382302 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl @@ -41,7 +41,7 @@ namespace Nz typeMask <<= 1; } - NazaraError("Failed to find a memory type suitable for typeBits: " + String::Number(typeBits) + " and properties: 0x" + String::Number(properties, 16)); + NazaraError("Failed to find a memory type suitable for typeBits: " + NumberToString(typeBits) + " and properties: 0x" + NumberToString(properties, 16)); return false; } diff --git a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl index 0c489d766..9079421f4 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl @@ -79,7 +79,7 @@ namespace Nz if (!m_images[i].view.Create(*m_device, imageViewCreateInfo)) { - NazaraError("Failed to create image view for image #" + String::Number(i)); + NazaraError("Failed to create image view for image #" + NumberToString(i)); return false; } } diff --git a/include/NazaraSDK/Application.hpp b/include/NazaraSDK/Application.hpp index 1ae04a520..2bd467137 100644 --- a/include/NazaraSDK/Application.hpp +++ b/include/NazaraSDK/Application.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #ifndef NDK_SERVER #include @@ -35,13 +36,13 @@ namespace Ndk #endif template World& AddWorld(Args&&... args); - inline const std::set& GetOptions() const; - inline const std::map& GetParameters() const; + inline const std::set& GetOptions() const; + inline const std::map& GetParameters() const; inline float GetUpdateTime() const; - inline bool HasOption(const Nz::String& option) const; - inline bool HasParameter(const Nz::String& key, Nz::String* value) const; + inline bool HasOption(const std::string& option) const; + inline bool HasParameter(const std::string& key, std::string* value) const; #ifndef NDK_SERVER inline bool IsConsoleEnabled() const; @@ -73,8 +74,8 @@ namespace Ndk std::vector m_windows; #endif - std::map m_parameters; - std::set m_options; + std::map m_parameters; + std::set m_options; std::list m_worlds; Nz::Clock m_updateClock; diff --git a/include/NazaraSDK/Application.inl b/include/NazaraSDK/Application.inl index 68dd600af..d6b58a257 100644 --- a/include/NazaraSDK/Application.inl +++ b/include/NazaraSDK/Application.inl @@ -81,7 +81,7 @@ namespace Ndk * * \return Command-line options */ - inline const std::set& Application::GetOptions() const + inline const std::set& Application::GetOptions() const { return m_options; } @@ -93,7 +93,7 @@ namespace Ndk * * \return Command-line parameters */ - inline const std::map& Application::GetParameters() const + inline const std::map& Application::GetParameters() const { return m_parameters; } @@ -118,7 +118,7 @@ namespace Ndk * * \see GetOptions */ - inline bool Application::HasOption(const Nz::String& option) const + inline bool Application::HasOption(const std::string& option) const { return m_options.count(option) != 0; } @@ -135,7 +135,7 @@ namespace Ndk * * \see GetParameters */ - inline bool Application::HasParameter(const Nz::String& key, Nz::String* value) const + inline bool Application::HasParameter(const std::string& key, std::string* value) const { auto it = m_parameters.find(key); if (it == m_parameters.end()) diff --git a/include/NazaraSDK/Components/PhysicsComponent3D.hpp b/include/NazaraSDK/Components/PhysicsComponent3D.hpp index 4dfb6fce6..16a242e81 100644 --- a/include/NazaraSDK/Components/PhysicsComponent3D.hpp +++ b/include/NazaraSDK/Components/PhysicsComponent3D.hpp @@ -58,7 +58,7 @@ namespace Ndk inline void SetLinearVelocity(const Nz::Vector3f& velocity); inline void SetMass(float mass); inline void SetMassCenter(const Nz::Vector3f& center); - inline void SetMaterial(const Nz::String& materialName); + inline void SetMaterial(const std::string& materialName); inline void SetMaterial(int materialIndex); inline void SetPosition(const Nz::Vector3f& position); inline void SetRotation(const Nz::Quaternionf& rotation); diff --git a/include/NazaraSDK/Components/PhysicsComponent3D.inl b/include/NazaraSDK/Components/PhysicsComponent3D.inl index 06a082ac9..9937f354c 100644 --- a/include/NazaraSDK/Components/PhysicsComponent3D.inl +++ b/include/NazaraSDK/Components/PhysicsComponent3D.inl @@ -410,7 +410,7 @@ namespace Ndk * * \remark materialName must exists in PhysWorld before this call */ - inline void PhysicsComponent3D::SetMaterial(const Nz::String& materialName) + inline void PhysicsComponent3D::SetMaterial(const std::string& materialName) { NazaraAssert(m_object, "Invalid physics object"); diff --git a/include/NazaraSDK/Entity.hpp b/include/NazaraSDK/Entity.hpp index e96bfe48e..3c8d99306 100644 --- a/include/NazaraSDK/Entity.hpp +++ b/include/NazaraSDK/Entity.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace Ndk @@ -72,7 +73,7 @@ namespace Ndk inline void RemoveComponent(ComponentIndex index); template void RemoveComponent(); - inline Nz::String ToString() const; + inline std::string ToString() const; Entity& operator=(const Entity&) = delete; Entity& operator=(Entity&&) = delete; diff --git a/include/NazaraSDK/Entity.inl b/include/NazaraSDK/Entity.inl index ed9d6e98e..60a8e7f24 100644 --- a/include/NazaraSDK/Entity.inl +++ b/include/NazaraSDK/Entity.inl @@ -4,9 +4,9 @@ #include #include -#include #include #include +#include #include namespace Ndk @@ -245,10 +245,12 @@ namespace Ndk * \return A string representation of the object: "Entity(GetId())" */ - inline Nz::String Entity::ToString() const + inline std::string Entity::ToString() const { - Nz::StringStream ss; - return ss << "Entity(" << GetId() << ')'; + std::ostringstream ss; + ss << "Entity(" << GetId() << ')'; + + return ss.str(); } /*! diff --git a/include/NazaraSDK/EntityOwner.inl b/include/NazaraSDK/EntityOwner.inl index bf0a1a82d..9016b4233 100644 --- a/include/NazaraSDK/EntityOwner.inl +++ b/include/NazaraSDK/EntityOwner.inl @@ -3,7 +3,6 @@ // For conditions of distribution and use, see copyright notice in Prerequisites.hpp #include -#include #include #include diff --git a/include/NazaraSDK/StateMachine.inl b/include/NazaraSDK/StateMachine.inl index 9392140e1..4079d06ea 100644 --- a/include/NazaraSDK/StateMachine.inl +++ b/include/NazaraSDK/StateMachine.inl @@ -4,6 +4,7 @@ #include #include +#include #include namespace Ndk diff --git a/plugins/Assimp/CustomStream.cpp b/plugins/Assimp/CustomStream.cpp index d66088c6a..4e8392aad 100644 --- a/plugins/Assimp/CustomStream.cpp +++ b/plugins/Assimp/CustomStream.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,7 @@ aiReturn StreamSeek(aiFile* file, size_t offset, aiOrigin origin) break; } - NazaraWarning("Unhandled aiOrigin enum (value: 0x" + String(origin, 16) + ')'); + NazaraWarning("Unhandled aiOrigin enum (value: 0x" + std::string(origin, 16) + ')'); return aiReturn_FAILURE; } @@ -105,7 +104,7 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod } else { - NazaraError(String("Unhandled/Invalid openmode: ") + openMode + String(" for file ") + filePath); + NazaraError(std::string("Unhandled/Invalid openmode: ") + openMode + std::string(" for file ") + filePath); return nullptr; } diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index cc9978b9b..10c1d1327 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -24,7 +24,6 @@ SOFTWARE. #include #include -#include #include #include #include @@ -46,9 +45,9 @@ SOFTWARE. using namespace Nz; -void ProcessJoints(aiNode* node, Skeleton* skeleton, const std::set& joints) +void ProcessJoints(aiNode* node, Skeleton* skeleton, const std::set& joints) { - Nz::String jointName(node->mName.data, node->mName.length); + std::string jointName(node->mName.data, node->mName.length); if (joints.count(jointName)) { Joint* joint = skeleton->GetJoint(jointName); @@ -121,7 +120,7 @@ AnimationRef LoadAnimation(Stream& stream, const AnimationParams& parameters) if (!scene) { - NazaraError("Assimp failed to import file: " + Nz::String(aiGetErrorString())); + NazaraError("Assimp failed to import file: " + std::string(aiGetErrorString())); return nullptr; } @@ -246,11 +245,11 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) if (!scene) { - NazaraError("Assimp failed to import file: " + Nz::String(aiGetErrorString())); + NazaraError("Assimp failed to import file: " + std::string(aiGetErrorString())); return nullptr; } - std::set joints; + std::set joints; bool animatedMesh = false; if (parameters.animated) @@ -276,7 +275,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) // First, assign names unsigned int jointIndex = 0; - for (const Nz::String& jointName : joints) + for (const std::string& jointName : joints) skeleton->GetJoint(jointIndex++)->SetName(jointName); ProcessJoints(scene->mRootNode, skeleton, joints); @@ -398,7 +397,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) break; default: - NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode[0], 16) + " not handled"); + NazaraWarning("Assimp texture map mode 0x" + NumberToString(mapMode[0], 16) + " not handled"); break; } @@ -420,7 +419,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) aiString name; if (aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS) - matData.SetParameter(MaterialData::Name, String(name.data, name.length)); + matData.SetParameter(MaterialData::Name, std::string(name.data, name.length)); int iValue; if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS) @@ -584,7 +583,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) break; default: - NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode[0], 16) + " not handled"); + NazaraWarning("Assimp texture map mode 0x" + NumberToString(mapMode[0], 16) + " not handled"); break; } @@ -606,7 +605,7 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters) aiString name; if (aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS) - matData.SetParameter(MaterialData::Name, String(name.data, name.length)); + matData.SetParameter(MaterialData::Name, std::string(name.data, name.length)); int iValue; if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS) diff --git a/src/Nazara/Audio/Audio.cpp b/src/Nazara/Audio/Audio.cpp index 3eff5dc3a..d1ea24372 100644 --- a/src/Nazara/Audio/Audio.cpp +++ b/src/Nazara/Audio/Audio.cpp @@ -71,7 +71,7 @@ namespace Nz return static_cast(channelCount); default: - NazaraError("Invalid channel count: " + String::Number(channelCount)); + NazaraError("Invalid channel count: " + NumberToString(channelCount)); return AudioFormat_Unknown; } } diff --git a/src/Nazara/Audio/Formats/sndfileLoader.cpp b/src/Nazara/Audio/Formats/sndfileLoader.cpp index 5d0fe19df..06e4a523c 100644 --- a/src/Nazara/Audio/Formats/sndfileLoader.cpp +++ b/src/Nazara/Audio/Formats/sndfileLoader.cpp @@ -141,7 +141,7 @@ namespace Nz m_handle = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream); if (!m_handle) { - NazaraError("Failed to open sound: " + String(sf_strerror(m_handle))); + NazaraError("Failed to open sound: " + std::string(sf_strerror(m_handle))); return false; } @@ -315,7 +315,7 @@ namespace Nz SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &info, &stream); if (!file) { - NazaraError("Failed to load sound file: " + String(sf_strerror(file))); + NazaraError("Failed to load sound file: " + std::string(sf_strerror(file))); return nullptr; } diff --git a/src/Nazara/Audio/OpenAL.cpp b/src/Nazara/Audio/OpenAL.cpp index 547807508..e1a148a96 100644 --- a/src/Nazara/Audio/OpenAL.cpp +++ b/src/Nazara/Audio/OpenAL.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -16,9 +17,9 @@ namespace Nz namespace { DynLib s_library; - String s_deviceName; - String s_rendererName; - String s_vendorName; + std::string s_deviceName; + std::string s_rendererName; + std::string s_vendorName; ALCdevice* s_device = nullptr; ALCcontext* s_context = nullptr; unsigned int s_version; @@ -31,7 +32,7 @@ namespace Nz * \param devices List of names of the devices */ - std::size_t ParseDevices(const char* deviceString, std::vector& devices) + std::size_t ParseDevices(const char* deviceString, std::vector& devices) { if (!deviceString) return 0; @@ -66,9 +67,9 @@ namespace Nz * \remark This does not produces a NazaraError if entry does not exist */ - OpenALFunc OpenAL::GetEntry(const String& entryPoint) + OpenALFunc OpenAL::GetEntry(const std::string& entryPoint) { - return LoadEntry(entryPoint.GetConstBuffer(), false); + return LoadEntry(entryPoint.data(), false); } /*! @@ -76,7 +77,7 @@ namespace Nz * \return Name of the renderer */ - String OpenAL::GetRendererName() + std::string OpenAL::GetRendererName() { return s_rendererName; } @@ -86,7 +87,7 @@ namespace Nz * \return Name of the vendor */ - String OpenAL::GetVendorName() + std::string OpenAL::GetVendorName() { return s_vendorName; } @@ -284,7 +285,7 @@ namespace Nz * \param devices List of names of the input devices */ - std::size_t OpenAL::QueryInputDevices(std::vector& devices) + std::size_t OpenAL::QueryInputDevices(std::vector& devices) { const char* deviceString = reinterpret_cast(alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER)); if (!deviceString) @@ -300,7 +301,7 @@ namespace Nz * \param devices List of names of the output devices */ - std::size_t OpenAL::QueryOutputDevices(std::vector& devices) + std::size_t OpenAL::QueryOutputDevices(std::vector& devices) { const char* deviceString = reinterpret_cast(alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER)); if (!deviceString) @@ -316,7 +317,7 @@ namespace Nz * \param deviceName Name of the device */ - bool OpenAL::SetDevice(const String& deviceName) + bool OpenAL::SetDevice(const std::string& deviceName) { s_deviceName = deviceName; if (IsInitialized()) @@ -337,8 +338,8 @@ namespace Nz { CloseDevice(); - s_rendererName.Clear(false); - s_vendorName.Clear(false); + s_rendererName.clear(); + s_vendorName.clear(); s_library.Unload(); } @@ -380,7 +381,7 @@ namespace Nz bool OpenAL::OpenDevice() { // Initialisation of the module - s_device = alcOpenDevice(s_deviceName.IsEmpty() ? nullptr : s_deviceName.GetConstBuffer()); // We choose the default device + s_device = alcOpenDevice(s_deviceName.empty() ? nullptr : s_deviceName.data()); // We choose the default device if (!s_device) { NazaraError("Failed to open default device"); @@ -420,7 +421,7 @@ namespace Nz s_version = major*100 + minor*10; - NazaraDebug("OpenAL version: " + String::Number(major) + '.' + String::Number(minor)); + NazaraDebug("OpenAL version: " + NumberToString(major) + '.' + NumberToString(minor)); } else { diff --git a/src/Nazara/Audio/Sound.cpp b/src/Nazara/Audio/Sound.cpp index c6e96fff8..ec7306a99 100644 --- a/src/Nazara/Audio/Sound.cpp +++ b/src/Nazara/Audio/Sound.cpp @@ -177,7 +177,7 @@ namespace Nz SoundBufferRef buffer = SoundBuffer::LoadFromMemory(data, size, params); if (!buffer) { - NazaraError("Failed to load buffer from memory (" + String::Pointer(data) + ')'); + NazaraError("Failed to load buffer from memory (" + PointerToString(data) + ')'); return false; } diff --git a/src/Nazara/Core/AbstractHash.cpp b/src/Nazara/Core/AbstractHash.cpp index c45ec4b0f..dff2570bc 100644 --- a/src/Nazara/Core/AbstractHash.cpp +++ b/src/Nazara/Core/AbstractHash.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace Nz @@ -74,7 +75,7 @@ namespace Nz return std::make_unique(); } - NazaraInternalError("Hash type not handled (0x" + String::Number(type, 16) + ')'); + NazaraInternalError("Hash type not handled (0x" + NumberToString(type, 16) + ')'); return nullptr; } } diff --git a/src/Nazara/Core/AbstractLogger.cpp b/src/Nazara/Core/AbstractLogger.cpp index a6eddc6ed..8eba0df9b 100644 --- a/src/Nazara/Core/AbstractLogger.cpp +++ b/src/Nazara/Core/AbstractLogger.cpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include +#include #include namespace Nz @@ -40,14 +40,14 @@ namespace Nz * \param function Name of the function throwing the error */ - void AbstractLogger::WriteError(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) + void AbstractLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { - StringStream stream; - stream << errorType[type] << error; + std::ostringstream ss; + ss << errorType[type] << error; if (line != 0 && file && function) - stream << " (" << file << ':' << line << ": " << function << ')'; + ss << " (" << file << ':' << line << ": " << function << ')'; - Write(stream); + Write(ss.str()); } } diff --git a/src/Nazara/Core/ByteArray.cpp b/src/Nazara/Core/ByteArray.cpp index a49801201..46adef6e3 100644 --- a/src/Nazara/Core/ByteArray.cpp +++ b/src/Nazara/Core/ByteArray.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -18,11 +19,11 @@ namespace Nz * \return String in base 16 */ - String ByteArray::ToHex() const + std::string ByteArray::ToHex() const { std::size_t length = m_array.size() * 2; - String hexOutput(length, '\0'); + std::string hexOutput(length, '\0'); for (std::size_t i = 0; i < m_array.size(); ++i) std::sprintf(&hexOutput[i * 2], "%02x", m_array[i]); diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index 090804ead..348950bec 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -45,7 +45,7 @@ namespace Nz * \param function Optional argument to set last error function */ - String Error::GetLastError(const char** file, unsigned int* line, const char** function) + std::string Error::GetLastError(const char** file, unsigned int* line, const char** function) { if (file) *file = s_lastErrorFile; @@ -103,7 +103,7 @@ namespace Nz #else #error GetLastSystemError is not implemented on this platform - return String("GetLastSystemError is not implemented on this platform"); + return "GetLastSystemError is not implemented on this platform"; #endif } @@ -128,12 +128,12 @@ namespace Nz * \remark Produces a std::runtime_error on AssertFailed or throwing exception */ - void Error::Trigger(ErrorType type, const String& error) + void Error::Trigger(ErrorType type, std::string error) { if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) Log::WriteError(type, error); - s_lastError = error; + s_lastError = std::move(error); s_lastErrorFile = ""; s_lastErrorFunction = ""; s_lastErrorLine = 0; @@ -145,7 +145,7 @@ namespace Nz if (type == ErrorType_AssertFailed || (type != ErrorType_Warning && (s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0)) - throw std::runtime_error(error.ToStdString()); + throw std::runtime_error(s_lastError); } /*! @@ -161,14 +161,14 @@ namespace Nz * \remark Produces a std::runtime_error on AssertFailed or throwing exception */ - void Error::Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) + void Error::Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function) { file = GetCurrentFileRelativeToEngine(file); if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) Log::WriteError(type, error, line, file, function); - s_lastError = error; + s_lastError = std::move(error); s_lastErrorFile = file; s_lastErrorFunction = function; s_lastErrorLine = line; @@ -180,7 +180,7 @@ namespace Nz if (type == ErrorType_AssertFailed || (type != ErrorType_Warning && (s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0)) - throw std::runtime_error(error.ToStdString()); + throw std::runtime_error(s_lastError); } const char* Error::GetCurrentFileRelativeToEngine(const char* file) @@ -195,7 +195,7 @@ namespace Nz } UInt32 Error::s_flags = ErrorFlag_None; - String Error::s_lastError; + std::string Error::s_lastError; const char* Error::s_lastErrorFunction = ""; const char* Error::s_lastErrorFile = ""; unsigned int Error::s_lastErrorLine = 0; diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 18a6d5a0a..3b1be9ada 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #if defined(NAZARA_PLATFORM_WINDOWS) diff --git a/src/Nazara/Core/FileLogger.cpp b/src/Nazara/Core/FileLogger.cpp index 2ce6f03db..5aedf9aad 100644 --- a/src/Nazara/Core/FileLogger.cpp +++ b/src/Nazara/Core/FileLogger.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -26,8 +25,8 @@ namespace Nz * \param logPath Path to log */ - FileLogger::FileLogger(const String& logPath) : - m_outputPath(logPath.ToStdString()), + FileLogger::FileLogger(std::filesystem::path logPath) : + m_outputPath(std::move(logPath)), m_forceStdOutput(false), m_stdReplicationEnabled(true), m_timeLoggingEnabled(true) @@ -92,7 +91,7 @@ namespace Nz * \see WriteError */ - void FileLogger::Write(const String& string) + void FileLogger::Write(const std::string_view& string) { if (m_forceStdOutput || m_stdReplicationEnabled) { @@ -148,7 +147,7 @@ namespace Nz * \see Write */ - void FileLogger::WriteError(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) + void FileLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { AbstractLogger::WriteError(type, error, line, file, function); m_outputFile.flush(); diff --git a/src/Nazara/Core/GuillotineBinPack.cpp b/src/Nazara/Core/GuillotineBinPack.cpp index e0589966d..9e33d8cc8 100644 --- a/src/Nazara/Core/GuillotineBinPack.cpp +++ b/src/Nazara/Core/GuillotineBinPack.cpp @@ -613,7 +613,7 @@ namespace Nz break; default: - NazaraError("Split heuristic out of enum (0x" + String::Number(method, 16) + ')'); + NazaraError("Split heuristic out of enum (0x" + NumberToString(method, 16) + ')'); splitHorizontal = true; } @@ -656,7 +656,7 @@ namespace Nz return ScoreWorstShortSideFit(width, height, freeRect); } - NazaraError("Rect choice heuristic out of enum (0x" + String::Number(rectChoice, 16) + ')'); + NazaraError("Rect choice heuristic out of enum (0x" + NumberToString(rectChoice, 16) + ')'); return std::numeric_limits::max(); } } diff --git a/src/Nazara/Core/HardwareInfo.cpp b/src/Nazara/Core/HardwareInfo.cpp index f90560e9d..a048ef99b 100644 --- a/src/Nazara/Core/HardwareInfo.cpp +++ b/src/Nazara/Core/HardwareInfo.cpp @@ -107,7 +107,7 @@ namespace Nz * \remark Produces a NazaraError if not Initialize */ - String HardwareInfo::GetProcessorBrandString() + std::string_view HardwareInfo::GetProcessorBrandString() { if (!Initialize()) NazaraError("Failed to initialize HardwareInfo"); @@ -150,7 +150,7 @@ namespace Nz * \remark Produces a NazaraError if not Initialize */ - String HardwareInfo::GetProcessorVendorName() + std::string_view HardwareInfo::GetProcessorVendorName() { if (!Initialize()) NazaraError("Failed to initialize HardwareInfo"); diff --git a/src/Nazara/Core/Log.cpp b/src/Nazara/Core/Log.cpp index cce990be9..862052110 100644 --- a/src/Nazara/Core/Log.cpp +++ b/src/Nazara/Core/Log.cpp @@ -76,7 +76,7 @@ namespace Nz * \see WriteError */ - void Log::Write(const String& string) + void Log::Write(const std::string_view& string) { if (s_enabled) s_logger->Write(string); @@ -96,7 +96,7 @@ namespace Nz * \see Write */ - void Log::WriteError(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) + void Log::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { if (s_enabled) s_logger->WriteError(type, error, line, file, function); diff --git a/src/Nazara/Core/ParameterList.cpp b/src/Nazara/Core/ParameterList.cpp index a0562fc16..c22ee24e6 100644 --- a/src/Nazara/Core/ParameterList.cpp +++ b/src/Nazara/Core/ParameterList.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -55,9 +56,9 @@ namespace Nz * \remark In case of failure, the variable pointed by value keep its value * \remark If the parameter is not a boolean, a conversion will be performed, compatibles types are: Integer: 0 is interpreted as false, any other value is interpreted as true - String: Conversion obeys the rule as described by String::ToBool + std::string: Conversion obeys the rule as described by std::string::ToBool */ - bool ParameterList::GetBooleanParameter(const String& name, bool* value) const + bool ParameterList::GetBooleanParameter(const std::string& name, bool* value) const { NazaraAssert(value, "Invalid pointer"); @@ -82,10 +83,14 @@ namespace Nz case ParameterType_String: { - bool converted; - if (it->second.value.stringVal.ToBool(&converted, String::CaseInsensitive)) + if (it->second.value.stringVal == "1" || it->second.value.stringVal == "yes" || it->second.value.stringVal == "true") { - *value = converted; + *value = true; + return true; + } + else if (it->second.value.stringVal == "0" || it->second.value.stringVal == "no" || it->second.value.stringVal == "false") + { + *value = false; return true; } @@ -115,7 +120,7 @@ namespace Nz * \remark In case of failure, the variable pointed by value keep its value * \remark If the parameter is not a color, the function fails */ - bool ParameterList::GetColorParameter(const String& name, Color* value) const + bool ParameterList::GetColorParameter(const std::string& name, Color* value) const { NazaraAssert(value, "Invalid pointer"); @@ -159,9 +164,9 @@ namespace Nz * \remark In case of failure, the variable pointed by value keep its value * \remark If the parameter is not a double, a conversion will be performed, compatibles types are: Integer: The integer value is converted to its double representation - String: Conversion obeys the rule as described by String::ToDouble + std::string: Conversion obeys the rule as described by std::string::ToDouble */ - bool ParameterList::GetDoubleParameter(const String& name, double* value) const + bool ParameterList::GetDoubleParameter(const std::string& name, double* value) const { NazaraAssert(value, "Invalid pointer"); @@ -185,16 +190,21 @@ namespace Nz return true; case ParameterType_String: - { - double converted; - if (it->second.value.stringVal.ToDouble(&converted)) - { - *value = converted; - return true; - } + { + const std::string& str = it->second.value.stringVal; + int& err = errno; + err = 0; + + char* endStr; + double ret = std::strtod(str.data(), &endStr); + + if (str.data() == endStr || err == ERANGE) break; - } + + *value = ret; + return true; + } case ParameterType_Boolean: case ParameterType_Color: @@ -220,9 +230,9 @@ namespace Nz * \remark If the parameter is not an integer, a conversion will be performed, compatibles types are: Boolean: The boolean is represented as 1 if true and 0 if false Double: The floating-point value is truncated and converted to a integer - String: Conversion obeys the rule as described by String::ToInteger + std::string: Conversion obeys the rule as described by std::string::ToInteger */ - bool ParameterList::GetIntegerParameter(const String& name, long long* value) const + bool ParameterList::GetIntegerParameter(const std::string& name, long long* value) const { NazaraAssert(value, "Invalid pointer"); @@ -250,15 +260,21 @@ namespace Nz return true; case ParameterType_String: - { - long long converted; - if (it->second.value.stringVal.ToInteger(&converted)) - { - *value = converted; - return true; - } + { + const std::string& str = it->second.value.stringVal; + + int& err = errno; + err = 0; + + char* endStr; + long long ret = std::strtoll(str.data(), &endStr, 0); + + if (str.data() == endStr || err == ERANGE) break; - } + + *value = ret; + return true; + } case ParameterType_Color: case ParameterType_None: @@ -280,7 +296,7 @@ namespace Nz * * \remark type must be a valid pointer to a ParameterType variable */ - bool ParameterList::GetParameterType(const String& name, ParameterType* type) const + bool ParameterList::GetParameterType(const std::string& name, ParameterType* type) const { NazaraAssert(type, "Invalid pointer"); @@ -305,7 +321,7 @@ namespace Nz * \remark If the parameter is not a pointer, a conversion will be performed, compatibles types are: Userdata: The pointer part of the userdata is returned */ - bool ParameterList::GetPointerParameter(const String& name, void** value) const + bool ParameterList::GetPointerParameter(const std::string& name, void** value) const { NazaraAssert(value, "Invalid pointer"); @@ -351,15 +367,15 @@ namespace Nz * \remark value must be a valid pointer * \remark In case of failure, the variable pointed by value keep its value * \remark If the parameter is not a string, a conversion will be performed, all types are compatibles: - Boolean: Conversion obeys the rules of String::Boolean + Boolean: Conversion obeys the rules of std::string::Boolean Color: Conversion obeys the rules of Color::ToString - Double: Conversion obeys the rules of String::Number - Integer: Conversion obeys the rules of String::Number + Double: Conversion obeys the rules of std::string::Number + Integer: Conversion obeys the rules of std::string::Number None: An empty string is returned - Pointer: Conversion obeys the rules of String::Pointer - Userdata: Conversion obeys the rules of String::Pointer + Pointer: Conversion obeys the rules of PointerToString + Userdata: Conversion obeys the rules of PointerToString */ - bool ParameterList::GetStringParameter(const String& name, String* value) const + bool ParameterList::GetStringParameter(const std::string& name, std::string* value) const { NazaraAssert(value, "Invalid pointer"); @@ -375,7 +391,7 @@ namespace Nz switch (it->second.type) { case ParameterType_Boolean: - *value = String::Boolean(it->second.value.boolVal); + *value = (it->second.value.boolVal) ? "true" : "false"; return true; case ParameterType_Color: @@ -383,11 +399,11 @@ namespace Nz return true; case ParameterType_Double: - *value = String::Number(it->second.value.doubleVal); + *value = std::to_string(it->second.value.doubleVal); return true; case ParameterType_Integer: - *value = String::Number(it->second.value.intVal); + *value = std::to_string(it->second.value.intVal); return true; case ParameterType_String: @@ -395,15 +411,15 @@ namespace Nz return true; case ParameterType_Pointer: - *value = String::Pointer(it->second.value.ptrVal); + *value = PointerToString(it->second.value.ptrVal); return true; case ParameterType_Userdata: - *value = String::Pointer(it->second.value.userdataVal->ptr); + *value = PointerToString(it->second.value.userdataVal->ptr); return true; case ParameterType_None: - *value = String(); + *value = std::string(); return true; } @@ -424,7 +440,7 @@ namespace Nz * * \see GetPointerParameter */ - bool ParameterList::GetUserdataParameter(const String& name, void** value) const + bool ParameterList::GetUserdataParameter(const std::string& name, void** value) const { NazaraAssert(value, "Invalid pointer"); @@ -437,9 +453,11 @@ namespace Nz return false; } - if (it->second.type == ParameterType_Userdata) + const auto& parameter = it->second; + + if (parameter.type == ParameterType_Userdata) { - *value = it->second.value.userdataVal->ptr; + *value = parameter.value.userdataVal->ptr; return true; } else @@ -455,7 +473,7 @@ namespace Nz * * \param name Name of the parameter */ - bool ParameterList::HasParameter(const String& name) const + bool ParameterList::HasParameter(const std::string& name) const { return m_parameters.find(name) != m_parameters.end(); } @@ -468,7 +486,7 @@ namespace Nz * * \param name Name of the parameter */ - void ParameterList::RemoveParameter(const String& name) + void ParameterList::RemoveParameter(const std::string& name) { auto it = m_parameters.find(name); if (it != m_parameters.end()) @@ -485,7 +503,7 @@ namespace Nz * * \param name Name of the parameter */ - void ParameterList::SetParameter(const String& name) + void ParameterList::SetParameter(const std::string& name) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_None; @@ -499,7 +517,7 @@ namespace Nz * \param name Name of the parameter * \param value The color value */ - void ParameterList::SetParameter(const String& name, const Color& value) + void ParameterList::SetParameter(const std::string& name, const Color& value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Color; @@ -515,7 +533,7 @@ namespace Nz * \param name Name of the parameter * \param value The string value */ - void ParameterList::SetParameter(const String& name, const String& value) + void ParameterList::SetParameter(const std::string& name, const std::string& value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_String; @@ -531,7 +549,7 @@ namespace Nz * \param name Name of the parameter * \param value The string value */ - void ParameterList::SetParameter(const String& name, const char* value) + void ParameterList::SetParameter(const std::string& name, const char* value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_String; @@ -547,7 +565,7 @@ namespace Nz * \param name Name of the parameter * \param value The boolean value */ - void ParameterList::SetParameter(const String& name, bool value) + void ParameterList::SetParameter(const std::string& name, bool value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Boolean; @@ -562,7 +580,7 @@ namespace Nz * \param name Name of the parameter * \param value The double value */ - void ParameterList::SetParameter(const String& name, double value) + void ParameterList::SetParameter(const std::string& name, double value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Double; @@ -577,7 +595,7 @@ namespace Nz * \param name Name of the parameter * \param value The integer value */ - void ParameterList::SetParameter(const String& name, long long value) + void ParameterList::SetParameter(const std::string& name, long long value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Integer; @@ -595,7 +613,7 @@ namespace Nz * \remark This sets a raw pointer, this class takes no responsibility toward it, if you wish to destroy the pointed variable along with the parameter list, you should set a userdata */ - void ParameterList::SetParameter(const String& name, void* value) + void ParameterList::SetParameter(const std::string& name, void* value) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Pointer; @@ -606,36 +624,39 @@ namespace Nz * \brief Gives a string representation * \return A string representation of the object: "ParameterList(Name: Type(value), ...)" */ - String ParameterList::ToString() const + std::string ParameterList::ToString() const { - StringStream ss; + std::ostringstream ss; + ss << std::boolalpha; ss << "ParameterList("; for (auto it = m_parameters.cbegin(); it != m_parameters.cend();) { + const auto& parameter = it->second; + ss << it->first << ": "; switch (it->second.type) { case ParameterType_Boolean: - ss << "Boolean(" << String::Boolean(it->second.value.boolVal) << ")"; + ss << "Boolean(" << parameter.value.boolVal << ")"; break; case ParameterType_Color: - ss << "Color(" << it->second.value.colorVal.ToString() << ")"; + ss << "Color(" << parameter.value.colorVal << ")"; break; case ParameterType_Double: - ss << "Double(" << it->second.value.doubleVal << ")"; + ss << "Double(" << parameter.value.doubleVal << ")"; break; case ParameterType_Integer: - ss << "Integer(" << it->second.value.intVal << ")"; + ss << "Integer(" << parameter.value.intVal << ")"; break; case ParameterType_String: - ss << "String(" << it->second.value.stringVal << ")"; + ss << "std::string(" << parameter.value.stringVal << ")"; break; case ParameterType_Pointer: - ss << "Pointer(" << String::Pointer(it->second.value.ptrVal) << ")"; + ss << "Pointer(" << parameter.value.ptrVal << ")"; break; case ParameterType_Userdata: - ss << "Userdata(" << String::Pointer(it->second.value.userdataVal->ptr) << ")"; + ss << "Userdata(" << parameter.value.userdataVal->ptr << ")"; break; case ParameterType_None: ss << "None"; @@ -647,7 +668,7 @@ namespace Nz } ss << ")"; - return ss; + return ss.str(); } /*! @@ -662,7 +683,7 @@ namespace Nz * \remark The destructor is called once when all copies of the userdata are destroyed, which means you can safely copy the parameter list around. */ - void ParameterList::SetParameter(const String& name, void* value, Destructor destructor) + void ParameterList::SetParameter(const std::string& name, void* value, Destructor destructor) { Parameter& parameter = CreateValue(name); parameter.type = ParameterType_Userdata; @@ -721,7 +742,7 @@ namespace Nz * * \remark The previous value if any gets destroyed */ - ParameterList::Parameter& ParameterList::CreateValue(const String& name) + ParameterList::Parameter& ParameterList::CreateValue(const std::string& name) { std::pair pair = m_parameters.insert(std::make_pair(name, Parameter())); Parameter& parameter = pair.first->second; @@ -742,7 +763,7 @@ namespace Nz switch (parameter.type) { case ParameterType_String: - parameter.value.stringVal.~String(); + PlacementDestroy(¶meter.value.stringVal); break; case ParameterType_Userdata: diff --git a/src/Nazara/Core/Posix/DynLibImpl.cpp b/src/Nazara/Core/Posix/DynLibImpl.cpp index 4e14fbf17..99b9c2f81 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.cpp +++ b/src/Nazara/Core/Posix/DynLibImpl.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index b340abde1..f1af9ebbe 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -159,7 +160,7 @@ namespace Nz break; default: - NazaraInternalError("Cursor position not handled (0x" + String::Number(pos, 16) + ')'); + NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')'); return false; } diff --git a/src/Nazara/Core/RefCounted.cpp b/src/Nazara/Core/RefCounted.cpp index cab4b2fac..69468eb29 100644 --- a/src/Nazara/Core/RefCounted.cpp +++ b/src/Nazara/Core/RefCounted.cpp @@ -37,7 +37,7 @@ namespace Nz { #if NAZARA_CORE_SAFE if (m_referenceCount > 0) - NazaraWarning("Resource destroyed while still referenced " + String::Number(m_referenceCount) + " time(s)"); + NazaraWarning("Resource destroyed while still referenced " + std::to_string(m_referenceCount) + " time(s)"); #endif } diff --git a/src/Nazara/Core/StdLogger.cpp b/src/Nazara/Core/StdLogger.cpp index 171139188..92602393b 100644 --- a/src/Nazara/Core/StdLogger.cpp +++ b/src/Nazara/Core/StdLogger.cpp @@ -60,9 +60,9 @@ namespace Nz * \see WriteError */ - void StdLogger::Write(const String& string) + void StdLogger::Write(const std::string_view& error) { - fputs(string.GetConstBuffer(), stdout); + fwrite(error.data(), sizeof(char), error.size(), stdout); fputc('\n', stdout); } @@ -78,9 +78,10 @@ namespace Nz * \see Write */ - void StdLogger::WriteError(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) + void StdLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { - fprintf(stderr, "%s: %s", errorType[type], error.GetConstBuffer()); + fprintf(stderr, "%s: ", errorType[type]); + fwrite(error.data(), sizeof(char), error.size(), stdout); if (line != 0 && file && function) fprintf(stderr, " (in %s at %s:%d)", function, file, line); diff --git a/src/Nazara/Core/Stream.cpp b/src/Nazara/Core/Stream.cpp index 5935a6ce3..7bf90a157 100644 --- a/src/Nazara/Core/Stream.cpp +++ b/src/Nazara/Core/Stream.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -147,22 +147,24 @@ namespace Nz * \param string String to write */ - bool Stream::Write(const String& string) + bool Stream::Write(const std::string_view& string) { - String temp(string); - if (m_streamOptions & StreamOption_Text) { - #if defined(NAZARA_PLATFORM_WINDOWS) - temp.Replace("\n", "\r\n"); - #elif defined(NAZARA_PLATFORM_LINUX) +#if defined(NAZARA_PLATFORM_WINDOWS) + std::string temp(string); + ReplaceStr(temp, "\n", "\r\n"); +#elif defined(NAZARA_PLATFORM_LINUX) + std::string_view temp(string); // Nothing to do - #elif defined(NAZARA_PLATFORM_MACOS) - temp.Replace('\n', '\r'); - #endif - } +#elif defined(NAZARA_PLATFORM_MACOS) + std::string temp(string); + ReplaceStr(temp, "\n", "\r"); +#endif - std::size_t size = temp.GetSize(); - return Write(temp.GetConstBuffer(), size) == size; + return Write(temp.data(), temp.size()) == temp.size(); + } + else + return Write(string.data(), string.size()) == string.size(); } } diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp deleted file mode 100644 index 054be149f..000000000 --- a/src/Nazara/Core/String.cpp +++ /dev/null @@ -1,6024 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -///TODO: Rewrite most of used algorithms (Reread to to line 4638) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace Detail - { - inline bool IsSpace(char32_t character) - { - return character == '\t' || Unicode::GetCategory(character) & Unicode::Category_Separator; - } - - // This algorithm is inspired by the documentation of Qt - inline std::size_t GetNewSize(std::size_t newSize) - { - if (newSize < 20) - return newSize+4; - else - { - if (newSize < (1 << 12)-12) - return GetNearestPowerOfTwo(newSize << 1)-12; - else - return newSize + (1 << 11); - } - } - - inline char ToLower(char character) - { - if (character >= 'A' && character <= 'Z') - return character + ('a' - 'A'); - else - return character; - } - - inline char ToUpper(char character) - { - if (character >= 'a' && character <= 'z') - return character + ('A' - 'a'); - else - return character; - } - - inline int Strcasecmp(const char* s1, const char* s2) - { - int ret = 0; - - while (((ret = static_cast(Detail::ToLower(*s1)) - static_cast(Detail::ToLower(*s2))) != 0) && *s2) - ++s1, ++s2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; - } - - inline int Unicodecasecmp(const char* s1, const char* s2) - { - int ret = 0; - utf8::unchecked::iterator it1(s1); - utf8::unchecked::iterator it2(s2); - - while (((ret = Unicode::GetLowercase(*it1) - Unicode::GetLowercase(*it2)) != 0) && *it2) - ++it1, ++it2; - - return ret != 0 ? (ret > 0 ? 1 : -1) : 0; - } - } - - /*! - * \ingroup core - * \class Nz::String - * \brief Core class that represents a string - */ - - /*! - * \brief Constructs a String object by default - */ - - String::String() : - m_sharedString(GetEmptyString()) - { - } - - /*! - * \brief Constructs a String object with a character - * - * \param character Single character - */ - - String::String(char character) - { - if (character != '\0') - { - m_sharedString = std::make_shared(1); - m_sharedString->string[0] = character; - } - else - m_sharedString = GetEmptyString(); - } - - /*! - * \brief Constructs a String object with multiple times the same character - * - * \param rep Number of repetitions of the character - * \param character Single character - */ - - String::String(std::size_t rep, char character) - { - if (rep > 0) - { - m_sharedString = std::make_shared(rep); - - if (character != '\0') - std::memset(m_sharedString->string.get(), character, rep); - } - else - m_sharedString = GetEmptyString(); - } - - /*! - * \brief Constructs a String object with multiple times the same string - * - * \param rep Number of repetitions of the string - * \param string String to multiply - */ - - String::String(std::size_t rep, const char* string) : - String(rep, string, (string) ? std::strlen(string) : 0) - { - } - - /*! - * \brief Constructs a String object with multiple times the same string - * - * \param rep Number of repetitions of the string - * \param string String to multiply - * \param length Length of the string - */ - - String::String(std::size_t rep, const char* string, std::size_t length) - { - std::size_t totalSize = rep*length; - - if (totalSize > 0) - { - m_sharedString = std::make_shared(totalSize); - - for (std::size_t i = 0; i < rep; ++i) - std::memcpy(&m_sharedString->string[i*length], string, length); - } - else - m_sharedString = GetEmptyString(); - } - - /*! - * \brief Constructs a String object with multiple times the same string - * - * \param rep Number of repetitions of the string - * \param string String to multiply - */ - - String::String(std::size_t rep, const String& string) : - String(rep, string.GetConstBuffer(), string.GetSize()) - { - } - - /*! - * \brief Constructs a String object with a "C string" - * - * \param string String to represent - */ - - String::String(const char* string) : - String(string, (string) ? std::strlen(string) : 0) - { - } - - /*! - * \brief Constructs a String object with a "C string" - * - * \param string String to represent - * \param length Length of the string - */ - - String::String(const char* string, std::size_t length) - { - if (length > 0) - { - m_sharedString = std::make_shared(length); - std::memcpy(m_sharedString->string.get(), string, length); - } - else - m_sharedString = GetEmptyString(); - } - - /*! - * \brief Constructs a String object which is a copy of another - * - * \param string String to copy - */ - - String::String(const std::string& string) : - String(string.data(), string.size()) - { - } - - /*! - * \brief Appends the character to the string - * \return A reference to this - * - * \param character Single character - * - * \see Insert - */ - - String& String::Append(char character) - { - return Insert(m_sharedString->size, character); - } - - /*! - * \brief Appends the "C string" to the string - * \return A reference to this - * - * \param string String to add - * - * \see Insert - */ - - String& String::Append(const char* string) - { - return Insert(m_sharedString->size, string); - } - - /*! - * \brief Appends the "C string" to the string - * \return A reference to this - * - * \param string String to add - * \param length Size of the string - * - * \see Insert - */ - - String& String::Append(const char* string, std::size_t length) - { - return Insert(m_sharedString->size, string, length); - } - - /*! - * \brief Appends the string to the string - * \return A reference to this - * - * \param string String to add - * - * \see Insert - */ - - String& String::Append(const String& string) - { - return Insert(m_sharedString->size, string); - } - - /*! - * \brief Clears the content of the string - * - * \param keepBuffer Should the buffer be kept - */ - - void String::Clear(bool keepBuffer) - { - if (keepBuffer) - { - EnsureOwnership(true); - m_sharedString->size = 0; - } - else - ReleaseString(); - } - - /*! - * \brief Checks whether the string contains the character - * \return true if found in the string - * - * \param character Single character - * \param start Index to begin the research - * \param flags Flag for the look up - * - * \see Find - */ - - bool String::Contains(char character, std::intmax_t start, UInt32 flags) const - { - return Find(character, start, flags) != npos; - } - - /*! - * \brief Checks whether the string contains the "C string" - * \return true if found in the string - * - * \param string String to search - * \param start Index to begin the research - * \param flags Flag for the look up - * - * \see Find - */ - - bool String::Contains(const char* string, std::intmax_t start, UInt32 flags) const - { - return Find(string, start, flags) != npos; - } - - /*! - * \brief Checks whether the string contains the string - * \return true if found in the string - * - * \param string String to search - * \param start Index to begin the research - * \param flags Flag for the look up - * - * \see Find - */ - - bool String::Contains(const String& string, std::intmax_t start, UInt32 flags) const - { - return Find(string, start, flags) != npos; - } - - /*! - * \brief Counts the number of occurrences in the string - * \return Number of occurrences - * - * \param character Single character - * \param start Index to begin the research - * \param flags Flag for the look up - */ - - unsigned int String::Count(char character, std::intmax_t start, UInt32 flags) const - { - if (character == '\0' || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - char character_lower = Detail::ToLower(character); - char character_upper = Detail::ToUpper(character); - do - { - if (*str == character_lower || *str == character_upper) - count++; - } - while (*++str); - } - else - { - while ((str = std::strchr(str, character)) != nullptr) - { - count++; - str++; - } - } - - return count; - } - - /*! - * \brief Counts the number of occurrences in the string - * \return Number of occurrences - * - * \param string String to count - * \param start Index to begin the research - * \param flags Flag for the look up - */ - - unsigned int String::Count(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - ++it; - - utf8::unchecked::iterator it2(t); - for (;;) - { - if (*it2 == '\0') - { - count++; - break; - } - - if (*it == '\0') - return count; - - if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = Detail::ToLower(string[0]); - do - { - if (Detail::ToLower(*str) == c) - { - str++; - - const char* ptr = &string[1]; - for (;;) - { - if (*ptr == '\0') - { - count++; - break; - } - - if (*str == '\0') - return count; - - if (Detail::ToLower(*str) != Detail::ToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - while ((str = std::strstr(str, string)) != nullptr) - { - count++; - str++; - } - } - - return count; - } - - /*! - * \brief Counts the number of occurrences in the string - * \return Number of occurrences - * - * \param string String to count - * \param start Index to begin the research - * \param flags Flag for the look up - */ - - unsigned int String::Count(const String& string, std::intmax_t start, UInt32 flags) const - { - return Count(string.GetConstBuffer(), start, flags); - } - - /*! - * \brief Counts the number of occurrences of any characters in the list in the string - * \return Number of occurrences - * - * \param string String to match - * \param start Index to begin the research - * \param flags Flag for the look up - */ - - unsigned int String::CountAny(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - char* str = &m_sharedString->string[pos]; - unsigned int count = 0; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (Unicode::GetLowercase(*it) == Unicode::GetLowercase(*it2)) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - { - count++; - break; - } - } - while (*++it2); - } - while (*++str); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - do - { - if (Detail::ToLower(*str) == Detail::ToLower(*c)) - { - count++; - break; - } - } - while (*++c); - } - while (*++str); - } - else - { - while ((str = std::strpbrk(str, string)) != nullptr) - { - count++; - str++; - } - } - } - - return count; - } - - /*! - * \brief Counts the number of occurrences of any characters in the list in the string - * \return Number of occurrences - * - * \param string String to match - * \param start Index to begin the research - * \param flags Flag for the look up - */ - - unsigned int String::CountAny(const String& string, std::intmax_t start, UInt32 flags) const - { - return CountAny(string.GetConstBuffer(), start, flags); - } - - /*! - * \brief Checks whether the string ends with the character - * \return true if it the case - * - * \param character Single character - * \param flags Flag for the look up - * - * \see StartsWith - */ - - bool String::EndsWith(char character, UInt32 flags) const - { - if (m_sharedString->size == 0) - return 0; - - if (flags & CaseInsensitive) - return Detail::ToLower(m_sharedString->string[m_sharedString->size-1]) == Detail::ToLower(character); - else - return m_sharedString->string[m_sharedString->size-1] == character; // character == '\0' will always be false - } - - /*! - * \brief Checks whether the string ends with the "C string" - * \return true if it the case - * - * \param string String to match - * \param flags Flag for the look up - * - * \see StartsWith - */ - - bool String::EndsWith(const char* string, UInt32 flags) const - { - return EndsWith(string, std::strlen(string), flags); - } - - /*! - * \brief Checks whether the string ends with the "C string" - * \return true if it the case - * - * \param string String to match - * \param length Size of the string - * \param flags Flag for the look up - * - * \see StartsWith - */ - - bool String::EndsWith(const char* string, std::size_t length, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0 || length > m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - return Detail::Unicodecasecmp(&m_sharedString->string[m_sharedString->size - length], string) == 0; - else - return Detail::Strcasecmp(&m_sharedString->string[m_sharedString->size - length], string) == 0; - } - else - return std::strcmp(&m_sharedString->string[m_sharedString->size - length], string) == 0; - } - - /*! - * \brief Checks whether the string ends with the string - * \return true if it the case - * - * \param string String to match - * \param flags Flag for the look up - * - * \see StartsWith - */ - - bool String::EndsWith(const String& string, UInt32 flags) const - { - return EndsWith(string.GetConstBuffer(), string.m_sharedString->size, flags); - } - - /*! - * \brief Finds the first index of the character in the string - * \return Index in the string - * - * \param character Single character - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::Find(char character, std::intmax_t start, UInt32 flags) const - { - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - if (flags & CaseInsensitive) - { - char ch = Detail::ToLower(character); - const char* str = m_sharedString->string.get(); - do - { - if (Detail::ToLower(*str) == ch) - return str - m_sharedString->string.get(); - } - while (*++str); - - return npos; - } - else - { - char* ch = std::strchr(&m_sharedString->string[pos], character); - if (ch) - return ch - m_sharedString->string.get(); - else - return npos; - } - } - - /*! - * \brief Finds the first index of the "C string" in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::Find(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - const char* t = string; - char32_t c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - const char* ptrPos = it.base(); - ++it; - - utf8::unchecked::iterator it2(t); - for (;;) - { - if (*it2 == '\0') - return ptrPos - m_sharedString->string.get(); - - if (*it == '\0') - return npos; - - if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) - break; - - ++it; - ++it2; - } - } - } - while (*++it); - } - else - { - char c = Detail::ToLower(string[0]); - do - { - if (Detail::ToLower(*str) == c) - { - char* ptrPos = str; - str++; - - const char* ptr = &string[1]; - for (;;) - { - if (*ptr == '\0') - return ptrPos - m_sharedString->string.get(); - - if (*str == '\0') - return npos; - - if (Detail::ToLower(*str) != Detail::ToLower(*ptr)) - break; - - ptr++; - str++; - } - } - } - while (*++str); - } - } - else - { - char* ch = std::strstr(&m_sharedString->string[pos], string); - if (ch) - return ch - m_sharedString->string.get(); - } - - return npos; - } - - /*! - * \brief Finds the first index of the string in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::Find(const String& string, std::intmax_t start, UInt32 flags) const - { - return Find(string.GetConstBuffer(), start, flags); - } - - /*! - * \brief Finds the first index of any characters in the list in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindAny(const char* string, std::intmax_t start, UInt32 flags) const - { - if (m_sharedString->size == 0 || !string || !string[0]) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = Unicode::GetLowercase(*it); - do - { - if (character == Unicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string.get(); - } - while (*++it2); - } - while (*++it); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string.get(); - } - while (*++it2); - } - while (*++it); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = Detail::ToLower(*str); - do - { - if (character == Detail::ToLower(*c)) - return str - m_sharedString->string.get(); - } - while (*++c); - } - while (*++str); - } - else - { - str = std::strpbrk(str, string); - if (str) - return str - m_sharedString->string.get(); - } - } - - return npos; - } - - /*! - * \brief Finds the first index of any characters in the list in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindAny(const String& string, std::intmax_t start, UInt32 flags) const - { - return FindAny(string.GetConstBuffer(), start, flags); - } - - /*! - * \brief Finds the last index of the character in the string - * \return Index in the string - * - * \param character Single character - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLast(char character, std::intmax_t start, UInt32 flags) const - { - if (character == '\0' || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = &m_sharedString->string[pos]; - - if (flags & CaseInsensitive) - { - character = Detail::ToLower(character); - do - { - if (Detail::ToLower(*ptr) == character) - return ptr - m_sharedString->string.get(); - } - while (ptr-- != m_sharedString->string.get()); - } - else - { - do - { - if (*ptr == character) - return ptr - m_sharedString->string.get(); - } - while (ptr-- != m_sharedString->string.get()); - } - - return npos; - } - - /*! - * \brief Finds the last index of the "C string" in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLast(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 1.FindLast#3 (Size of the pattern unknown) - const char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have one pointer pointing to the begin of the character - - utf8::unchecked::iterator it(ptr); - const char* t = string; - char32_t c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - for (;;) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string.get(); - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string.get()); - } - else - { - char c = Detail::ToLower(string[0]); - do - { - if (Detail::ToLower(*ptr) == c) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - return ptr - m_sharedString->string.get(); - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (Detail::ToLower(*tPtr) != Detail::ToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string.get()); - } - } - else - { - do - { - if (*ptr == string[0]) - { - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - return ptr - m_sharedString->string.get(); - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string.get()); - } - - return npos; - } - - /*! - * \brief Finds the last index of the string in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLast(const String& string, std::intmax_t start, UInt32 flags) const - { - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size || string.m_sharedString->size > m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - ///Algo 1.FindLast#3 (Iterator non-adapted) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have one pointer pointing to the begin of the character - - utf8::unchecked::iterator it(ptr); - const char* t = string.GetConstBuffer(); - char32_t c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - utf8::unchecked::iterator it2(t); - utf8::unchecked::iterator tIt(it); - ++tIt; - - for (;;) - { - if (*it2 == '\0') - return it.base() - m_sharedString->string.get(); - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*it2)) - break; - - ++it2; - ++tIt; - } - } - } - while (it--.base() != limit); - } - else - { - ///Algo 1.FindLast#4 (Size of the pattern unknown) - char c = Detail::ToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - for (;;) - { - if (Detail::ToLower(*ptr) == c) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (Detail::ToLower(*ptr) != Detail::ToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string.get(); - - if (ptr == m_sharedString->string.get()) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - } - else - { - ///Algo 1.FindLast#4 (Size of the pattern known) - for (;;) - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - return ptr-m_sharedString->string.get(); - - if (ptr == m_sharedString->string.get()) - return npos; - } - } - else if (ptr-- <= limit) - break; - } - } - - return npos; - } - - /*! - * \brief Finds the last index of any characters in the list in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLastAny(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* str = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - while (utf8::internal::is_trail(*str)) - str++; - - utf8::unchecked::iterator it(str); - - if (flags & CaseInsensitive) - { - do - { - utf8::unchecked::iterator it2(string); - char32_t character = Unicode::GetLowercase(*it); - do - { - if (character == Unicode::GetLowercase(*it2)) - return it.base() - m_sharedString->string.get(); - } - while (*++it2); - } - while (it--.base() != m_sharedString->string.get()); - } - else - { - do - { - utf8::unchecked::iterator it2(string); - do - { - if (*it == *it2) - return it.base() - m_sharedString->string.get(); - } - while (*++it2); - } - while (it--.base() != m_sharedString->string.get()); - } - } - else - { - if (flags & CaseInsensitive) - { - do - { - const char* c = string; - char character = Detail::ToLower(*str); - do - { - if (character == Detail::ToLower(*c)) - return str - m_sharedString->string.get(); - } - while (*++c); - } - while (str-- != m_sharedString->string.get()); - } - else - { - do - { - const char* c = string; - do - { - if (*str == *c) - return str - m_sharedString->string.get(); - } - while (*++c); - } - while (str-- != m_sharedString->string.get()); - } - } - - return npos; - } - - /*! - * \brief Finds the last index of any characters in the list in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLastAny(const String& string, std::intmax_t start, UInt32 flags) const - { - return FindLastAny(string.GetConstBuffer(), start, flags); - } - - /*! - * \brief Finds the last word in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLastWord(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 2.FindLastWord#1 (Size of the pattern unknown) - const char* ptr = &m_sharedString->string[pos]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have a pointer pointing to the beginning of the string - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*tIt)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string.get()); - } - else - { - const char* t = string; // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*tIt)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string.get()); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = Detail::ToLower(string[0]); - do - { - if (Detail::ToLower(*ptr) == c) - { - if (ptr != m_sharedString->string.get()) - { - --ptr; - if (!Detail::IsSpace(*ptr++)) - continue; - } - - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - { - if (*tPtr == '\0' || Detail::IsSpace(*tPtr)) - return ptr-m_sharedString->string.get(); - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (Detail::ToLower(*tPtr) != Detail::ToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string.get()); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string.get()) - { - --ptr; - if (!Detail::IsSpace(*ptr++)) - continue; - } - - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - { - if (*tPtr == '\0' || Detail::IsSpace(*tPtr)) - return ptr-m_sharedString->string.get(); - else - break; - } - - if (tPtr > &m_sharedString->string[pos]) - break; - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (ptr-- != m_sharedString->string.get()); - } - } - - return npos; - } - - /*! - * \brief Finds the last word in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindLastWord(const String& string, std::intmax_t start, UInt32 flags) const - { - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - const char* ptr = &m_sharedString->string[pos]; - const char* limit = &m_sharedString->string[string.m_sharedString->size-1]; - - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have a pointer pointing to the beginning of the string - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - do - { - if (Unicode::GetLowercase(*it) == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*tIt)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string.get()); - } - else - { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = utf8::unchecked::next(t); - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*tIt)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (tIt.base() > &m_sharedString->string[pos]) - break; - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (it--.base() != m_sharedString->string.get()); - } - } - else - { - ///Algo 2.FindLastWord#2 (Size of the pattern known) - if (flags & CaseInsensitive) - { - char c = Detail::ToLower(string.m_sharedString->string[string.m_sharedString->size-1]); - do - { - if (Detail::ToLower(*ptr) == c) - { - char nextC = *(ptr + 1); - if (nextC != '\0' && (Detail::IsSpace(nextC)) == 0) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (Detail::ToLower(*ptr) != Detail::ToLower(*p)) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string.get() || Detail::IsSpace(*(ptr-1))) - return ptr-m_sharedString->string.get(); - else - break; - } - - if (ptr == m_sharedString->string.get()) - return npos; - } - } - } - while (ptr-- > limit); - } - else - { - do - { - if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) - { - char nextC = *(ptr + 1); - if (nextC != '\0' && !Detail::IsSpace(nextC)) - continue; - - const char* p = &string.m_sharedString->string[string.m_sharedString->size-1]; - for (; p >= &string.m_sharedString->string[0]; --p, --ptr) - { - if (*ptr != *p) - break; - - if (p == &string.m_sharedString->string[0]) - { - if (ptr == m_sharedString->string.get() || Detail::IsSpace(*(ptr - 1))) - return ptr-m_sharedString->string.get(); - else - break; - } - - if (ptr == m_sharedString->string.get()) - return npos; - } - } - } - while (ptr-- > limit); - } - } - - return npos; - } - - /*! - * \brief Finds the first word in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindWord(const char* string, std::intmax_t start, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - ///Algo 3.FindWord#3 (Size of the pattern unknown) - const char* ptr = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have one pointer pointing to the begin of the character - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string; // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*it++)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (*++ptr); - } - else - { - const char* t = string; // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*it++)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (*++ptr); - } - } - else - { - if (flags & CaseInsensitive) - { - char c = Detail::ToLower(string[0]); - do - { - if (Detail::ToLower(*ptr) == c) - { - if (ptr != m_sharedString->string.get() && !Detail::IsSpace(*(ptr - 1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - { - if (*tPtr == '\0' || Detail::IsSpace(*tPtr)) - return ptr - m_sharedString->string.get(); - else - break; - } - - if (Detail::ToLower(*tPtr) != Detail::ToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - do - { - if (*ptr == string[0]) - { - if (ptr != m_sharedString->string.get() && !Detail::IsSpace(*(ptr-1))) - continue; - - const char* p = &string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - { - if (*tPtr == '\0' || Detail::IsSpace(*tPtr)) - return ptr - m_sharedString->string.get(); - else - break; - } - - if (*tPtr != *p) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - } - - return npos; - } - - /*! - * \brief Finds the first word in the string - * \return Index in the string - * - * \param string String to match - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::FindWord(const String& string, std::intmax_t start, UInt32 flags) const - { - if (string.m_sharedString->size == 0 || string.m_sharedString->size > m_sharedString->size) - return npos; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - char* ptr = &m_sharedString->string[pos]; - if (flags & HandleUtf8) - { - ///Algo 3.FindWord#3 (Iterator too slow for #2) - if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // We ensure to have one pointer pointing to the begin of the character - - utf8::unchecked::iterator it(ptr); - - if (flags & CaseInsensitive) - { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*it++)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*p)) - break; - - ++p; - ++tIt; - } - } - } - while (*++ptr); - } - else - { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument - UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); - - do - { - if (*it == c) - { - if (it.base() != m_sharedString->string.get()) - { - --it; - if (!Detail::IsSpace(*it++)) - continue; - } - - utf8::unchecked::iterator p(t); - utf8::unchecked::iterator tIt = it; - ++tIt; - - for (;;) - { - if (*p == '\0') - { - if (*tIt == '\0' || Detail::IsSpace(*it++)) - return it.base() - m_sharedString->string.get(); - else - break; - } - - if (*tIt != *p) - break; - - ++p; - ++tIt; - } - } - } - while (*++ptr); - } - } - else - { - ///Algo 3.FindWord#2 (Size of the pattern known) - if (flags & CaseInsensitive) - { - char c = Detail::ToLower(string.m_sharedString->string[0]); - do - { - if (Detail::ToLower(*ptr) == c) - { - if (ptr != m_sharedString->string.get() && !Detail::IsSpace(*(ptr-1))) - continue; - - const char* p = &string.m_sharedString->string[1]; - const char* tPtr = ptr+1; - for (;;) - { - if (*p == '\0') - { - if (*tPtr == '\0' || Detail::IsSpace(*tPtr)) - return ptr - m_sharedString->string.get(); - else - break; - } - - if (Detail::ToLower(*tPtr) != Detail::ToLower(*p)) - break; - - p++; - tPtr++; - } - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strstr(ptr, string.GetConstBuffer())) != nullptr) - { - // If the word is really alone - if ((ptr == m_sharedString->string.get() || Detail::IsSpace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || Detail::IsSpace(*(ptr+m_sharedString->size)))) - return ptr - m_sharedString->string.get(); - - ptr++; - } - } - } - - return npos; - } - - /*! - * \brief Gets the raw buffer - * \return Raw buffer - */ - - char* String::GetBuffer() - { - EnsureOwnership(); - - return m_sharedString->string.get(); - } - - /*! - * \brief Gets the capacity of the string - * \return Capacity of the string - */ - - std::size_t String::GetCapacity() const - { - return m_sharedString->capacity; - } - - /*! - * \brief Gets the index where a character begin - * - * Iterate through the string to find the starting position of a specific character index - * This is useful because non-ASCII characters may be encoded using multiple bytes. - * - * \param characterIndex Index of the character to search for - * - * \return Starting index - */ - std::size_t String::GetCharacterPosition(std::size_t characterIndex) const - { - const char* ptr = m_sharedString->string.get(); - const char* end = &m_sharedString->string[m_sharedString->size]; - - try - { - utf8::advance(ptr, characterIndex, end); - - return ptr - m_sharedString->string.get(); - } - catch (utf8::not_enough_room& /*e*/) - { - // Returns npos - } - catch (utf8::exception& e) - { - NazaraError("UTF-8 error: " + String(e.what())); - } - catch (std::exception& e) - { - NazaraError(e.what()); - } - - return npos; - } - - /*! - * \brief Gets the raw buffer - * \return Raw buffer - */ - - const char* String::GetConstBuffer() const - { - return m_sharedString->string.get(); - } - - /*! - * \brief Gets the length of the string - * \return Length of the string with UTF-8 awareness - */ - - std::size_t String::GetLength() const - { - return utf8::distance(m_sharedString->string.get(), &m_sharedString->string[m_sharedString->size]); - } - - /*! - * \brief Gets the size of the string - * \return Size of the string without UTF-8 awareness - */ - - std::size_t String::GetSize() const - { - return m_sharedString->size; - } - - /*! - * \brief Gets the std::string corresponding - * \return String in UTF-8 - */ - - std::string String::GetUtf8String() const - { - return std::string(m_sharedString->string.get(), m_sharedString->size); - } - - /*! - * \brief Gets the std::string corresponding - * \return String in UTF-16 - */ - - std::u16string String::GetUtf16String() const - { - if (m_sharedString->size == 0) - return std::u16string(); - - std::u16string str; - str.reserve(m_sharedString->size); - - utf8::utf8to16(begin(), end(), std::back_inserter(str)); - - return str; - } - - /*! - * \brief Gets the std::string corresponding - * \return String in UTF-32 - */ - - std::u32string String::GetUtf32String() const - { - if (m_sharedString->size == 0) - return std::u32string(); - - std::u32string str; - str.reserve(m_sharedString->size); - - utf8::utf8to32(begin(), end(), std::back_inserter(str)); - - return str; - } - - /*! - * \brief Gets the std::wstring corresponding - * \return String in Wide - */ - - std::wstring String::GetWideString() const - { - static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "wchar_t size is not supported"); - if (m_sharedString->size == 0) - return std::wstring(); - - std::wstring str; - str.reserve(m_sharedString->size); - - if (sizeof(wchar_t) == 4) // I want a static_if :( - utf8::utf8to32(begin(), end(), std::back_inserter(str)); - else - { - utf8::unchecked::iterator it(m_sharedString->string.get()); - do - { - char32_t cp = *it; - if (cp <= 0xFFFF && (cp < 0xD800 || cp > 0xDFFF)) // @Laurent Gomila - str.push_back(static_cast(cp)); - else - str.push_back(L'?'); - } - while (*it++); - } - - return str; - } - - /*! - * \brief Gets the word until next separator - * \return Word string - * - * \param index Index to begin the search - * \param flags Flag for the look up - */ - - String String::GetWord(unsigned int index, UInt32 flags) const - { - std::size_t startPos = GetWordPosition(index, flags); - if (startPos == npos) - return String(); - - std::intmax_t endPos = -1; - const char* ptr = &m_sharedString->string[startPos]; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (Detail::IsSpace(*it)) - { - endPos = static_cast(it.base() - m_sharedString->string.get() - 1); - break; - } - } - while (*++it); - } - else - { - do - { - if (Detail::IsSpace(*ptr)) - { - endPos = static_cast(ptr - m_sharedString->string.get() - 1); - break; - } - } - while (*++ptr); - } - - return SubString(startPos, endPos); - } - - /*! - * \brief Gets the word position - * \return Position of the beginning of the word - * - * \param index Index to begin the search - * \param flags Flag for the look up - */ - - std::size_t String::GetWordPosition(unsigned int index, UInt32 flags) const - { - if (m_sharedString->size == 0) - return npos; - - unsigned int currentWord = 0; - bool inWord = false; - - const char* ptr = m_sharedString->string.get(); - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (Detail::IsSpace(*it)) - inWord = false; - else - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return it.base() - m_sharedString->string.get(); - } - } - } - while (*++it); - } - else - { - do - { - if (Detail::IsSpace(*ptr)) - inWord = false; - else - { - if (!inWord) - { - inWord = true; - if (++currentWord > index) - return ptr - m_sharedString->string.get(); - } - } - } - while (*++ptr); - } - - return npos; - } - - /*! - * \brief Inserts the character into the string - * \return A reference to this - * - * \param pos Position in the string - * \param character Single character - */ - - String& String::Insert(std::intmax_t pos, char character) - { - return Insert(pos, &character, 1); - } - - /*! - * \brief Inserts the "C string" into the string - * \return A reference to this - * - * \param pos Position in the string - * \param string String to add - */ - - String& String::Insert(std::intmax_t pos, const char* string) - { - return Insert(pos, string, std::strlen(string)); - } - - /*! - * \brief Inserts the "C string" into the string - * \return A reference to this - * - * \param pos Position in the string - * \param string String to add - * \param length Size of the string - */ - - String& String::Insert(std::intmax_t pos, const char* string, std::size_t length) - { - if (length == 0) - return *this; - - if (pos < 0) - pos = std::max(m_sharedString->size + pos, 0); - - std::size_t start = std::min(pos, m_sharedString->size); - - // If buffer is already big enough - if (m_sharedString->capacity >= m_sharedString->size + length) - { - EnsureOwnership(); - - std::memmove(&m_sharedString->string[start+length], &m_sharedString->string[start], m_sharedString->size - start); - std::memcpy(&m_sharedString->string[start], string, length); - - m_sharedString->size += length; - m_sharedString->string[m_sharedString->size] = '\0'; - } - else - { - auto newString = std::make_shared(m_sharedString->size + length); - - char* ptr = newString->string.get(); - - if (start > 0) - { - std::memcpy(ptr, m_sharedString->string.get(), start*sizeof(char)); - ptr += start; - } - - std::memcpy(ptr, string, length*sizeof(char)); - ptr += length; - - if (m_sharedString->size > start) - std::memcpy(ptr, &m_sharedString->string[start], m_sharedString->size - start); - - m_sharedString = std::move(newString); - } - - return *this; - } - - /*! - * \brief Inserts the string into the string - * \return A reference to this - * - * \param pos Position in the string - * \param string String to add - */ - - String& String::Insert(std::intmax_t pos, const String& string) - { - return Insert(pos, string.GetConstBuffer(), string.m_sharedString->size); - } - - /*! - * \brief Checks whether the string is empty - * \return true if string is empty - */ - - bool String::IsEmpty() const - { - return m_sharedString->size == 0; - } - - /*! - * \brief Checks whether the string is null - * \return true if string is null - */ - - bool String::IsNull() const - { - return m_sharedString.get() == GetEmptyString().get(); - } - - /*! - * \brief Checks whether the string is a number - * \return true if string is a number - * - * \param base Base of the number - * \param flags Flag for the look up - * - * \remark Produces a NazaraError if base is not in [2, 36( with NAZARA_CORE_SAFE defined - */ - - bool String::IsNumber(UInt8 base, UInt32 flags) const - { - #if NAZARA_CORE_SAFE - if (base < 2 || base > 36) - { - NazaraError("Base must be between 2 and 36"); - return false; - } - #endif - - if (m_sharedString->size == 0) - return false; - - String check = Simplified(); - if (check.m_sharedString->size == 0) - return false; - - char* ptr = (check.m_sharedString->string[0] == '-') ? &check.m_sharedString->string[1] : check.m_sharedString->string.get(); - - if (base > 10) - { - if (flags & CaseInsensitive) - { - char limitLower = 'a' + base-10 - 1; - char limitUpper = 'A' + base-10 - 1; - - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'A') || (c > limitUpper && c < 'a') || c > limitLower)) - return false; - } - while (*++ptr); - } - else - { - char limit = 'a' + base-10 - 1; - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || (c > '9' && c < 'a') || c > limit)) - return false; - } - while (*++ptr); - } - } - else - { - char limit = '0' + base - 1; - - do - { - char c = *ptr; - if (c != ' ' && (c < '0' || c > limit)) - return false; - } - while (*++ptr); - } - - return true; - } - - /*! - * \brief Checks whether the string matches the pattern - * \return true if string matches - * - * \param pattern Pattern to search - */ - - bool String::Match(const char* pattern) const - { - if (m_sharedString->size == 0 || !pattern) - return false; - - // Par Jack Handy - akkhandy@hotmail.com - // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing - const char* str = m_sharedString->string.get(); - while (*str && *pattern != '*') - { - if (*pattern != *str && *pattern != '?') - return false; - - pattern++; - str++; - } - - const char* cp = nullptr; - const char* mp = nullptr; - while (*str) - { - if (*pattern == '*') - { - if (!*++pattern) - return true; - - mp = pattern; - cp = str+1; - } - else if (*pattern == *str || *pattern == '?') - { - pattern++; - str++; - } - else - { - pattern = mp; - str = cp++; - } - } - - while (*pattern == '*') - pattern++; - - return !*pattern; - } - - /*! - * \brief Checks whether the string matches the pattern - * \return true if string matches - * - * \param pattern Pattern to search - */ - - bool String::Match(const String& pattern) const - { - return Match(pattern.m_sharedString->string.get()); - } - - /*! - * \brief Prepends the character to the string - * \return A reference to this - * - * \param character Single character - * - * \see Insert - */ - - String& String::Prepend(char character) - { - return Insert(0, character); - } - - /*! - * \brief Prepends the "C string" to the string - * \return A reference to this - * - * \param string String to add - * - * \see Insert - */ - - String& String::Prepend(const char* string) - { - return Insert(0, string); - } - - /*! - * \brief Prepends the "C string" to the string - * \return A reference to this - * - * \param string String to add - * \param length Size of the string - * - * \see Insert - */ - - String& String::Prepend(const char* string, std::size_t length) - { - return Insert(0, string, length); - } - - /*! - * \brief Prepends the string to the string - * \return A reference to this - * - * \param string String to add - * - * \see Insert - */ - - String& String::Prepend(const String& string) - { - return Insert(0, string); - } - - /*! - * \brief Replaces the old character by the new one - * \return Number of changes - * - * \param oldCharacter Pattern to find - * \param newCharacter Pattern to change for - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - unsigned int String::Replace(char oldCharacter, char newCharacter, std::intmax_t start, UInt32 flags) - { - if (oldCharacter == '\0' || oldCharacter == newCharacter) - return 0; - - if (newCharacter == '\0') // In this case, we must use a more advanced algorithm - return Replace(String(oldCharacter), String(), start); - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - bool found = false; - if (flags & CaseInsensitive) - { - char character_lower = Detail::ToLower(oldCharacter); - char character_upper = Detail::ToUpper(oldCharacter); - do - { - if (*ptr == character_lower || *ptr == character_upper) - { - if (!found) - { - std::ptrdiff_t offset = ptr - m_sharedString->string.get(); - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - while (*++ptr); - } - else - { - while ((ptr = std::strchr(ptr, oldCharacter)) != nullptr) - { - if (!found) - { - std::ptrdiff_t offset = ptr-m_sharedString->string.get(); - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = newCharacter; - ++count; - } - } - - return count; - } - - /*! - * \brief Replaces the old "C string" by the new one - * \return Number of changes - * - * \param oldString Pattern to find - * \param replaceString Pattern to change for - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - unsigned int String::Replace(const char* oldString, const char* replaceString, std::intmax_t start, UInt32 flags) - { - return Replace(oldString, std::strlen(oldString), replaceString, std::strlen(replaceString), start, flags); - } - - /*! - * \brief Replaces the old "C string" by the new one - * \return Number of changes - * - * \param oldString Pattern to find - * \param oldLength Length of the old string - * \param replaceString Pattern to change for - * \param replaceLength of the new string - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - unsigned int String::Replace(const char* oldString, std::size_t oldLength, const char* replaceString, std::size_t replaceLength, std::intmax_t start, UInt32 flags) - { - if (oldLength == 0) - return 0; - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return 0; - - unsigned int count = 0; - if (oldLength == replaceLength) - { - bool found = false; - - // If no size change is necessary, we can thus use a quicker algorithm - while ((pos = Find(oldString, pos, flags)) != npos) - { - if (!found) - { - EnsureOwnership(); - found = true; - } - - std::memcpy(&m_sharedString->string[pos], replaceString, oldLength); - pos += oldLength; - - ++count; - } - } - else ///TODO: Replacement algorithm without changing the buffer (if replaceLength < oldLength) - { - std::size_t newSize = m_sharedString->size + Count(oldString)*(replaceLength - oldLength); - if (newSize == m_sharedString->size) // Then it's the fact that Count(oldString) == 0 - return 0; - - auto newString = std::make_shared(newSize); - - ///Algo 4.Replace#2 - char* ptr = newString->string.get(); - const char* p = m_sharedString->string.get(); - - while ((pos = Find(oldString, pos, flags)) != npos) - { - const char* r = &m_sharedString->string[pos]; - - std::memcpy(ptr, p, r-p); - ptr += r-p; - std::memcpy(ptr, replaceString, replaceLength); - ptr += replaceLength; - p = r+oldLength; - pos += oldLength; - - count++; - } - - std::strcpy(ptr, p); - - m_sharedString = std::move(newString); - } - - return count; - } - - /*! - * \brief Replaces the old string by the new one - * \return Number of changes - * - * \param oldString Pattern to find - * \param replaceString Pattern to change for - * \param start Index to begin the search - * \param flags Flag for the look up - */ - - unsigned int String::Replace(const String& oldString, const String& replaceString, std::intmax_t start, UInt32 flags) - { - return Replace(oldString.GetConstBuffer(), oldString.m_sharedString->size, replaceString.GetConstBuffer(), replaceString.m_sharedString->size, start, flags); - } - - /*! - * \brief Replaces the old characters in the list by the new one - * \return Number of changes - * - * \param oldCharacters Pattern to find - * \param replaceCharacter Pattern to change for - * \param start Index to begin the search - * \param flags Flag for the look up - * - * \remark Does not handle UTF-8 currently - */ - - unsigned int String::ReplaceAny(const char* oldCharacters, char replaceCharacter, std::intmax_t start, UInt32 flags) - { - ///FIXME: Does not handle UTF-8 - if (!oldCharacters || !oldCharacters[0]) - return 0; - - /*if (replaceCharacter == '\0') // In this case, we must use a more advance algorithm - return ReplaceAny(String(oldCharacters), String(), start);*/ - - if (start < 0) - start = std::max(m_sharedString->size + start, 0); - - std::size_t pos = static_cast(start); - if (pos >= m_sharedString->size) - return npos; - - unsigned int count = 0; - char* ptr = &m_sharedString->string[pos]; - if (flags & CaseInsensitive) - { - do - { - const char* c = oldCharacters; - char character = Detail::ToLower(*ptr); - bool found = false; - do - { - if (character == Detail::ToLower(*c)) - { - if (!found) - { - std::ptrdiff_t offset = ptr - m_sharedString->string.get(); - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr = replaceCharacter; - ++count; - break; - } - } - while (*++c); - } - while (*++ptr); - } - else - { - bool found = false; - while ((ptr = std::strpbrk(ptr, oldCharacters)) != nullptr) - { - if (!found) - { - std::ptrdiff_t offset = ptr - m_sharedString->string.get(); - - EnsureOwnership(); - - ptr = &m_sharedString->string[offset]; - found = true; - } - - *ptr++ = replaceCharacter; - ++count; - } - } - - return count; - } - /* - unsigned int String::ReplaceAny(const char* oldCharacters, const char* replaceString, std::intmax_t start, UInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - unsigned int oSize = (oldCharacters) ? std::strlen(oldCharacters) : 0; - unsigned int rSize = (replaceString) ? std::strlen(replaceString) : 0; - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oSize == 0) - return 0; - - unsigned int count = 0; - - if (rSize == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - f or (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oSize; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = replaceString[0]; - ++count; - - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*rSize; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oSize; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < rSize; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } - - unsigned int String::ReplaceAny(const String& oldCharacters, const String& replaceString, std::intmax_t start, UInt32 flags) - { - if (start < 0) - { - start = m_sharedString->size+start; - if (start < 0) - start = 0; - } - - unsigned int pos = static_cast(start); - - if (pos >= m_sharedString->size || m_sharedString->size == 0 || oldCharacters.m_sharedString->size == 0) - return 0; - - unsigned int count = 0; - - if (replaceString.m_sharedString->size == 1) // On utilise un algorithme optimisé - { - EnsureOwnership(); - - char character = replaceString[0]; - for (; pos < m_sharedString->size; ++pos) - { - for (unsigned int i = 0; i < oldCharacters.m_sharedString->size; ++i) - { - if (m_sharedString->string[pos] == oldCharacters[i]) - { - m_sharedString->string[pos] = character; - ++count; - break; - } - } - } - } - else - { - unsigned int newSize; - { - unsigned int count = CountAny(oldCharacters); - newSize = m_sharedString->size - count + count*replaceString.m_sharedString->size; - } - char* newString = new char[newSize+1]; - - unsigned int j = 0; - for (unsigned int i = 0; i < m_sharedString->size; ++i) - { - if (i < pos) // Avant la position où on est censé commencer à remplacer, on ne fait que recopier - newString[j++] = m_sharedString->string[i]; - else - { - bool found = false; - for (unsigned int l = 0; l < oldCharacters.m_sharedString->size; ++l) - { - if (m_sharedString->string[i] == oldCharacters[l]) - { - for (unsigned int k = 0; k < replaceString.m_sharedString->size; ++k) - newString[j++] = replaceString[k]; - - ++count; - found = true; - break; // Simple façon d'éviter la ligne après la boucle - } - } - - if (!found) - newString[j++] = m_sharedString->string[i]; - } - } - newString[newSize] = '\0'; - - ReleaseString(); - - m_sharedString->size = newSize; - m_sharedString->string = newString; - } - - return count; - } - */ - - /*! - * \brief Reserves enough memory for the buffer size - * - * \param bufferSize Size of the buffer to allocate - * - * \remark If bufferSize is smaller than the old one, nothing is done - */ - - void String::Reserve(std::size_t bufferSize) - { - if (m_sharedString->capacity > bufferSize) - return; - - auto newString = std::make_shared(bufferSize); - newString->size = m_sharedString->size; - - if (m_sharedString->size > 0) - std::memcpy(newString->string.get(), m_sharedString->string.get(), m_sharedString->size); - - m_sharedString = std::move(newString); - } - - /*! - * \brief Resizes the string - * \return A reference to this - * - * \param size Target size - * \param flags Flag for the look up - */ - - String& String::Resize(std::intmax_t size, UInt32 flags) - { - if (size == 0) - { - Clear(true); - return *this; - } - - if (size < 0) - size = std::max(m_sharedString->size + size, 0); - - std::size_t newSize = static_cast(size); - - if (flags & HandleUtf8 && newSize < m_sharedString->size) - { - std::size_t characterToRemove = m_sharedString->size - newSize; - - char* ptr = &m_sharedString->string[m_sharedString->size]; - for (std::size_t i = 0; i < characterToRemove; ++i) - utf8::prior(ptr, m_sharedString->string.get()); - - newSize = ptr - m_sharedString->string.get(); - } - - if (m_sharedString->capacity >= newSize) - { - EnsureOwnership(); - - m_sharedString->size = newSize; - m_sharedString->string[newSize] = '\0'; // Adds the EoS character - } - else // Then we want to make the string bigger - { - auto newString = std::make_shared(newSize); - std::memcpy(newString->string.get(), m_sharedString->string.get(), m_sharedString->size); - - m_sharedString = std::move(newString); - } - - return *this; - } - - /*! - * \brief Resize a copy of the string - * \return A copy of what would be the string resized - * - * \param size Target size - * \param flags Flag for the look up - */ - - String String::Resized(std::intmax_t size, UInt32 flags) const - { - if (size < 0) - size = m_sharedString->size + size; - - if (size <= 0) - return String(); - - std::size_t newSize = static_cast(size); - if (newSize == m_sharedString->size) - return *this; - - if (flags & HandleUtf8 && newSize < m_sharedString->size) - { - std::size_t characterToRemove = m_sharedString->size - newSize; - - char* ptr = &m_sharedString->string[m_sharedString->size - 1]; - for (std::size_t i = 0; i < characterToRemove; ++i) - utf8::prior(ptr, m_sharedString->string.get()); - - newSize = ptr - m_sharedString->string.get(); - } - - auto sharedStr = std::make_shared(newSize); - if (newSize > m_sharedString->size) - std::memcpy(sharedStr->string.get(), m_sharedString->string.get(), m_sharedString->size); - else - std::memcpy(sharedStr->string.get(), m_sharedString->string.get(), newSize); - - return String(std::move(sharedStr)); - } - - /*! - * \brief Reverses the string - * \return A reference to this - */ - - String& String::Reverse() - { - if (m_sharedString->size != 0) - { - std::size_t i = 0; - std::size_t j = m_sharedString->size-1; - - while (i < j) - std::swap(m_sharedString->string[i++], m_sharedString->string[j--]); - } - - return *this; - } - - /*! - * \brief Reverses a copy of the string - * \return A copy of what would be the string reversed - */ - - String String::Reversed() const - { - if (m_sharedString->size == 0) - return String(); - - auto sharedStr = std::make_shared(m_sharedString->size); - - char* ptr = &sharedStr->string[m_sharedString->size - 1]; - char* p = m_sharedString->string.get(); - - do - *ptr-- = *p; - while (*(++p)); - - return String(std::move(sharedStr)); - } - - /*! - * \brief Sets the string to the character - * \return A reference to this - * - * \param character Single character - */ - - String& String::Set(char character) - { - if (character != '\0') - { - if (m_sharedString->capacity >= 1) - { - EnsureOwnership(true); - - m_sharedString->size = 1; - m_sharedString->string[1] = '\0'; - } - else - m_sharedString = std::make_shared(1); - - m_sharedString->string[0] = character; - } - else - ReleaseString(); - - return *this; - } - - - /*! - * \brief Sets the string with multiple times the same character - * \return A reference to this - * - * \param rep Number of repetitions of the character - * \param character Single character - */ - - String& String::Set(std::size_t rep, char character) - { - if (rep > 0) - { - if (m_sharedString->capacity >= rep) - { - EnsureOwnership(true); - - m_sharedString->size = rep; - m_sharedString->string[rep] = '\0'; - } - else - m_sharedString = std::make_shared(rep); - - if (character != '\0') - std::memset(m_sharedString->string.get(), character, rep); - } - else - ReleaseString(); - - return *this; - } - - /*! - * \brief Sets the string with multiple times the same string - * \return A reference to this - * - * \param rep Number of repetitions of the string - * \param string String to multiply - */ - - String& String::Set(std::size_t rep, const char* string) - { - return Set(rep, string, (string) ? std::strlen(string) : 0); - } - - /*! - * \brief Sets the string with multiple times the same string - * \return A reference to this - * - * \param rep Number of repetitions of the string - * \param string String to multiply - * \param length Length of the string - */ - - String& String::Set(std::size_t rep, const char* string, std::size_t length) - { - std::size_t totalSize = rep*length; - - if (totalSize > 0) - { - if (m_sharedString->capacity >= totalSize) - { - EnsureOwnership(true); - - m_sharedString->size = totalSize; - m_sharedString->string[totalSize] = '\0'; - } - else - m_sharedString = std::make_shared(totalSize); - - for (std::size_t i = 0; i < rep; ++i) - std::memcpy(&m_sharedString->string[i*length], string, length); - } - else - ReleaseString(); - - return *this; - } - - /*! - * \brief Sets the string with multiple times the same string - * \return A reference to this - * - * \param rep Number of repetitions of the string - * \param string String to multiply - */ - - String& String::Set(std::size_t rep, const String& string) - { - return Set(rep, string.GetConstBuffer(), string.m_sharedString->size); - } - - /*! - * \brief Sets the string with other "C string" - * \return A reference to this - * - * \param string String to copy - */ - - String& String::Set(const char* string) - { - return Set(string, (string) ? std::strlen(string) : 0); - } - - /*! - * \brief Sets the string with other "C string" - * \return A reference to this - * - * \param string String to represent - * \param length Length of the string - */ - - String& String::Set(const char* string, std::size_t length) - { - if (length > 0) - { - if (m_sharedString->capacity >= length) - { - EnsureOwnership(true); - - m_sharedString->size = length; - m_sharedString->string[length] = '\0'; - } - else - m_sharedString = std::make_shared(length); - - std::memcpy(m_sharedString->string.get(), string, length); - } - else - ReleaseString(); - - return *this; - } - - /*! - * \brief Sets the string with a std::string - * \return A reference to this - * - * \param string String to copy - */ - - String& String::Set(const std::string& string) - { - return Set(string.data(), string.size()); - } - - /*! - * \brief Sets the string with other string - * \return A reference to this - * - * \param string String to copy - */ - - String& String::Set(const String& string) - { - m_sharedString = string.m_sharedString; - - return *this; - } - - /*! - * \brief Sets the string by move semantic - * \return A reference to this - * - * \param string String to move - */ - - String& String::Set(String&& string) noexcept - { - std::swap(m_sharedString, string.m_sharedString); - - return *this; - } - - /*! - * \brief Simplifies a copy of the string - * \return A copy of what would be the string simplified - * - * \param flags Flag for the look up - */ - - String String::Simplified(UInt32 flags) const - { - if (m_sharedString->size == 0) - return String(); - - auto newString = std::make_shared(m_sharedString->size); - char* str = newString->string.get(); - char* p = str; - - const char* ptr = m_sharedString->string.get(); - bool inword = false; - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(ptr); - do - { - if (Detail::IsSpace(*it)) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - p = utf8::append(*it, p); - inword = true; - } - } - while (*++it); - } - else - { - const char* limit = &m_sharedString->string[m_sharedString->size]; - do - { - if (Detail::IsSpace(*ptr)) - { - if (inword) - { - *p++ = ' '; - inword = false; - } - } - else - { - *p++ = *ptr; - inword = true; - } - } - while (++ptr != limit); - } - - if (!inword && p != str) - p--; - - *p = '\0'; - newString->size = p - str; - - return String(std::move(newString)); - } - - /*! - * \brief Simplifies the string - * \return A reference to this - * - * \param flags Flag for the look up - */ - - String& String::Simplify(UInt32 flags) - { - return Set(Simplified(flags)); - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separation Separation character - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::Split(std::vector& result, char separation, std::intmax_t start, UInt32 flags) const - { - if (separation == '\0' || m_sharedString->size == 0) - return 0; - - std::size_t lastSep = Find(separation, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(SubString(0, lastSep-1)); - - for (;;) - { - std::size_t sep = Find(separation, lastSep+1, flags); - if (sep == npos) - break; - - if (sep-lastSep > 1) - result.push_back(SubString(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(SubString(lastSep+1)); - - return result.size(); - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separation Separation string - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::Split(std::vector& result, const char* separation, std::intmax_t start, UInt32 flags) const - { - return Split(result, separation, std::strlen(separation), start, flags); - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separation Separation String - * \param length Length of the string - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::Split(std::vector& result, const char* separation, std::size_t length, std::intmax_t start, UInt32 flags) const - { - if (m_sharedString->size == 0) - return 0; - else if (length == 0) - { - result.reserve(m_sharedString->size); - for (std::size_t i = 0; i < m_sharedString->size; ++i) - result.push_back(String(m_sharedString->string[i])); - - return m_sharedString->size; - } - else if (length > m_sharedString->size) - { - result.push_back(*this); - return 1; - } - - std::size_t lastSep = Find(separation, start, flags); - std::size_t oldSize = result.size(); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(SubString(0, lastSep-1)); - - std::size_t sep; - while ((sep = Find(separation, lastSep + length, flags)) != npos) - { - if (sep-lastSep > length) - result.push_back(SubString(lastSep + length, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size - length) - result.push_back(SubString(lastSep + length)); - - return result.size()-oldSize; - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separation Separation string - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::Split(std::vector& result, const String& separation, std::intmax_t start, UInt32 flags) const - { - return Split(result, separation.m_sharedString->string.get(), separation.m_sharedString->size, start, flags); - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separations List of characters for separation - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::SplitAny(std::vector& result, const char* separations, std::intmax_t start, UInt32 flags) const - { - if (m_sharedString->size == 0) - return 0; - - std::size_t oldSize = result.size(); - - std::size_t lastSep = FindAny(separations, start, flags); - if (lastSep == npos) - { - result.push_back(*this); - return 1; - } - else if (lastSep != 0) - result.push_back(SubString(0, lastSep-1)); - - std::size_t sep; - while ((sep = FindAny(separations, lastSep+1, flags)) != npos) - { - if (sep-lastSep > 1) - result.push_back(SubString(lastSep+1, sep-1)); - - lastSep = sep; - } - - if (lastSep != m_sharedString->size-1) - result.push_back(SubString(lastSep+1)); - - return result.size()-oldSize; - } - - /*! - * \brief Splits the string into others - * \return The number of splits - * - * \param result Resulting tokens - * \param separations List of characters for separation - * \param start Index for the beginning of the search - * \param flags Flag for the look up - */ - - unsigned int String::SplitAny(std::vector& result, const String& separations, std::intmax_t start, UInt32 flags) const - { - return SplitAny(result, separations.m_sharedString->string.get(), start, flags); - } - - /*! - * \brief Checks whether the string begins with the character - * \return true if it the case - * - * \param character Single character - * \param flags Flag for the look up - * - * \see EndsWith - */ - - bool String::StartsWith(char character, UInt32 flags) const - { - if (character == '\0' || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - return Detail::ToLower(m_sharedString->string[0]) == Detail::ToLower(character); - else - return m_sharedString->string[0] == character; - } - - /*! - * \brief Checks whether the string begins with the "C string" - * \return true if it the case - * - * \param string String to match - * \param flags Flag for the look up - * - * \see EndsWith - */ - - bool String::StartsWith(const char* string, UInt32 flags) const - { - if (!string || !string[0] || m_sharedString->size == 0) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string.get()); - utf8::unchecked::iterator it2(string); - do - { - if (*it2 == '\0') - return true; - - if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string.get(); - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (Detail::ToLower(*ptr) != Detail::ToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - { - char* ptr = m_sharedString->string.get(); - const char* s = string; - do - { - if (*s == '\0') - return true; - - if (*ptr != *s) - return false; - - s++; - } - while (*ptr++); - } - - return false; - } - - /*! - * \brief Checks whether the string begins with the string - * \return true if it the case - * - * \param string String to match - * \param flags Flag for the look up - * - * \see EndsWith - */ - - bool String::StartsWith(const String& string, UInt32 flags) const - { - if (string.m_sharedString->size == 0) - return false; - - if (m_sharedString->size < string.m_sharedString->size) - return false; - - if (flags & CaseInsensitive) - { - if (flags & HandleUtf8) - { - utf8::unchecked::iterator it(m_sharedString->string.get()); - utf8::unchecked::iterator it2(string.GetConstBuffer()); - do - { - if (*it2 == '\0') - return true; - - if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) - return false; - - ++it2; - } - while (*it++); - } - else - { - char* ptr = m_sharedString->string.get(); - const char* s = string.GetConstBuffer(); - do - { - if (*s == '\0') - return true; - - if (Detail::ToLower(*ptr) != Detail::ToLower(*s)) - return false; - - s++; - } - while (*ptr++); - } - } - else - return std::memcmp(m_sharedString->string.get(), string.GetConstBuffer(), string.m_sharedString->size) == 0; - - return false; - } - - /*! - * \brief Returns a sub string of the string - * \return SubString - * - * \param startPos Index for the beginning of the search - * \param endPos Index for the end of the search - */ - - String String::SubString(std::intmax_t startPos, std::intmax_t endPos) const - { - if (startPos < 0) - startPos = std::max(m_sharedString->size + startPos, 0); - - std::size_t start = static_cast(startPos); - - if (endPos < 0) - { - endPos = m_sharedString->size+endPos; - if (endPos < 0) - return String(); - } - - std::size_t minEnd = std::min(static_cast(endPos), m_sharedString->size - 1); - if (start > minEnd || start >= m_sharedString->size) - return String(); - - std::size_t size = minEnd - start + 1; - - auto str = std::make_shared(size); - std::memcpy(str->string.get(), &m_sharedString->string[start], size); - - return String(std::move(str)); - } - - /*! - * \brief Returns a sub string of the string from a character - * \return SubString - * - * \param character Pattern to find - * \param startPos Index for the beginning of the search - * \param fromLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringFrom(char character, std::intmax_t startPos, bool fromLast, bool include, UInt32 flags) const - { - if (character == '\0') - return *this; - - std::size_t pos; - if (fromLast) - pos = FindLast(character, startPos, flags); - else - pos = Find(character, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return String(); - - return SubString(pos + ((include) ? 0 : 1)); - } - - /*! - * \brief Returns a sub string of the string from a string - * \return SubString - * - * \param string Pattern to find - * \param startPos Index for the beginning of the search - * \param fromLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringFrom(const char* string, std::intmax_t startPos, bool fromLast, bool include, UInt32 flags) const - { - return SubStringFrom(string, std::strlen(string), startPos, fromLast, include, flags); - } - - /*! - * \brief Returns a sub string of the string from a string - * \return SubString - * - * \param string Pattern to find - * \param length Size of the string - * \param startPos Index for the beginning of the search - * \param fromLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringFrom(const char* string, std::size_t length, std::intmax_t startPos, bool fromLast, bool include, UInt32 flags) const - { - std::size_t pos; - if (fromLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0 && include) - return *this; - else if (pos == npos) - return String(); - - return SubString(pos + ((include) ? 0 : length)); - } - - /*! - * \brief Returns a sub string of the string from a string - * \return SubString - * - * \param string Pattern to find - * \param startPos Index for the beginning of the search - * \param fromLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringFrom(const String& string, std::intmax_t startPos, bool fromLast, bool include, UInt32 flags) const - { - return SubStringFrom(string.GetConstBuffer(), string.m_sharedString->size, startPos, fromLast, include, flags); - } - - /*! - * \brief Returns a sub string of the string up to a character - * \return SubString - * - * \param character Pattern to find - * \param startPos Index for the beginning of the search - * \param toLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringTo(char character, std::intmax_t startPos, bool toLast, bool include, UInt32 flags) const - { - if (character == '\0') - return *this; - - std::size_t pos; - if (toLast) - pos = FindLast(character, startPos); - else - pos = Find(character, startPos, flags); - - if (pos == 0) - return (include) ? String(character) : String(); - else if (pos == npos) - return *this; - - return SubString(0, pos+((include) ? 1 : 0)-1); - } - - /*! - * \brief Returns a sub string of the string up to a string - * \return SubString - * - * \param string Pattern to find - * \param startPos Index for the beginning of the search - * \param toLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringTo(const char* string, std::intmax_t startPos, bool toLast, bool include, UInt32 flags) const - { - return SubStringTo(string, std::strlen(string), startPos, toLast, include, flags); - } - - /*! - * \brief Returns a sub string of the string up to a string - * \return SubString - * - * \param string Pattern to find - * \param length Size of the string - * \param startPos Index for the beginning of the search - * \param toLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringTo(const char* string, std::size_t length, std::intmax_t startPos, bool toLast, bool include, UInt32 flags) const - { - std::size_t pos; - if (toLast) - pos = FindLast(string, startPos, flags); - else - pos = Find(string, startPos, flags); - - if (pos == 0) - return (include) ? string : String(); - else if (pos == npos) - return *this; - - return SubString(0, pos+((include) ? length : 0)-1); - } - - /*! - * \brief Returns a sub string of the string up to a string - * \return SubString - * - * \param string Pattern to find - * \param startPos Index for the beginning of the search - * \param toLast beginning by the end - * \param include Include the character - * \param flags Flag for the look up - */ - - String String::SubStringTo(const String& string, std::intmax_t startPos, bool toLast, bool include, UInt32 flags) const - { - return SubStringTo(string.GetConstBuffer(), string.m_sharedString->size, startPos, toLast, include, flags); - } - - /*! - * \brief Swaps the content with the other string - * - * \param str Other string to swap with - */ - - void String::Swap(String& str) - { - std::swap(m_sharedString, str.m_sharedString); - } - - /*! - * \brief Converts the string to boolean - * \return true if successful - * - * \param value Boolean to convert to - * \param flags Flag for the look up - */ - - bool String::ToBool(bool* value, UInt32 flags) const - { - if (m_sharedString->size == 0) - return false; - - String word = GetWord(0); - - if (word[0] == '1') - { - if (value) - *value = true; - } - else if (word[0] == '0') - { - if (value) - *value = false; - } - else - { - if (flags & CaseInsensitive) - word = word.ToLower(); // The identified words are in ASCII, no use of Unicode flag - - if (word == "true") - { - if (value) - *value = true; - } - else if (word == "false") - { - if (value) - *value = false; - } - else - return false; - } - - return true; - } - - /*! - * \brief Converts the string to double - * \return true if successful - * - * \param value Double to convert to - */ - - bool String::ToDouble(double* value) const - { - if (m_sharedString->size == 0) - return false; - - if (value) - *value = std::atof(m_sharedString->string.get()); - - return true; - } - - /*! - * \brief Converts the string to integer - * \return true if successful - * - * \param value Integer to convert to - * \param base Base to convert the integer to - */ - - bool String::ToInteger(long long* value, UInt8 base) const - { - if (value) - { - bool ok; - *value = StringToNumber(*this, base, &ok); - - return ok; - } - else - return IsNumber(base); - } - - /*! - * \brief Converts the string to lower - * \return Lower string - * - * \param flags Flag for the look up - */ - - String String::ToLower(UInt32 flags) const - { - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - String lower; - lower.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string.get()); - do - utf8::append(Unicode::GetLowercase(*it), std::back_inserter(lower)); - while (*++it); - - return lower; - } - else - { - auto str = std::make_shared(m_sharedString->size); - - char* ptr = m_sharedString->string.get(); - char* s = str->string.get(); - do - *s++ = Detail::ToLower(*ptr); - while (*++ptr); - - *s = '\0'; - - return String(std::move(str)); - } - } - - /*! - * \brief Converts the string to std::string - * \return std::string representation - */ - std::string String::ToStdString() const - { - return std::string(m_sharedString->string.get(), m_sharedString->size); - } - - /*! - * \brief Converts the string to upper - * \return Upper string - * - * \param flags Flag for the look up - */ - String String::ToUpper(UInt32 flags) const - { - if (m_sharedString->size == 0) - return *this; - - if (flags & HandleUtf8) - { - String upper; - upper.Reserve(m_sharedString->size); - utf8::unchecked::iterator it(m_sharedString->string.get()); - do - utf8::append(Unicode::GetUppercase(*it), std::back_inserter(upper)); - while (*++it); - - return upper; - } - else - { - auto str = std::make_shared(m_sharedString->size); - - char* ptr = m_sharedString->string.get(); - char* s = str->string.get(); - do - *s++ = Detail::ToUpper(*ptr); - while (*++ptr); - - *s = '\0'; - - return String(std::move(str)); - } - } - - /*! - * \brief Trims the string - * \return A reference to this - * - * \param flags Flag for the look up - */ - - String& String::Trim(UInt32 flags) - { - return Set(Trimmed(flags)); - } - - /*! - * \brief Trims the string from a character - * \return A reference to this - * - * \param character Character to suppress - * \param flags Flag for the look up - */ - - String& String::Trim(char character, UInt32 flags) - { - return Set(Trimmed(character, flags)); - } - - /*! - * \brief Trims a copy of the string - * \return A copy of what would be the string trimmed - * - * \param flags Flag for the look up - */ - - String String::Trimmed(UInt32 flags) const - { - if (m_sharedString->size == 0) - return *this; - - std::size_t startPos; - std::size_t endPos; - if (flags & HandleUtf8) - { - if ((flags & TrimOnlyRight) == 0) - { - utf8::unchecked::iterator it(m_sharedString->string.get()); - do - { - if (!Detail::IsSpace(*it)) - break; - } - while (*++it); - - startPos = it.base() - m_sharedString->string.get(); - } - else - startPos = 0; - - if ((flags & TrimOnlyLeft) == 0) - { - utf8::unchecked::iterator it(&m_sharedString->string[m_sharedString->size]); - while ((it--).base() != m_sharedString->string.get()) - { - if (!Detail::IsSpace(*it)) - break; - } - - endPos = it.base() - m_sharedString->string.get(); - } - else - endPos = m_sharedString->size-1; - } - else - { - startPos = 0; - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - char c = m_sharedString->string[startPos]; - if (!Detail::IsSpace(c)) - break; - } - } - - endPos = m_sharedString->size-1; - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - char c = m_sharedString->string[endPos]; - if (!Detail::IsSpace(c)) - break; - } - } - } - - return SubString(startPos, endPos); - } - - /*! - * \brief Trims a copy of the string from a character - * \return A copy of what would be the string trimmed - * - * \param character Character to suppress - * \param flags Flag for the look up - */ - - String String::Trimmed(char character, UInt32 flags) const - { - if (m_sharedString->size == 0) - return *this; - - std::size_t startPos = 0; - std::size_t endPos = m_sharedString->size-1; - if (flags & CaseInsensitive) - { - char ch = Detail::ToLower(character); - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (Detail::ToLower(m_sharedString->string[startPos]) != ch) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (Detail::ToLower(m_sharedString->string[endPos]) != ch) - break; - } - } - } - else - { - if ((flags & TrimOnlyRight) == 0) - { - for (; startPos < m_sharedString->size; ++startPos) - { - if (m_sharedString->string[startPos] != character) - break; - } - } - - if ((flags & TrimOnlyLeft) == 0) - { - for (; endPos > 0; --endPos) - { - if (m_sharedString->string[endPos] != character) - break; - } - } - } - - return SubString(startPos, endPos); - } - - /*! - * \brief Returns an iterator pointing to the beginning of the string - * \return beginning of the string - */ - - char* String::begin() - { - return m_sharedString->string.get(); - } - - /*! - * \brief Returns an iterator pointing to the beginning of the string - * \return beginning of the string - */ - - const char* String::begin() const - { - return m_sharedString->string.get(); - } - - /*! - * \brief Returns an iterator pointing to the end of the string - * \return End of the string - */ - - char* String::end() - { - return &m_sharedString->string[m_sharedString->size]; - } - - /*! - * \brief Returns an iterator pointing to the end of the string - * \return End of the string - */ - - const char* String::end() const - { - return &m_sharedString->string[m_sharedString->size]; - } - - /*! - * \brief Pushed the character to the front of the string - * - * \param c Single character - * - * \see Prepend - */ - - void String::push_front(char c) - { - Prepend(c); - } - - /*! - * \brief Pushed the character to the back of the string - * - * \param c Single character - * - * \see Append - */ - - void String::push_back(char c) - { - Append(c); - } - /* - char* String::rbegin() - { - return &m_sharedString->string[m_sharedString->size-1]; - } - - const char* String::rbegin() const - { - return &m_sharedString->string[m_sharedString->size-1]; - } - - char* String::rend() - { - return &m_sharedString->string[-1]; - } - - const char* String::rend() const - { - return &m_sharedString->string[-1]; - } - */ - - /*! - * \brief Gets the ith character in the string - * \return A reference to the character - * - * \param pos Index of the character - * - * \remark If pos is greather than the size, Resize is called - */ - - char& String::operator[](std::size_t pos) - { - EnsureOwnership(); - - if (pos >= m_sharedString->size) - Resize(pos+1); - - return m_sharedString->string[pos]; - } - - /*! - * \brief Gets the ith character in the string - * \return The character - * - * \param pos Index of the character - * - * \remark Produces a NazaraError if pos is greather than the size - */ - - char String::operator[](std::size_t pos) const - { - #if NAZARA_CORE_SAFE - if (pos >= m_sharedString->size) - { - NazaraError("Index out of range (" + Number(pos) + " >= " + Number(m_sharedString->size) + ')'); - return 0; - } - #endif - - return m_sharedString->string[pos]; - } - - /*! - * \brief Assigns the string to the character - * \return A reference to this - * - * \param character Single character - */ - - String& String::operator=(char character) - { - return Set(character); - } - - /*! - * \brief Assigns the string with other "C string" - * \return A reference to this - * - * \param string String to copy - */ - - String& String::operator=(const char* string) - { - return Set(string); - } - - /*! - * \brief Assigns the string with a std::string - * \return A reference to this - * - * \param string String to copy - */ - - String& String::operator=(const std::string& string) - { - return Set(string); - } - - /*! - * \brief Assigns the string with other string - * \return A reference to this - * - * \param string String to copy - */ - - String& String::operator=(const String& string) - { - return Set(string); - } - - /*! - * \brief Assigns the string by move semantic - * \return A reference to this - * - * \param string String to move - */ - - String& String::operator=(String&& string) noexcept - { - return Set(std::move(string)); - } - - /*! - * \brief Concatenates the character to the string - * \return String which is the result of the concatenation - * - * \param character Single character - */ - - String String::operator+(char character) const - { - if (character == '\0') - return *this; - - auto str = std::make_shared(m_sharedString->size + 1); - std::memcpy(str->string.get(), GetConstBuffer(), m_sharedString->size); - str->string[m_sharedString->size] = character; - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the "C string" to the string - * \return String which is the result of the concatenation - * - * \param string String to add - */ - - String String::operator+(const char* string) const - { - if (!string || !string[0]) - return *this; - - if (m_sharedString->size == 0) - return string; - - std::size_t length = std::strlen(string); - if (length == 0) - return *this; - - auto str = std::make_shared(m_sharedString->size + length); - std::memcpy(str->string.get(), GetConstBuffer(), m_sharedString->size); - std::memcpy(&str->string[m_sharedString->size], string, length+1); - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the std::string to the string - * \return String which is the result of the concatenation - * - * \param string String to add - */ - - String String::operator+(const std::string& string) const - { - if (string.empty()) - return *this; - - if (m_sharedString->size == 0) - return string; - - auto str = std::make_shared(m_sharedString->size + string.size()); - std::memcpy(str->string.get(), GetConstBuffer(), m_sharedString->size); - std::memcpy(&str->string[m_sharedString->size], string.c_str(), string.size()+1); - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the string to the string - * \return String which is the result of the concatenation - * - * \param string String to add - */ - - String String::operator+(const String& string) const - { - if (string.m_sharedString->size == 0) - return *this; - - if (m_sharedString->size == 0) - return string; - - auto str = std::make_shared(m_sharedString->size + string.m_sharedString->size); - std::memcpy(str->string.get(), GetConstBuffer(), m_sharedString->size); - std::memcpy(&str->string[m_sharedString->size], string.GetConstBuffer(), string.m_sharedString->size); - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the character to this string - * \return A reference to this - * - * \param character Single character - */ - - String& String::operator+=(char character) - { - return Insert(m_sharedString->size, character); - } - - /*! - * \brief Concatenates the "C string" to this string - * \return A reference to this - * - * \param string String to add - */ - - String& String::operator+=(const char* string) - { - return Insert(m_sharedString->size, string); - } - - /*! - * \brief Concatenates the std::string to this string - * \return A reference to this - * - * \param string String to add - */ - - String& String::operator+=(const std::string& string) - { - return Insert(m_sharedString->size, string.c_str(), string.size()); - } - - /*! - * \brief Concatenates the string to this string - * \return A reference to this - * - * \param string String to add - */ - - String& String::operator+=(const String& string) - { - return Insert(m_sharedString->size, string); - } - - /*! - * \brief Checks whether the string is equal to the character - * \return true if it is the case - * - * \param character Single character - */ - - bool String::operator==(char character) const - { - if (m_sharedString->size == 0) - return character == '\0'; - - if (m_sharedString->size > 1) - return false; - - return m_sharedString->string[0] == character; - } - - /*! - * \brief Checks whether the string is equal to the "C string" - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator==(const char* string) const - { - if (m_sharedString->size == 0) - return !string || !string[0]; - - if (!string || !string[0]) - return false; - - return std::strcmp(GetConstBuffer(), string) == 0; - } - - /*! - * \brief Checks whether the string is equal to the std::string - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator==(const std::string& string) const - { - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(GetConstBuffer(), string.c_str()) == 0; - } - - /*! - * \brief Checks whether the string is equal to the character - * \return false if it is the case - * - * \param character Single character - */ - - bool String::operator!=(char character) const - { - if (m_sharedString->size == 0) - return character != '\0'; - - if (character == '\0' || m_sharedString->size != 1) - return true; - - if (m_sharedString->size != 1) - return true; - - return m_sharedString->string[0] != character; - } - - /*! - * \brief Checks whether the string is equal to the "C string" - * \return false if it is the case - * - * \param string String to compare - */ - - bool String::operator!=(const char* string) const - { - if (m_sharedString->size == 0) - return string && string[0]; - - if (!string || !string[0]) - return true; - - return std::strcmp(GetConstBuffer(), string) != 0; - } - - /*! - * \brief Checks whether the string is equal to the std::string - * \return false if it is the case - * - * \param string String to compare - */ - - bool String::operator!=(const std::string& string) const - { - if (m_sharedString->size == 0 || string.empty()) - return m_sharedString->size == string.size(); - - if (m_sharedString->size != string.size()) - return false; - - return std::strcmp(GetConstBuffer(), string.c_str()) != 0; - } - - /*! - * \brief Checks whether the string is less than the character - * \return true if it is the case - * - * \param character Single character - */ - - bool String::operator<(char character) const - { - if (character == '\0') - return false; - - if (m_sharedString->size == 0) - return true; - - return m_sharedString->string[0] < character; - } - - /*! - * \brief Checks whether the string is less than the "C string" - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator<(const char* string) const - { - if (!string || !string[0]) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(GetConstBuffer(), string) < 0; - } - - /*! - * \brief Checks whether the string is less than the std::string - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator<(const std::string& string) const - { - if (string.empty()) - return false; - - if (m_sharedString->size == 0) - return true; - - return std::strcmp(GetConstBuffer(), string.c_str()) < 0; - } - - /*! - * \brief Checks whether the string is less or equal than the character - * \return true if it is the case - * - * \param character Single character - */ - - bool String::operator<=(char character) const - { - if (m_sharedString->size == 0) - return true; - - if (character == '\0') - return false; - - return m_sharedString->string[0] < character || (m_sharedString->string[0] == character && m_sharedString->size == 1); - } - - /*! - * \brief Checks whether the string is less or equal than the "C string" - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator<=(const char* string) const - { - if (m_sharedString->size == 0) - return true; - - if (!string || !string[0]) - return false; - - return std::strcmp(GetConstBuffer(), string) <= 0; - } - - /*! - * \brief Checks whether the string is less or equal than the std::string - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator<=(const std::string& string) const - { - if (m_sharedString->size == 0) - return true; - - if (string.empty()) - return false; - - return std::strcmp(GetConstBuffer(), string.c_str()) <= 0; - } - - /*! - * \brief Checks whether the string is greather than the character - * \return true if it is the case - * - * \param character Single character - */ - - bool String::operator>(char character) const - { - if (m_sharedString->size == 0) - return false; - - if (character == '\0') - return true; - - return m_sharedString->string[0] > character; - } - - /*! - * \brief Checks whether the string is greather than the "C string" - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator>(const char* string) const - { - if (m_sharedString->size == 0) - return false; - - if (!string || !string[0]) - return true; - - return std::strcmp(GetConstBuffer(), string) > 0; - } - - /*! - * \brief Checks whether the string is greather than the std::string - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator>(const std::string& string) const - { - if (m_sharedString->size == 0) - return false; - - if (string.empty()) - return true; - - return std::strcmp(GetConstBuffer(), string.c_str()) > 0; - } - - /*! - * \brief Checks whether the string is greather or equal than the character - * \return true if it is the case - * - * \param character Single character - */ - - bool String::operator>=(char character) const - { - if (character == '\0') - return true; - - if (m_sharedString->size == 0) - return false; - - return m_sharedString->string[0] > character || (m_sharedString->string[0] == character && m_sharedString->size == 1); - } - - /*! - * \brief Checks whether the string is greather or equal than the "C string" - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator>=(const char* string) const - { - if (!string || !string[0]) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(GetConstBuffer(), string) >= 0; - } - - /*! - * \brief Checks whether the string is greather or equal than the std::string - * \return true if it is the case - * - * \param string String to compare - */ - - bool String::operator>=(const std::string& string) const - { - if (string.empty()) - return true; - - if (m_sharedString->size == 0) - return false; - - return std::strcmp(GetConstBuffer(), string.c_str()) >= 0; - } - - /*! - * \brief Converts the boolean to string - * \return String representation of the boolean - * - * \param boolean Boolean value - */ - - String String::Boolean(bool boolean) - { - std::size_t size = (boolean) ? 4 : 5; - - auto str = std::make_shared(size); - std::memcpy(str->string.get(), (boolean) ? "true" : "false", size); - - return String(std::move(str)); - } - - /*! - * \brief Lexicographically compares the string - * \return The expected result - * - * \param first First string to use for comparison - * \param second Second string to use for comparison - */ - - int String::Compare(const String& first, const String& second) - { - if (first.m_sharedString->size == 0) - return (second.m_sharedString->size == 0) ? 0 : -1; - - if (second.m_sharedString->size == 0) - return 1; - - return std::strcmp(first.GetConstBuffer(), second.GetConstBuffer()); - } - - /*! - * \brief Build a string using a format and returns it - * \return Formatted string - * - * \param format String format - * \param args Format arguments - */ - String String::FormatVA(const char* format, va_list args) - { - // Copy va_list to use it twice - va_list args2; - va_copy(args2, args); - - std::size_t length = std::vsnprintf(nullptr, 0, format, args); - - auto str = std::make_shared(length); - std::vsnprintf(str->string.get(), length + 1, format, args2); - - return String(std::move(str)); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Float value - */ - - String String::Number(float number) - { - std::ostringstream oss; - oss.imbue(std::locale::classic()); - oss.precision(NAZARA_CORE_DECIMAL_DIGITS); - oss << number; - - return String(oss.str()); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Double value - */ - - String String::Number(double number) - { - std::ostringstream oss; - oss.imbue(std::locale::classic()); - oss.precision(NAZARA_CORE_DECIMAL_DIGITS); - oss << number; - - return String(oss.str()); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Long double value - */ - - String String::Number(long double number) - { - std::ostringstream oss; - oss.imbue(std::locale::classic()); - oss.precision(NAZARA_CORE_DECIMAL_DIGITS); - oss << number; - - return String(oss.str()); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Signed char value - * \param radix Base of the number - */ - - String String::Number(signed char number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Unsigned char value - * \param radix Base of the number - */ - - String String::Number(unsigned char number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Short value - * \param radix Base of the number - */ - - String String::Number(short number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Unsigned short value - * \param radix Base of the number - */ - - String String::Number(unsigned short number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Int value - * \param radix Base of the number - */ - - String String::Number(int number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Unsigned int value - * \param radix Base of the number - */ - - String String::Number(unsigned int number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Long value - * \param radix Base of the number - */ - - String String::Number(long number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Unsigned long value - * \param radix Base of the number - */ - - String String::Number(unsigned long number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Long long value - * \param radix Base of the number - */ - - String String::Number(long long number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the number to string - * \return String representation of the number - * - * \param number Unsigned long long value - * \param radix Base of the number - */ - - String String::Number(unsigned long long number, UInt8 radix) - { - return NumberToString(number, radix); - } - - /*! - * \brief Converts the pointer to string - * \return String representation of the pointer - * - * \param ptr Pointer to represent - */ - - String String::Pointer(const void* ptr) - { - const std::size_t capacity = sizeof(void*)*2 + 2; - - auto str = std::make_shared(capacity); - str->size = std::sprintf(str->string.get(), "0x%p", ptr); - - return String(std::move(str)); - } - - /*! - * \brief Converts the unicode point to string - * \return String representation of the unicode point - * - * \param character Unicode point - */ - - String String::Unicode(char32_t character) - { - if (character == '\0') - return String(); - - std::size_t count = 0; - if (character < 0x80) - count = 1; - else if (character < 0x800) - count = 2; - else if (character < 0x10000) - count = 3; - else - count = 4; - - auto str = std::make_shared(count); - utf8::append(character, str->string.get()); - - return String(std::move(str)); - } - - /*! - * \brief Converts the unicode "C string" to string - * \return String representation of the unicode "C string" - * - * \param u8String String in UTF-8 - */ - - String String::Unicode(const char* u8String) - { - return String(u8String); - } - - /*! - * \brief Converts the unicode "C string" to string - * \return String representation of the unicode "C string" - * - * \param u16String String in UTF-16 - */ - - String String::Unicode(const char16_t* u16String) - { - if (!u16String || !u16String[0]) - return String(); - - const char16_t* ptr = u16String; - std::size_t count = 0; - do - count++; - while (*++ptr); - - count *= 2; // We ensure to have enough place - - auto str = std::make_shared(count); - - char* r = utf8::utf16to8(u16String, ptr, str->string.get()); - *r = '\0'; - - str->size = r - str->string.get(); - - return String(std::move(str)); - } - - /*! - * \brief Converts the unicode "C string" to string - * \return String representation of the unicode "C string" - * - * \param u32String String in UTF-32 - */ - - String String::Unicode(const char32_t* u32String) - { - if (!u32String || !u32String[0]) - return String(); - - const char32_t* ptr = u32String; - std::size_t count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - auto str = std::make_shared(count); - utf8::utf32to8(u32String, ptr, str->string.get()); - - return String(std::move(str)); - } - - /*! - * \brief Converts the unicode "C string" to string - * \return String representation of the unicode "C string" - * - * \param wString String in Wide - */ - - String String::Unicode(const wchar_t* wString) - { - if (!wString || !wString[0]) - return String(); - - const wchar_t* ptr = wString; - std::size_t count = 0; - do - { - char32_t cp = *ptr; - if (cp < 0x80) - count += 1; - else if (cp < 0x800) - count += 2; - else if (cp < 0x10000) - count += 3; - else - count += 4; - } - while (*++ptr); - - auto str = std::make_shared(count); - utf8::utf32to8(wString, ptr, str->string.get()); - - return String(std::move(str)); - } - - /*! - * \brief Inputs the stream into the string - * \return A reference to the stream - * - * \param is Stream to get information from - * \param str String to set value - */ - - std::istream& operator>>(std::istream& is, String& str) - { - str.Clear(); - - char c; - for (;;) - { - is.get(c); - if (c == '\0') - break; - else if (std::isspace(c)) - { - if (str.IsNull()) - continue; - else - break; - } - else - str += c; - } - - return is; - } - - /*! - * \brief Output operator - * \return The stream - * - * \param os The stream - * \param str The string to output - */ - - std::ostream& operator<<(std::ostream& os, const String& str) - { - if (str.IsEmpty()) - return os; - - return operator<<(os, str.m_sharedString->string.get()); - } - - /*! - * \brief Concatenates the character to the string - * \return String which is the result of the concatenation - * - * \param character Single character - * \param string String in the right hand side - */ - - String operator+(char character, const String& string) - { - if (character == '\0') - return string; - - if (string.IsEmpty()) - return String(character); - - auto str = std::make_shared(string.m_sharedString->size + 1); - str->string[0] = character; - std::memcpy(&str->string[1], string.GetConstBuffer(), string.m_sharedString->size); - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the "C string" to the string - * \return String which is the result of the concatenation - * - * \param string String to add - * \param nstring String in the right hand side - */ - - String operator+(const char* string, const String& nstring) - { - if (!string || !string[0]) - return nstring; - - if (nstring.IsEmpty()) - return string; - - std::size_t size = std::strlen(string); - std::size_t totalSize = size + nstring.m_sharedString->size; - - auto str = std::make_shared(totalSize); - std::memcpy(str->string.get(), string, size); - std::memcpy(&str->string[size], nstring.GetConstBuffer(), nstring.m_sharedString->size+1); - - return String(std::move(str)); - } - - /*! - * \brief Concatenates the std::string to the string - * \return String which is the result of the concatenation - * - * \param string String to add - * \param nstring String in the right hand side - */ - - String operator+(const std::string& string, const String& nstring) - { - if (string.empty()) - return nstring; - - if (nstring.m_sharedString->size == 0) - return string; - - std::size_t totalSize = string.size() + nstring.m_sharedString->size; - - auto str = std::make_shared(totalSize); - std::memcpy(str->string.get(), string.c_str(), string.size()); - std::memcpy(&str->string[string.size()], nstring.GetConstBuffer(), nstring.m_sharedString->size+1); - - return String(std::move(str)); - } - - /*! - * \brief Checks whether the first string is equal to the second string - * \return true if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator==(const String& first, const String& second) - { - if (first.m_sharedString->size == 0 || second.m_sharedString->size == 0) - return first.m_sharedString->size == second.m_sharedString->size; - - if (first.m_sharedString->size != second.m_sharedString->size) - return false; - - if (first.m_sharedString == second.m_sharedString) - return true; - - return std::strcmp(first.GetConstBuffer(), second.GetConstBuffer()) == 0; - } - - /*! - * \brief Checks whether the first string is equal to the second string - * \return false if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator!=(const String& first, const String& second) - { - return !operator==(first, second); - } - - /*! - * \brief Checks whether the first string is less than the second string - * \return true if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator<(const String& first, const String& second) - { - if (second.m_sharedString->size == 0) - return false; - - if (first.m_sharedString->size == 0) - return true; - - return std::strcmp(first.GetConstBuffer(), second.GetConstBuffer()) < 0; - } - - /*! - * \brief Checks whether the first string is less or equal than the second string - * \return true if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator<=(const String& first, const String& second) - { - return !operator<(second, first); - } - - /*! - * \brief Checks whether the first string is greather than the second string - * \return true if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator>(const String& first, const String& second) - { - return second < first; - } - - /*! - * \brief Checks whether the first string is greather or equal than the second string - * \return true if it is the case - * - * \param first String to compare in left hand side - * \param second String to compare in right hand side - */ - - bool operator>=(const String& first, const String& second) - { - return !operator<(first, second); - } - - /*! - * \brief Checks whether the string is equal to the character - * \return true if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator==(char character, const String& nstring) - { - return nstring == character; - } - - /*! - * \brief Checks whether the string is equal to the "C string" - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator==(const char* string, const String& nstring) - { - return nstring == string; - } - - /*! - * \brief Checks whether the string is equal to the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator==(const std::string& string, const String& nstring) - { - return nstring == string; - } - - /*! - * \brief Checks whether the string is equal to the character - * \return false if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator!=(char character, const String& nstring) - { - return !operator==(character, nstring); - } - - /*! - * \brief Checks whether the string is equal to the "C string" - * \return false if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator!=(const char* string, const String& nstring) - { - return !operator==(string, nstring); - } - - /*! - * \brief Checks whether the string is equal to the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator!=(const std::string& string, const String& nstring) - { - return !operator==(string, nstring); - } - - /*! - * \brief Checks whether the string is less than the character - * \return true if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<(char character, const String& nstring) - { - return nstring > character; - } - - /*! - * \brief Checks whether the string is less than the "C string" - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<(const char* string, const String& nstring) - { - return nstring > string; - } - - /*! - * \brief Checks whether the string is less than the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<(const std::string& string, const String& nstring) - { - return nstring > string; - } - - /*! - * \brief Checks whether the string is less or equal than the character - * \return true if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<=(char character, const String& nstring) - { - return !operator<(nstring, String(character)); - } - - /*! - * \brief Checks whether the string is less or equal than the "C string" - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<=(const char* string, const String& nstring) - { - return !operator<(nstring, string); - } - - /*! - * \brief Checks whether the string is less or equal than the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator<=(const std::string& string, const String& nstring) - { - return !operator<(nstring, string); - } - - /*! - * \brief Checks whether the string is greather than the character - * \return true if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>(char character, const String& nstring) - { - return nstring < character; - } - - /*! - * \brief Checks whether the string is greather than the "C string" - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>(const char* string, const String& nstring) - { - return nstring < string; - } - - /*! - * \brief Checks whether the string is greather than the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>(const std::string& string, const String& nstring) - { - return nstring < string; - } - - /*! - * \brief Checks whether the string is greather or equal than the character - * \return true if it is the case - * - * \param character Single character in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>=(char character, const String& nstring) - { - return !operator<(character, nstring); - } - - /*! - * \brief Checks whether the string is greather or equal than the "C string" - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>=(const char* string, const String& nstring) - { - return !operator<(string, nstring); - } - - /*! - * \brief Checks whether the string is greather or equal than the std::string - * \return true if it is the case - * - * \param string String to compare in left hand side - * \param nstring String to compare in right hand side - */ - - bool operator>=(const std::string& string, const String& nstring) - { - return !operator<(string, nstring); - } - - /*! - * \brief Ensures the ownership of the string - * - * \param discardContent Should discard the content - */ - - void String::EnsureOwnership(bool discardContent) - { - if (!m_sharedString) - return; - - if (!m_sharedString.unique()) - { - auto newSharedString = std::make_shared(GetSize(), GetCapacity()); - if (!discardContent && newSharedString->size > 0) - std::memcpy(newSharedString->string.get(), GetConstBuffer(), GetSize()+1); - - m_sharedString = std::move(newSharedString); - } - } - - /*! - * \brief Gets the empty string - * \return A reference to the empty string - */ - - const std::shared_ptr& String::GetEmptyString() - { - static auto emptyString = std::make_shared(); - return emptyString; - } - - /*! - * \brief Serializes a string - * \return true if successful - * - * \param context Context of serialization - * \param string String to serialize - */ - bool Serialize(SerializationContext& context, const String& string, TypeTag) - { - if (!Serialize(context, UInt32(string.GetSize()))) - return false; - - return context.stream->Write(string.GetConstBuffer(), string.GetSize()) == string.GetSize(); - } - - /*! - * \brief Unserializes a string - * \return true if successful - * - * \param context Context of unserialization - * \param string String to unserialize - */ - bool Unserialize(SerializationContext& context, String* string, TypeTag) - { - UInt32 size; - if (!Unserialize(context, &size)) - return false; - - string->Resize(size); - return context.stream->Read(string->GetBuffer(), size) == size; - } - - const std::size_t String::npos(std::numeric_limits::max()); -} - -namespace std -{ - /*! - * \brief Gets the line from the input stream - * \return A reference to the stream - * - * \param is Input stream to get information from - * \param str String to set - */ - - istream& getline(istream& is, Nz::String& str) - { - return getline(is, str, is.widen('\n')); - } - - /*! - * \brief Gets the line from the input stream - * \return A reference to the stream - * - * \param is Input stream to get information from - * \param str String to set - * \param delim Delimitor defining the end - */ - - istream& getline(istream& is, Nz::String& str, char delim) - { - str.Clear(); - - char c; - - for (;;) - { - is.get(c); - if (c != delim && c != '\0') - str += c; - else - { - if (c == '\0') - is.setstate(std::ios_base::eofbit); - break; - } - } - - return is; - } - - /*! - * \brief Swaps two strings, specialisation of std - * - * \param lhs First string - * \param rhs Second string - */ - - void swap(Nz::String& lhs, Nz::String& rhs) - { - lhs.Swap(rhs); - } -} diff --git a/src/Nazara/Core/StringExt.cpp b/src/Nazara/Core/StringExt.cpp index 3dbdb041e..05d998e91 100644 --- a/src/Nazara/Core/StringExt.cpp +++ b/src/Nazara/Core/StringExt.cpp @@ -13,7 +13,18 @@ namespace Nz { bool IsSpace(char32_t character) { - return character == '\t' || Unicode::GetCategory(character) & Unicode::Category_Separator; + switch (character) + { + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + return true; + + default: + return Unicode::GetCategory(character) & Unicode::Category_Separator; + } } char ToLower(char character) @@ -79,12 +90,6 @@ namespace Nz }; } - std::string FromUtf16String(const char16_t* u16str) - { - std::size_t size = std::char_traits::length(u16str); - return FromUtf16String(std::u16string_view(u16str, size)); - } - std::string FromUtf16String(const std::u16string_view& u16str) { std::string result; @@ -93,12 +98,6 @@ namespace Nz return result; } - std::string FromUtf32String(const char32_t* u32str) - { - std::size_t size = std::char_traits::length(u32str); - return FromUtf32String(std::u32string_view(u32str, size)); - } - std::string FromUtf32String(const std::u32string_view& u32str) { std::string result; @@ -107,17 +106,56 @@ namespace Nz return result; } - std::string FromWideString(const wchar_t* wstr) - { - std::size_t size = std::char_traits::length(wstr); - return WideConverter::From(wstr, size); - } - std::string FromWideString(const std::wstring_view& wstr) { return WideConverter::From(wstr.data(), wstr.size()); } + std::string_view GetWord(const std::string_view& str, std::size_t wordIndex) + { + std::size_t pos = 0; + std::size_t previousPos = 0; + while ((pos = str.find_first_of(" \f\n\r\t\v", previousPos)) != std::string::npos) + { + std::size_t splitPos = previousPos; + previousPos = pos + 1; + + if (pos != splitPos && wordIndex-- == 0) + return str.substr(splitPos, pos - splitPos); + } + + return {}; + } + + std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware) + { + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + + auto FindNextSeparator = [&]() -> std::size_t + { + for (; it != end; ++it) + { + if (IsSpace(*it)) + return true; + } + + return false; + }; + + utf8::unchecked::iterator lastSplit = it; + while (FindNextSeparator()) + { + if (it != lastSplit && wordIndex-- == 0) + return std::string_view(lastSplit.base(), it.base() - lastSplit.base()); + + ++it; + lastSplit = it; + } + + return {}; + } + bool MatchPattern(const std::string_view& str, const std::string_view& pattern) { if (str.empty() || pattern.empty()) @@ -169,27 +207,60 @@ namespace Nz return patternPtr >= patternPtrEnd; } - bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent) + + std::string PointerToString(const void* ptr) { - if (s.size() > str.size()) + constexpr std::size_t capacity = sizeof(void*) * 2 + 2; + + std::string str(capacity, '\0'); + str.resize(std::sprintf(str.data(), "0x%p", ptr)); + + return str; + } + + bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent) + { + if (rhs.size() > lhs.size()) return false; - return std::equal(str.begin(), str.begin() + s.size(), s.begin(), s.end(), [](char c1, char c2) + return std::equal(lhs.begin(), lhs.begin() + rhs.size(), rhs.begin(), rhs.end(), [](char c1, char c2) { return ToLower(c1) == ToLower(c2); }); } - bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent, UnicodeAware) + bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware) { - if (str.empty() || s.empty()) - return str == s; + if (lhs.empty() || rhs.empty()) + return lhs == rhs; - utf8::iterator it(str.data(), str.data(), str.data() + str.size()); - utf8::iterator it2(s.data(), s.data(), s.data() + s.size()); + utf8::iterator it(lhs.data(), lhs.data(), lhs.data() + lhs.size()); + utf8::iterator it2(rhs.data(), rhs.data(), rhs.data() + rhs.size()); do { - if (it2.base() >= s.data() + s.size()) + if (it2.base() >= rhs.data() + rhs.size()) + return true; + + if (*it != *it2) + return false; + + ++it2; + } + while (*it++); + + return true; + } + + bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware) + { + if (lhs.empty() || rhs.empty()) + return lhs == rhs; + + utf8::iterator it(lhs.data(), lhs.data(), lhs.data() + lhs.size()); + utf8::iterator it2(rhs.data(), rhs.data(), rhs.data() + rhs.size()); + do + { + if (it2.base() >= rhs.data() + rhs.size()) return true; if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) @@ -202,6 +273,40 @@ namespace Nz return true; } + bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware) + { + if (lhs.empty() || rhs.empty()) + return lhs == rhs; + + utf8::iterator it(lhs.data(), lhs.data(), lhs.data() + lhs.size()); + utf8::iterator it2(rhs.data(), rhs.data(), rhs.data() + rhs.size()); + + for (; it.base() < lhs.data() + lhs.size(); ++it, ++it2) + { + if (*it != *it2) + return false; + } + + return true; + } + + bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware) + { + if (lhs.empty() || rhs.empty()) + return lhs == rhs; + + utf8::iterator it(lhs.data(), lhs.data(), lhs.data() + lhs.size()); + utf8::iterator it2(rhs.data(), rhs.data(), rhs.data() + rhs.size()); + + for (; it.base() < lhs.data() + lhs.size(); ++it, ++it2) + { + if (Unicode::GetLowercase(*it) != Unicode::GetLowercase(*it2)) + return false; + } + + return true; + } + std::string ToLower(const std::string_view& str) { std::string result; @@ -220,9 +325,9 @@ namespace Nz result.reserve(str.size()); utf8::unchecked::iterator it(str.data()); - do + utf8::unchecked::iterator end(str.data() + str.size()); + for (; it != end; ++it) utf8::append(Unicode::GetLowercase(*it), std::back_inserter(result)); - while (*++it); return result; } @@ -244,10 +349,10 @@ namespace Nz std::string result; result.reserve(str.size()); - utf8::iterator it(str.data(), str.data(), str.data() + str.size()); - do + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + for (; it != end; ++it) utf8::append(Unicode::GetUppercase(*it), std::back_inserter(result)); - while (*++it); return result; } @@ -272,6 +377,151 @@ namespace Nz { return WideConverter::To(str); } + + std::string_view TrimLeft(std::string_view str) + { + while (!str.empty() && IsSpace(str.front())) + str.remove_prefix(1); + + return str; + } + + std::string_view TrimLeft(std::string_view str, UnicodeAware) + { + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + while (it != end && IsSpace(*it)) + ++it; + + return std::string_view(it.base(), end.base() - it.base()); + } + + std::string_view TrimLeft(std::string_view str, char32_t c, UnicodeAware) + { + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + while (it != end && *it == c) + ++it; + + return std::string_view(it.base(), end.base() - it.base()); + } + + std::string_view TrimLeft(std::string_view str, char32_t c, CaseIndependent, UnicodeAware) + { + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + + c = Unicode::GetLowercase(c); + + while (it != end && Unicode::GetLowercase(*it) == c) + ++it; + + return std::string_view(it.base(), end.base() - it.base()); + } + + std::string_view TrimLeft(std::string_view str, Unicode::Category category, UnicodeAware) + { + utf8::unchecked::iterator it(str.data()); + utf8::unchecked::iterator end(str.data() + str.size()); + while (it != end && (Unicode::GetCategory(*it) & category) == category) + ++it; + + return std::string_view(it.base(), end.base() - it.base()); + } + + std::string_view TrimRight(std::string_view str) + { + while (!str.empty() && IsSpace(str.back())) + str.remove_suffix(1); + + return str; + } + + std::string_view TrimRight(std::string_view str, UnicodeAware) + { + if (str.empty()) + return str; + + // Find last character head + const char* lastCharacter = str.data() + str.size() - 1; + while (utf8::internal::is_trail(*lastCharacter) && lastCharacter != str.data()) + --lastCharacter; + + utf8::unchecked::iterator start(str.data()); + utf8::unchecked::iterator it(lastCharacter); + + while (it != start && IsSpace(*it)) + --it; + + ++it; + + return std::string_view(start.base(), it.base() - start.base()); + } + + std::string_view TrimRight(std::string_view str, char32_t c, UnicodeAware) + { + if (str.empty()) + return str; + + // Find last character head + const char* lastCharacter = str.data() + str.size() - 1; + while (utf8::internal::is_trail(*lastCharacter) && lastCharacter != str.data()) + --lastCharacter; + + utf8::unchecked::iterator start(str.data()); + utf8::unchecked::iterator it(lastCharacter); + + while (it != start && *it == c) + --it; + + ++it; + + return std::string_view(start.base(), it.base() - start.base()); + } + + std::string_view TrimRight(std::string_view str, char32_t c, CaseIndependent, UnicodeAware) + { + if (str.empty()) + return str; + + // Find last character head + const char* lastCharacter = str.data() + str.size() - 1; + while (utf8::internal::is_trail(*lastCharacter) && lastCharacter != str.data()) + --lastCharacter; + + utf8::unchecked::iterator start(str.data()); + utf8::unchecked::iterator it(lastCharacter); + + c = Unicode::GetLowercase(c); + + while (it != start && Unicode::GetLowercase(*it) == c) + --it; + + ++it; + + return std::string_view(start.base(), it.base() - start.base()); + } + + std::string_view TrimRight(std::string_view str, Unicode::Category category, UnicodeAware) + { + if (str.empty()) + return str; + + // Find last character head + const char* lastCharacter = str.data() + str.size() - 1; + while (utf8::internal::is_trail(*lastCharacter) && lastCharacter != str.data()) + --lastCharacter; + + utf8::unchecked::iterator start(str.data()); + utf8::unchecked::iterator it(lastCharacter); + + while (it != start && (Unicode::GetCategory(*it) & category) == category) + --it; + + ++it; + + return std::string_view(start.base(), it.base() - start.base()); + } } #include diff --git a/src/Nazara/Core/StringStream.cpp b/src/Nazara/Core/StringStream.cpp deleted file mode 100644 index d6b17cac8..000000000 --- a/src/Nazara/Core/StringStream.cpp +++ /dev/null @@ -1,349 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup core - * \class Nz::StringStream - * \brief Core class that represents a stream of strings - */ - - /*! - * \brief Constructs a StringStream object with a string - * - * \param str First value of the stream - */ - StringStream::StringStream(String str) : - m_result(std::move(str)) - { - } - - /*! - * \brief Resets the state of the stream, erasing every contained text - */ - void StringStream::Clear() - { - m_result.Clear(); - } - - /*! - * \brief Get the current buffer size - * \return The internal accumulation buffer size, this is equivalent to the size of the final string - */ - std::size_t StringStream::GetBufferSize() const - { - return m_result.GetSize(); - } - - /*! - * \brief Gives a string representation - * \return A string representation of the object where every objects of the stream has been converted with Nz::String - */ - String StringStream::ToString() const - { - return m_result; - } - - /*! - * \brief Adds the representation of the boolean - * \return A reference to this - * - * \param boolean Boolean value - */ - StringStream& StringStream::operator<<(bool boolean) - { - std::size_t size = (boolean) ? 4 : 5; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + size); - std::memcpy(&m_result[start], (boolean) ? "true" : "false", size); - - return *this; - } - - /*! - * \brief Adds the representation of the short - * \return A reference to this - * - * \param number Short value - */ - StringStream& StringStream::operator<<(short number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 2; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%hd", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the unsigned short - * \return A reference to this - * - * \param number Short value - */ - StringStream& StringStream::operator<<(unsigned short number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 1; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%hu", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the int - * \return A reference to this - * - * \param number Int value - */ - StringStream& StringStream::operator<<(int number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 2; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%d", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the unsigned int - * \return A reference to this - * - * \param number Int value - */ - StringStream& StringStream::operator<<(unsigned int number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 1; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%u", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the long - * \return A reference to this - * - * \param number Long value - */ - StringStream& StringStream::operator<<(long number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 2; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%ld", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the unsigned long - * \return A reference to this - * - * \param number Long value - */ - StringStream& StringStream::operator<<(unsigned long number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 1; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%lu", number); - m_result.Resize(start + written); - - - return *this; - } - - /*! - * \brief Adds the representation of the long long - * \return A reference to this - * - * \param number Long long value - */ - StringStream& StringStream::operator<<(long long number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 2; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%lld", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the unsigned long long - * \return A reference to this - * - * \param number Long long value - */ - StringStream& StringStream::operator<<(unsigned long long number) - { - constexpr std::size_t maxSize = std::numeric_limits::digits10 + 1; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "%llu", number); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Adds the representation of the float - * \return A reference to this - * - * \param number Float value - */ - StringStream& StringStream::operator<<(float number) - { - return operator<<(double(number)); //< snprintf doesn't support float anyway - } - - /*! - * \brief Adds the representation of the double - * \return A reference to this - * - * \param number Double value - */ - StringStream& StringStream::operator<<(double number) - { - // https://stackoverflow.com/questions/1701055/what-is-the-maximum-length-in-chars-needed-to-represent-any-double-value - const std::size_t maxSize = 3 + std::numeric_limits::digits - std::numeric_limits::min_exponent; - - // Use a temporary buffer to prevent 1kb string capacity growth - std::array buffer; - std::size_t written = std::snprintf(buffer.data(), buffer.size(), "%.6f", number); - - std::size_t start = m_result.GetSize(); - m_result.Resize(start + written); - std::memcpy(&m_result[start], buffer.data(), written); - - return *this; - } - - /*! - * \brief Adds the representation of the long double - * \return A reference to this - * - * \param number Long double value - */ - StringStream& StringStream::operator<<(long double number) - { - // https://stackoverflow.com/questions/1701055/what-is-the-maximum-length-in-chars-needed-to-represent-any-double-value - const std::size_t maxSize = 3 + std::numeric_limits::digits - std::numeric_limits::min_exponent; - - // Use a temporary buffer to prevent 1kb string capacity growth - std::array buffer; - std::size_t written = std::snprintf(buffer.data(), buffer.size(), "%.6Lf", number); - - std::size_t start = m_result.GetSize(); - m_result.Resize(start + written); - std::memcpy(&m_result[start], buffer.data(), written); - - return *this; - } - - /*! - * \brief Adds the representation of the char - * \return A reference to this - * - * \param character Char value - */ - StringStream& StringStream::operator<<(char character) - { - m_result.Append(character); - return *this; - } - - /*! - * \brief Adds the representation of the unsigned char - * \return A reference to this - * - * \param character Char value - */ - StringStream& StringStream::operator<<(unsigned char character) - { - m_result.Append(static_cast(character)); - return *this; - } - - /*! - * \brief Adds the representation of the const char* - * \return A reference to this - * - * \param string String value - */ - StringStream& StringStream::operator<<(const char* string) - { - m_result.Append(string); - return *this; - } - - /*! - * \brief Adds the representation of the std::string - * \return A reference to this - * - * \param string String value - */ - StringStream& StringStream::operator<<(const std::string& string) - { - m_result.Append(string.data(), string.size()); - return *this; - } - - /*! - * \brief Adds the representation of the Nz::String - * \return A reference to this - * - * \param string String value - */ - StringStream& StringStream::operator<<(const String& string) - { - m_result.Append(string); - - return *this; - } - - /*! - * \brief Adds the representation of the pointer - * \return A reference to this - * - * \param ptr Pointer value - */ - StringStream& StringStream::operator<<(const void* ptr) - { - constexpr std::size_t maxSize = sizeof(void*) * 2 + 2; - std::size_t start = m_result.GetSize(); - m_result.Resize(start + maxSize); - std::size_t written = std::snprintf(&m_result[start], maxSize + 1, "0x%p", ptr); - m_result.Resize(start + written); - - return *this; - } - - /*! - * \brief Converts this to Nz::String - * \return The string representation of the stream - */ - StringStream::operator String() const - { - return ToString(); - } -} diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index fd58fc9d8..71274fc47 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -149,7 +149,7 @@ namespace Nz break; default: - NazaraInternalError("Cursor position not handled (0x" + String::Number(pos, 16) + ')'); + NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')'); return false; } diff --git a/src/Nazara/Network/AbstractSocket.cpp b/src/Nazara/Network/AbstractSocket.cpp index d61dfd4b2..205ead63e 100644 --- a/src/Nazara/Network/AbstractSocket.cpp +++ b/src/Nazara/Network/AbstractSocket.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #if defined(NAZARA_PLATFORM_WINDOWS) @@ -177,7 +178,7 @@ namespace Nz { SocketError errorCode; if (!SocketImpl::SetBlocking(m_handle, m_isBlockingEnabled, &errorCode)) - NazaraWarning("Failed to set socket blocking mode (0x" + String::Number(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket blocking mode (0x" + NumberToString(errorCode, 16) + ')'); } /*! @@ -199,7 +200,7 @@ namespace Nz { SocketImpl::Close(handle); - NazaraError("Failed to open a dual-stack socket: " + Nz::String(ErrorToString(m_lastError))); + NazaraError("Failed to open a dual-stack socket: " + std::string(ErrorToString(m_lastError))); return false; } diff --git a/src/Nazara/Network/ENetHost.cpp b/src/Nazara/Network/ENetHost.cpp index 3b176e7e9..778fcdac0 100644 --- a/src/Nazara/Network/ENetHost.cpp +++ b/src/Nazara/Network/ENetHost.cpp @@ -153,7 +153,7 @@ namespace Nz if (peerCount > ENetConstants::ENetProtocol_MaximumPeerId) { - NazaraError("Peer count exceeds maximum peer count supported by protocol (" + String::Number(ENetConstants::ENetProtocol_MaximumPeerId) + ")"); + NazaraError("Peer count exceeds maximum peer count supported by protocol (" + NumberToString(ENetConstants::ENetProtocol_MaximumPeerId) + ")"); return false; } diff --git a/src/Nazara/Network/IpAddress.cpp b/src/Nazara/Network/IpAddress.cpp index e0f5e33f0..fbb528488 100644 --- a/src/Nazara/Network/IpAddress.cpp +++ b/src/Nazara/Network/IpAddress.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -88,7 +89,7 @@ namespace Nz return m_ipv6 == LoopbackIpV6.m_ipv6; // Only compare the ip value } - NazaraInternalError("Invalid protocol for IpAddress (0x" + String::Number(m_protocol) + ')'); + NazaraInternalError("Invalid protocol for IpAddress (0x" + NumberToString(m_protocol) + ')'); return false; } @@ -164,7 +165,7 @@ namespace Nz else if (i != 0) stream << ':'; - stream << String::Number(m_ipv6[i], 16).ToLower(); + stream << ToLower(NumberToString(m_ipv6[i], 16)); } if (m_port != 0) diff --git a/src/Nazara/Network/Linux/SocketPollerImpl.cpp b/src/Nazara/Network/Linux/SocketPollerImpl.cpp index 53de22a70..be848deb1 100644 --- a/src/Nazara/Network/Linux/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Linux/SocketPollerImpl.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -60,7 +61,7 @@ namespace Nz if (epoll_ctl(m_handle, EPOLL_CTL_ADD, socket, &entry) != 0) { - NazaraError("Failed to add socket to epoll structure (errno " + String::Number(errno) + ": " + Error::GetLastSystemError() + ')'); + NazaraError("Failed to add socket to epoll structure (errno " + NumberToString(errno) + ": " + Error::GetLastSystemError() + ')'); return false; } @@ -78,7 +79,7 @@ namespace Nz m_sockets.erase(socket); if (epoll_ctl(m_handle, EPOLL_CTL_DEL, socket, nullptr) != 0) - NazaraWarning("An error occured while removing socket from epoll structure (errno " + String::Number(errno) + ": " + Error::GetLastSystemError() + ')'); + NazaraWarning("An error occured while removing socket from epoll structure (errno " + NumberToString(errno) + ": " + Error::GetLastSystemError() + ')'); } unsigned int SocketPollerImpl::Wait(int msTimeout, SocketError* error) @@ -115,7 +116,7 @@ namespace Nz } else { - NazaraWarning("Descriptor " + String::Number(m_events[i].data.fd) + " was returned by epoll without EPOLLIN nor EPOLLOUT flags (events: 0x" + String::Number(m_events[i].events, 16) + ')'); + NazaraWarning("Descriptor " + NumberToString(m_events[i].data.fd) + " was returned by epoll without EPOLLIN nor EPOLLOUT flags (events: 0x" + NumberToString(m_events[i].events, 16) + ')'); activeSockets--; } } diff --git a/src/Nazara/Network/Posix/IpAddressImpl.cpp b/src/Nazara/Network/Posix/IpAddressImpl.cpp index 3b7a5470b..ac643896c 100644 --- a/src/Nazara/Network/Posix/IpAddressImpl.cpp +++ b/src/Nazara/Network/Posix/IpAddressImpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -216,7 +217,7 @@ namespace Nz } default: - NazaraInternalError("Unhandled ip protocol (0x" + String::Number(ipAddress.GetProtocol()) + ')'); + NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(ipAddress.GetProtocol(), 16) + ')'); break; } } @@ -292,7 +293,7 @@ namespace Nz return ResolveError_TemporaryFailure; } - NazaraWarning("Unhandled EAI error: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ") as " + gai_strerror(error)); + NazaraWarning("Unhandled EAI error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ") as " + gai_strerror(error)); return ResolveError_Unknown; } } diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index af0b5557f..a9623e544 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -955,7 +956,7 @@ namespace Nz case EALREADY: case EISCONN: case EWOULDBLOCK: - NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ')'); + NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + NumberToString(error)+')'); return SocketError_Internal; case EADDRNOTAVAIL: @@ -1001,7 +1002,7 @@ namespace Nz return SocketError_TimedOut; } - NazaraWarning("Unhandled POSIX error: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ')'); + NazaraWarning("Unhandled POSIX error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); return SocketError_Unknown; } diff --git a/src/Nazara/Network/Posix/SocketPollerImpl.cpp b/src/Nazara/Network/Posix/SocketPollerImpl.cpp index fc100d8eb..2e1b03a44 100644 --- a/src/Nazara/Network/Posix/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Posix/SocketPollerImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include @@ -103,7 +104,7 @@ namespace Nz } else { - NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by poll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.revents, 16) + ')'); + NazaraWarning("Socket " + NumberToString(entry.fd) + " was returned by poll without POLLRDNORM nor POLLWRNORM events (events: 0x" + NumberToString(entry.revents, 16) + ')'); activeSockets--; } diff --git a/src/Nazara/Network/RUdpConnection.cpp b/src/Nazara/Network/RUdpConnection.cpp index 4ab592db1..2211c0705 100644 --- a/src/Nazara/Network/RUdpConnection.cpp +++ b/src/Nazara/Network/RUdpConnection.cpp @@ -421,7 +421,7 @@ namespace Nz void RUdpConnection::OnPacketLost(PeerData& peer, PendingAckPacket&& packet) { - //NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + String::Number(packet.sequenceId)); + //NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + NumberToString(packet.sequenceId)); if (IsReliable(packet.reliability)) EnqueuePacketInternal(peer, packet.priority, packet.reliability, std::move(packet.data)); @@ -465,7 +465,7 @@ namespace Nz UInt64 token; packet >> token; - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_RequestConnection from " + peerIp.ToString() + ": " + String::Number(token)); + NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_RequestConnection from " + peerIp.ToString() + ": " + NumberToString(token)); if (!m_shouldAcceptConnections) return; //< Ignore @@ -487,7 +487,7 @@ namespace Nz if (m_isSimulationEnabled && m_packetLossProbability(s_randomGenerator)) { - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + String::Number(sequenceId) + " from " + peerIp.ToString() + " for simulation purpose"); + NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + NumberToString(sequenceId) + " from " + peerIp.ToString() + " for simulation purpose"); return; } @@ -519,7 +519,7 @@ namespace Nz UInt64 token; packet /*>> externalAddress*/ >> token; - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_AcknowledgeConnection from " + peerIp.ToString() + ": " + String::Number(token)); + NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_AcknowledgeConnection from " + peerIp.ToString() + ": " + NumberToString(token)); if (token == ~peer.stateData1) { peer.state = PeerState_Connected; @@ -527,7 +527,7 @@ namespace Nz } else { - NazaraNotice("Received wrong token (" + String::Number(token) + " instead of " + String::Number(~peer.stateData1) + ") from client " + peer.address.ToString()); + NazaraNotice("Received wrong token (" + NumberToString(token) + " instead of " + NumberToString(~peer.stateData1) + ") from client " + peer.address.ToString()); return; //< Ignore } @@ -553,7 +553,7 @@ namespace Nz default: { - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received 0x" + String::Number(packet.GetNetCode(), 16) + " from " + peerIp.ToString()); + NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received 0x" + NumberToString(packet.GetNetCode(), 16) + " from " + peerIp.ToString()); RUdpMessage receivedMessage; receivedMessage.from = peerIp; receivedMessage.data = std::move(packet); diff --git a/src/Nazara/Network/SocketPoller.cpp b/src/Nazara/Network/SocketPoller.cpp index 5ef9f617a..93c6d21a1 100644 --- a/src/Nazara/Network/SocketPoller.cpp +++ b/src/Nazara/Network/SocketPoller.cpp @@ -3,6 +3,8 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include +#include #include #if defined(NAZARA_PLATFORM_WINDOWS) @@ -195,7 +197,7 @@ namespace Nz if (waitError != SocketError_NoError) { if (waitError != SocketError_Interrupted) //< Do not log interrupted error - NazaraError("SocketPoller encountered an error (code: 0x" + String::Number(waitError, 16) + "): " + ErrorToString(waitError)); + NazaraError("SocketPoller encountered an error (code: 0x" + NumberToString(waitError, 16) + "): " + ErrorToString(waitError)); return 0; } diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index ec983645b..ecff0e6e4 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -213,7 +214,7 @@ namespace Nz break; } - NazaraInternalError("Unexpected socket state (0x" + String::Number(m_state, 16) + ')'); + NazaraInternalError("Unexpected socket state (0x" + NumberToString(m_state, 16) + ')'); return m_state; } @@ -520,7 +521,7 @@ namespace Nz break; } - NazaraInternalError("Unhandled socket state (0x" + String::Number(m_state, 16) + ')'); + NazaraInternalError("Unhandled socket state (0x" + NumberToString(m_state, 16) + ')'); return m_state; } @@ -557,10 +558,10 @@ namespace Nz SocketError errorCode; if (!SocketImpl::SetNoDelay(m_handle, m_isLowDelayEnabled, &errorCode)) - NazaraWarning("Failed to set socket no delay mode (0x" + String::Number(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket no delay mode (0x" + NumberToString(errorCode, 16) + ')'); if (!SocketImpl::SetKeepAlive(m_handle, m_isKeepAliveEnabled, m_keepAliveTime, m_keepAliveInterval, &errorCode)) - NazaraWarning("Failed to set socket keep alive mode (0x" + String::Number(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket keep alive mode (0x" + NumberToString(errorCode, 16) + ')'); m_peerAddress = IpAddress::Invalid; m_openMode = OpenMode_ReadWrite; diff --git a/src/Nazara/Network/UdpSocket.cpp b/src/Nazara/Network/UdpSocket.cpp index 5d8e87f17..e0209c427 100644 --- a/src/Nazara/Network/UdpSocket.cpp +++ b/src/Nazara/Network/UdpSocket.cpp @@ -3,6 +3,8 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include +#include #include #if defined(NAZARA_PLATFORM_WINDOWS) @@ -193,7 +195,7 @@ namespace Nz if (packetSize != received) { m_lastError = SocketError_Packet; - NazaraWarning("Invalid packet size (packet size is " + String::Number(packetSize) + " bytes, received " + Nz::String::Number(received) + " bytes)"); + NazaraWarning("Invalid packet size (packet size is " + NumberToString(packetSize) + " bytes, received " + NumberToString(received) + " bytes)"); return false; } diff --git a/src/Nazara/Network/Win32/IpAddressImpl.cpp b/src/Nazara/Network/Win32/IpAddressImpl.cpp index 6008eb59c..570cf8fe2 100644 --- a/src/Nazara/Network/Win32/IpAddressImpl.cpp +++ b/src/Nazara/Network/Win32/IpAddressImpl.cpp @@ -271,7 +271,7 @@ namespace Nz } default: - NazaraInternalError("Unhandled ip protocol (0x" + String::Number(ipAddress.GetProtocol()) + ')'); + NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(ipAddress.GetProtocol()) + ')'); break; } } @@ -346,7 +346,7 @@ namespace Nz return ResolveError_TemporaryFailure; } - NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ')'); + NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); return ResolveError_Unknown; } } diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 468948133..349dfea0a 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include // Some compilers (older versions of MinGW) lack Mstcpip.h which defines some structs/defines @@ -163,7 +164,7 @@ namespace Nz return false; } - NazaraDebug("Initialized Windows Socket " + String::Number(LOBYTE(s_WSA.wVersion)) + '.' + String::Number(HIBYTE(s_WSA.wVersion)) + " (" + String(s_WSA.szDescription) + ')'); + NazaraDebug("Initialized Windows Socket " + NumberToString(LOBYTE(s_WSA.wVersion)) + '.' + NumberToString(HIBYTE(s_WSA.wVersion)) + " (" + std::string(s_WSA.szDescription) + ')'); return true; } @@ -955,7 +956,7 @@ namespace Nz case WSAEALREADY: case WSAEISCONN: case WSAEWOULDBLOCK: - NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ')'); + NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); return SocketError_Internal; case WSAEADDRNOTAVAIL: @@ -1000,7 +1001,7 @@ namespace Nz return SocketError_TimedOut; } - NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + String::Number(error) + ')'); + NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); return SocketError_Unknown; } diff --git a/src/Nazara/Network/Win32/SocketPollerImpl.cpp b/src/Nazara/Network/Win32/SocketPollerImpl.cpp index 93142e755..927d0b447 100644 --- a/src/Nazara/Network/Win32/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Win32/SocketPollerImpl.cpp @@ -3,6 +3,8 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include +#include #include namespace Nz @@ -89,7 +91,7 @@ namespace Nz fd_set& targetSet = (i == 0) ? m_readSockets : m_writeSockets; if (targetSet.fd_count > FD_SETSIZE) { - NazaraError("Socket count exceeding hard-coded FD_SETSIZE (" + String::Number(FD_SETSIZE) + ")"); + NazaraError("Socket count exceeding hard-coded FD_SETSIZE (" + NumberToString(FD_SETSIZE) + ")"); return false; } @@ -157,7 +159,7 @@ namespace Nz } else { - NazaraWarning("Socket " + String::Number(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + String::Number(entry.revents, 16) + ')'); + NazaraWarning("Socket " + NumberToString(entry.fd) + " was returned by WSAPoll without POLLRDNORM nor POLLWRNORM events (events: 0x" + NumberToString(entry.revents, 16) + ')'); activeSockets--; } diff --git a/src/Nazara/OpenGLRenderer/OpenGLBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLBuffer.cpp index 1745cee73..236380511 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLBuffer.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -37,7 +36,7 @@ namespace Nz case BufferType_Vertex: target = GL::BufferTarget::Array; break; default: - throw std::runtime_error("unknown buffer type 0x" + String::Number(UnderlyingCast(m_type), 16).ToStdString()); + throw std::runtime_error("unknown buffer type 0x" + NumberToString(UnderlyingCast(m_type), 16)); } GLenum hint = GL_STREAM_COPY; diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index 40171f442..f23eba582 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -49,7 +49,7 @@ namespace Nz break; } - throw std::runtime_error(("component type 0x" + String::Number(component, 16) + " is not handled").ToStdString()); + throw std::runtime_error("component type 0x" + NumberToString(component, 16) + " is not handled"); } } diff --git a/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp b/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp index 4ab8d0c06..f5c69190a 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.cpp @@ -31,7 +31,7 @@ namespace Nz break; default: - throw std::runtime_error(("unknown binding type 0x" + String::Number(UnderlyingCast(bindingInfo.type), 16)).ToStdString()); + throw std::runtime_error("unknown binding type 0x" + NumberToString(UnderlyingCast(bindingInfo.type), 16)); } } } diff --git a/src/Nazara/OpenGLRenderer/Utils_OpenGLRenderer.cpp b/src/Nazara/OpenGLRenderer/Utils_OpenGLRenderer.cpp index 80809c949..10ac5f987 100644 --- a/src/Nazara/OpenGLRenderer/Utils_OpenGLRenderer.cpp +++ b/src/Nazara/OpenGLRenderer/Utils_OpenGLRenderer.cpp @@ -99,7 +99,7 @@ namespace Nz break; } - return "Unknown OpenGL error (0x" + String::Number(code, 16).ToStdString() + ')'; + return "Unknown OpenGL error (0x" + NumberToString(code, 16) + ')'; } } diff --git a/src/Nazara/Physics3D/Collider3D.cpp b/src/Nazara/Physics3D/Collider3D.cpp index 800caaa9b..7736e6129 100644 --- a/src/Nazara/Physics3D/Collider3D.cpp +++ b/src/Nazara/Physics3D/Collider3D.cpp @@ -30,7 +30,7 @@ namespace Nz return SphereCollider3D::New(primitive.sphere.size, primitive.matrix.GetTranslation()); } - NazaraError("Primitive type not handled (0x" + String::Number(primitive.type, 16) + ')'); + NazaraError("Primitive type not handled (0x" + NumberToString(primitive.type, 16) + ')'); return Collider3DRef(); } } diff --git a/src/Nazara/Physics3D/PhysWorld3D.cpp b/src/Nazara/Physics3D/PhysWorld3D.cpp index 34214a96f..534b48935 100644 --- a/src/Nazara/Physics3D/PhysWorld3D.cpp +++ b/src/Nazara/Physics3D/PhysWorld3D.cpp @@ -27,7 +27,7 @@ namespace Nz NewtonDestroy(m_world); } - int PhysWorld3D::CreateMaterial(String name) + int PhysWorld3D::CreateMaterial(std::string name) { NazaraAssert(m_materialIds.find(name) == m_materialIds.end(), "Material \"" + name + "\" already exists"); @@ -60,7 +60,7 @@ namespace Nz return m_world; } - int PhysWorld3D::GetMaterial(const String& name) + int PhysWorld3D::GetMaterial(const std::string& name) { auto it = m_materialIds.find(name); NazaraAssert(it != m_materialIds.end(), "Material \"" + name + "\" does not exists"); @@ -159,7 +159,7 @@ namespace Nz } } - int PhysWorld3D::OnAABBOverlap(const NewtonJoint* const contactJoint, dFloat timestep, int threadIndex) + int PhysWorld3D::OnAABBOverlap(const NewtonJoint* const contactJoint, float timestep, int threadIndex) { RigidBody3D* bodyA = static_cast(NewtonBodyGetUserData(NewtonJointGetBody0(contactJoint))); RigidBody3D* bodyB = static_cast(NewtonBodyGetUserData(NewtonJointGetBody1(contactJoint))); diff --git a/src/Nazara/Physics3D/RigidBody3D.cpp b/src/Nazara/Physics3D/RigidBody3D.cpp index 945dad5a9..c6fc9b891 100644 --- a/src/Nazara/Physics3D/RigidBody3D.cpp +++ b/src/Nazara/Physics3D/RigidBody3D.cpp @@ -345,7 +345,7 @@ namespace Nz NewtonBodySetCentreOfMass(m_body, ¢er.x); } - void RigidBody3D::SetMaterial(const String& materialName) + void RigidBody3D::SetMaterial(const std::string& materialName) { SetMaterial(m_world->GetMaterial(materialName)); } diff --git a/src/Nazara/Platform/Keyboard.cpp b/src/Nazara/Platform/Keyboard.cpp index 149361132..f5a5b79bb 100644 --- a/src/Nazara/Platform/Keyboard.cpp +++ b/src/Nazara/Platform/Keyboard.cpp @@ -8,12 +8,12 @@ namespace Nz { - String Keyboard::GetKeyName(Scancode scancode) + std::string Keyboard::GetKeyName(Scancode scancode) { return EventImpl::GetKeyName(scancode); } - String Keyboard::GetKeyName(VKey key) + std::string Keyboard::GetKeyName(VKey key) { return EventImpl::GetKeyName(key); } diff --git a/src/Nazara/Platform/SDL2/InputImpl.cpp b/src/Nazara/Platform/SDL2/InputImpl.cpp index 933d40e60..97ec9ea92 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.cpp +++ b/src/Nazara/Platform/SDL2/InputImpl.cpp @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine - Platform module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include -#include #include #include #include @@ -14,26 +14,30 @@ namespace Nz { - String EventImpl::GetKeyName(Keyboard::Scancode key) + std::string EventImpl::GetKeyName(Keyboard::Scancode key) { SDL_Scancode scancode = SDLHelper::ToSDL(key); - String name; + std::string name; if (scancode != SDL_SCANCODE_UNKNOWN) name = SDL_GetScancodeName(scancode); + else + name = "Unknown"; - return !name.IsEmpty() ? name : String::Unicode("Unknown"); + return name; } - String EventImpl::GetKeyName(Keyboard::VKey key) + std::string EventImpl::GetKeyName(Keyboard::VKey key) { SDL_Keycode vkey = SDLHelper::ToSDL(key); - String name; + std::string name; if (vkey != SDLK_UNKNOWN) name = SDL_GetKeyName(vkey); + else + name = "Unknown"; - return !name.IsEmpty() ? name : String::Unicode("Unknown"); + return name; } Vector2i EventImpl::GetMousePosition() diff --git a/src/Nazara/Platform/SDL2/InputImpl.hpp b/src/Nazara/Platform/SDL2/InputImpl.hpp index 3c175a0db..0f1c41a72 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.hpp +++ b/src/Nazara/Platform/SDL2/InputImpl.hpp @@ -7,18 +7,18 @@ #ifndef NAZARA_INPUTIMPL_HPP #define NAZARA_INPUTIMPL_HPP -#include #include #include #include +#include namespace Nz { class EventImpl { public: - static String GetKeyName(Keyboard::Scancode scancode); - static String GetKeyName(Keyboard::VKey key); + static std::string GetKeyName(Keyboard::Scancode scancode); + static std::string GetKeyName(Keyboard::VKey key); static Vector2i GetMousePosition(); static Vector2i GetMousePosition(const Window& relativeTo); static bool IsKeyPressed(Keyboard::Scancode key); diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index c4fe1076b..c50b976c7 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Platform module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -60,7 +60,7 @@ namespace Nz m_cursor = SDL_GetDefaultCursor(); } - bool WindowImpl::Create(const VideoMode& mode, const String& title, WindowStyleFlags style) + bool WindowImpl::Create(const VideoMode& mode, const std::string& title, WindowStyleFlags style) { bool async = (style & WindowStyle_Threaded) != 0; if (async) @@ -108,7 +108,7 @@ namespace Nz m_sizemove = false; m_style = style; - m_handle = SDL_CreateWindow(title.GetConstBuffer(), x, y, width, height, winStyle); + m_handle = SDL_CreateWindow(title.c_str(), x, y, width, height, winStyle); if (!m_handle) { @@ -240,9 +240,9 @@ namespace Nz return handle; } - String WindowImpl::GetTitle() const + std::string WindowImpl::GetTitle() const { - return String::Unicode(SDL_GetWindowTitle(m_handle)); + return SDL_GetWindowTitle(m_handle); } bool WindowImpl::HasFocus() const @@ -491,7 +491,7 @@ namespace Nz evt.type = WindowEventType_TextEntered; evt.text.repeated = false; - for (decltype(evt.text.character) codepoint : String::Unicode(event->text.text).Simplify().GetUtf32String()) + for (decltype(evt.text.character) codepoint : ToUtf32String(event->text.text)) { evt.text.character = codepoint; @@ -589,9 +589,9 @@ namespace Nz NazaraDebug("Stay on top isn't supported by SDL2 backend for now"); } - void WindowImpl::SetTitle(const String& title) + void WindowImpl::SetTitle(const std::string& title) { - SDL_SetWindowTitle(m_handle, title.GetConstBuffer()); + SDL_SetWindowTitle(m_handle, title.c_str()); } void WindowImpl::SetVisible(bool visible) diff --git a/src/Nazara/Platform/SDL2/WindowImpl.hpp b/src/Nazara/Platform/SDL2/WindowImpl.hpp index 7080e14e7..01c05cf77 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.hpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.hpp @@ -9,7 +9,6 @@ #ifndef NAZARA_WINDOWIMPL_HPP #define NAZARA_WINDOWIMPL_HPP -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include namespace Nz { @@ -34,7 +34,7 @@ namespace Nz WindowImpl(WindowImpl&&) = delete; ///TODO? ~WindowImpl() = default; - bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style); + bool Create(const VideoMode& mode, const std::string& title, WindowStyleFlags style); bool Create(void* handle); void Destroy(); @@ -47,7 +47,7 @@ namespace Nz Vector2ui GetSize() const; WindowStyleFlags GetStyle() const; WindowHandle GetSystemHandle() const; - String GetTitle() const; + std::string GetTitle() const; bool HasFocus() const; @@ -69,7 +69,7 @@ namespace Nz void SetPosition(int x, int y); void SetSize(unsigned int width, unsigned int height); void SetStayOnTop(bool stayOnTop); - void SetTitle(const String& title); + void SetTitle(const std::string& title); void SetVisible(bool visible); WindowImpl& operator=(const WindowImpl&) = delete; diff --git a/src/Nazara/Platform/Window.cpp b/src/Nazara/Platform/Window.cpp index b23b88d30..733a459c3 100644 --- a/src/Nazara/Platform/Window.cpp +++ b/src/Nazara/Platform/Window.cpp @@ -7,7 +7,7 @@ #include #include #include - #include +#include #include namespace Nz @@ -50,7 +50,7 @@ namespace Nz Destroy(); } - bool Window::Create(VideoMode mode, const String& title, WindowStyleFlags style) + bool Window::Create(VideoMode mode, const std::string& title, WindowStyleFlags style) { // If the window is already open, we keep its position bool opened = IsOpen(); @@ -65,7 +65,7 @@ namespace Nz { if (fullscreenWindow) { - NazaraError("Window " + String::Pointer(fullscreenWindow) + " already in fullscreen mode"); + NazaraError("Window " + PointerToString(fullscreenWindow) + " already in fullscreen mode"); style &= ~WindowStyle_Fullscreen; } else @@ -245,13 +245,13 @@ namespace Nz return m_impl->GetSystemHandle(); } - String Window::GetTitle() const + std::string Window::GetTitle() const { #if NAZARA_PLATFORM_SAFE if (!m_impl) { NazaraError("Window not created"); - return String(); + return {}; } #endif @@ -508,7 +508,7 @@ namespace Nz m_impl->SetStayOnTop(stayOnTop); } - void Window::SetTitle(const String& title) + void Window::SetTitle(const std::string& title) { #if NAZARA_PLATFORM_SAFE if (!m_impl) diff --git a/src/Nazara/Shader/GlslWriter.cpp b/src/Nazara/Shader/GlslWriter.cpp index 4e22aeffc..ccea40fe7 100644 --- a/src/Nazara/Shader/GlslWriter.cpp +++ b/src/Nazara/Shader/GlslWriter.cpp @@ -253,7 +253,7 @@ namespace Nz { NazaraAssert(m_currentState, "This function should only be called while processing an AST"); - String stars((section.size() < 33) ? (36 - section.size()) / 2 : 3, '*'); + std::string stars((section.size() < 33) ? (36 - section.size()) / 2 : 3, '*'); m_currentState->stream << "/*" << stars << ' ' << section << ' ' << stars << "*/"; AppendLine(); } diff --git a/src/Nazara/Utility/Animation.cpp b/src/Nazara/Utility/Animation.cpp index 81f627f8e..635c96694 100644 --- a/src/Nazara/Utility/Animation.cpp +++ b/src/Nazara/Utility/Animation.cpp @@ -16,7 +16,7 @@ namespace Nz { struct AnimationImpl { - std::unordered_map sequenceMap; + std::unordered_map sequenceMap; std::vector sequences; std::vector sequenceJoints; // Uniquement pour les animations squelettiques AnimationType type; @@ -58,7 +58,7 @@ namespace Nz } } - if (!sequence.name.IsEmpty()) + if (!sequence.name.empty()) { #if NAZARA_UTILITY_SAFE auto it = m_impl->sequenceMap.find(sequence.name); @@ -147,7 +147,7 @@ namespace Nz return m_impl->jointCount; } - Sequence* Animation::GetSequence(const String& sequenceName) + Sequence* Animation::GetSequence(const std::string& sequenceName) { NazaraAssert(m_impl, "Animation not created"); @@ -169,7 +169,7 @@ namespace Nz return &m_impl->sequences[index]; } - const Sequence* Animation::GetSequence(const String& sequenceName) const + const Sequence* Animation::GetSequence(const std::string& sequenceName) const { NazaraAssert(m_impl, "Animation not created"); @@ -198,7 +198,7 @@ namespace Nz return static_cast(m_impl->sequences.size()); } - std::size_t Animation::GetSequenceIndex(const String& sequenceName) const + std::size_t Animation::GetSequenceIndex(const std::string& sequenceName) const { NazaraAssert(m_impl, "Animation not created"); @@ -235,7 +235,7 @@ namespace Nz return m_impl->type; } - bool Animation::HasSequence(const String& sequenceName) const + bool Animation::HasSequence(const std::string& sequenceName) const { NazaraAssert(m_impl, "Animation not created"); @@ -261,7 +261,7 @@ namespace Nz return m_impl != nullptr; } - void Animation::RemoveSequence(const String& identifier) + void Animation::RemoveSequence(const std::string& identifier) { NazaraAssert(m_impl, "Animation not created"); diff --git a/src/Nazara/Utility/Font.cpp b/src/Nazara/Utility/Font.cpp index 7900760d9..aa91678af 100644 --- a/src/Nazara/Utility/Font.cpp +++ b/src/Nazara/Utility/Font.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -146,13 +147,13 @@ namespace Nz return count; } - String Font::GetFamilyName() const + std::string Font::GetFamilyName() const { #if NAZARA_UTILITY_SAFE if (!IsValid()) { NazaraError("Invalid font"); - return String("Invalid font"); + return std::string("Invalid font"); } #endif @@ -237,13 +238,13 @@ namespace Nz return it->second; } - String Font::GetStyleName() const + std::string Font::GetStyleName() const { #if NAZARA_UTILITY_SAFE if (!IsValid()) { NazaraError("Invalid font"); - return String("Invalid font"); + return std::string("Invalid font"); } #endif @@ -261,10 +262,10 @@ namespace Nz return PrecacheGlyph(m_glyphes[key], characterSize, style, outlineThickness, character).valid; } - bool Font::Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const String& characterSet) const + bool Font::Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const std::string& characterSet) const { ///TODO: Itération UTF-8 => UTF-32 sans allocation de buffer (Exposer utf8cpp ?) - std::u32string set = characterSet.GetUtf32String(); + std::u32string set = ToUtf32String(characterSet); if (set.empty()) { NazaraError("Invalid character set"); @@ -548,7 +549,7 @@ namespace Nz glyph.valid = true; } else - NazaraWarning("Failed to extract glyph \"" + String::Unicode(character) + "\""); + NazaraWarning("Failed to extract glyph \"" + FromUtf32String(std::u32string_view(&character, 1)) + "\""); } else { diff --git a/src/Nazara/Utility/Formats/DDSLoader.cpp b/src/Nazara/Utility/Formats/DDSLoader.cpp index 4d2edf50e..b269e0daa 100644 --- a/src/Nazara/Utility/Formats/DDSLoader.cpp +++ b/src/Nazara/Utility/Formats/DDSLoader.cpp @@ -99,7 +99,7 @@ namespace Nz if (byteStream.Read(ptr, byteCount) != byteCount) { - NazaraError("Failed to read level #" + String::Number(i)); + NazaraError("Failed to read level #" + NumberToString(i)); return nullptr; } @@ -245,7 +245,7 @@ namespace Nz buf[3] = (header.format.fourCC >> 24) & 255; buf[4] = '\0'; - NazaraError("Unhandled format \"" + String(buf) + "\""); + NazaraError("Unhandled format \"" + std::string(buf) + "\""); return false; } } diff --git a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp index aaba0dc87..96b4b9d6c 100644 --- a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp +++ b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include namespace Nz @@ -243,12 +244,12 @@ namespace Nz return true; } - String GetFamilyName() const override + std::string GetFamilyName() const override { return m_face->family_name; } - String GetStyleName() const override + std::string GetStyleName() const override { return m_face->style_name; } diff --git a/src/Nazara/Utility/Formats/MD5AnimParser.cpp b/src/Nazara/Utility/Formats/MD5AnimParser.cpp index f85a279c5..8a79d753d 100644 --- a/src/Nazara/Utility/Formats/MD5AnimParser.cpp +++ b/src/Nazara/Utility/Formats/MD5AnimParser.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -81,13 +82,13 @@ namespace Nz { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING case 'M': // MD5Version - if (m_currentLine.GetWord(0) != "MD5Version") + if (GetWord(m_currentLine, 0) != "MD5Version") UnrecognizedLine(); break; #endif case 'b': // baseframe/bounds - if (m_currentLine.StartsWith("baseframe {")) + if (StartsWith(m_currentLine, "baseframe {")) { if (!ParseBaseframe()) { @@ -95,7 +96,7 @@ namespace Nz return false; } } - else if (m_currentLine.StartsWith("bounds {")) + else if (StartsWith(m_currentLine, "bounds {")) { if (!ParseBounds()) { @@ -111,7 +112,7 @@ namespace Nz #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING case 'c': // commandline - if (m_currentLine.GetWord(0) != "commandline") + if (GetWord(m_currentLine, 0) != "commandline") UnrecognizedLine(); break; #endif @@ -123,7 +124,7 @@ namespace Nz { if (m_frameIndex != index) { - Error("Unexpected frame index (expected " + String::Number(m_frameIndex) + ", got " + String::Number(index) + ')'); + Error("Unexpected frame index (expected " + NumberToString(m_frameIndex) + ", got " + NumberToString(index) + ')'); return false; } @@ -145,7 +146,7 @@ namespace Nz } case 'h': // hierarchy - if (m_currentLine.StartsWith("hierarchy {")) + if (StartsWith(m_currentLine, "hierarchy {")) { if (!ParseHierarchy()) { @@ -220,7 +221,7 @@ namespace Nz if (m_frameIndex != frameCount) { - NazaraError("Missing frame infos: [" + String::Number(m_frameIndex) + ',' + String::Number(frameCount) + ']'); + NazaraError("Missing frame infos: [" + NumberToString(m_frameIndex) + ',' + NumberToString(frameCount) + ']'); return false; } @@ -250,13 +251,10 @@ namespace Nz m_lineCount++; m_currentLine = m_stream.ReadLine(); - if (m_currentLine.IsEmpty()) - continue; - - m_currentLine = m_currentLine.SubStringTo("//"); // On ignore les commentaires - m_currentLine.Simplify(); // Pour un traitement plus simple + if (std::size_t pos = m_currentLine.find("//"); pos != std::string::npos) + m_currentLine.resize(pos); } - while (m_currentLine.IsEmpty()); + while (m_currentLine.empty()); } else m_keepLastLine = false; @@ -264,9 +262,9 @@ namespace Nz return true; } - void MD5AnimParser::Error(const String& message) + void MD5AnimParser::Error(const std::string& message) { - NazaraError(message + " at line #" + String::Number(m_lineCount)); + NazaraError(message + " at line #" + NumberToString(m_lineCount)); } bool MD5AnimParser::ParseBaseframe() @@ -295,7 +293,7 @@ namespace Nz if (!Advance()) return false; - if (m_currentLine != '}') + if (m_currentLine != "}") { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING Warning("Bounds braces closing not found"); @@ -336,7 +334,7 @@ namespace Nz if (!Advance()) return false; - if (m_currentLine != '}') + if (m_currentLine != "}") { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING Warning("Bounds braces closing not found"); @@ -365,7 +363,7 @@ namespace Nz return false; } - String line; + std::string line; std::size_t count = 0; do @@ -374,7 +372,7 @@ namespace Nz return false; std::size_t index = 0; - std::size_t size = m_currentLine.GetSize(); + std::size_t size = m_currentLine.size(); do { float f; @@ -430,7 +428,7 @@ namespace Nz if (!Advance(false)) return true; - if (m_currentLine != '}') + if (m_currentLine != "}") { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING Warning("Hierarchy braces closing not found"); @@ -457,8 +455,8 @@ namespace Nz if (!Advance()) return false; - std::size_t pos = m_currentLine.Find(' '); - if (pos == String::npos) + std::size_t pos = m_currentLine.find(' '); + if (pos == std::string::npos) { UnrecognizedLine(true); return false; @@ -477,15 +475,14 @@ namespace Nz return false; } - m_joints[i].name = name; - m_joints[i].name.Trim('"'); + m_joints[i].name = Trim(name, '"'); Int32 parent = m_joints[i].parent; if (parent >= 0) { if (static_cast(parent) >= jointCount) { - Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')'); + Error("Joint's parent is out of bounds (" + NumberToString(parent) + " >= " + NumberToString(jointCount) + ')'); return false; } } @@ -494,7 +491,7 @@ namespace Nz if (!Advance()) return false; - if (m_currentLine != '}') + if (m_currentLine != "}") { #if NAZARA_UTILITY_STRICT_RESOURCE_PARSING Warning("Hierarchy braces closing not found"); @@ -507,14 +504,14 @@ namespace Nz return true; } - void MD5AnimParser::Warning(const String& message) + void MD5AnimParser::Warning(const std::string& message) { - NazaraWarning(message + " at line #" + String::Number(m_lineCount)); + NazaraWarning(message + " at line #" + NumberToString(m_lineCount)); } void MD5AnimParser::UnrecognizedLine(bool error) { - String message = "Unrecognized \"" + m_currentLine + '"'; + std::string message = "Unrecognized \"" + m_currentLine + '"'; if (error) Error(message); diff --git a/src/Nazara/Utility/Formats/MD5MeshParser.cpp b/src/Nazara/Utility/Formats/MD5MeshParser.cpp index 9556e1ced..a2d00dc3e 100644 --- a/src/Nazara/Utility/Formats/MD5MeshParser.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshParser.cpp @@ -229,7 +229,7 @@ namespace Nz return false; std::size_t pos = m_currentLine.find(' '); - if (pos == String::npos) + if (pos == std::string::npos) { UnrecognizedLine(true); return false; @@ -250,8 +250,7 @@ namespace Nz return false; } - m_joints[i].name = name; - m_joints[i].name.Trim('"'); + m_joints[i].name = Trim(name, '"'); Int32 parent = m_joints[i].parent; if (parent >= 0) diff --git a/src/Nazara/Utility/Formats/MTLParser.cpp b/src/Nazara/Utility/Formats/MTLParser.cpp index d2f3ea4ae..1d64820cf 100644 --- a/src/Nazara/Utility/Formats/MTLParser.cpp +++ b/src/Nazara/Utility/Formats/MTLParser.cpp @@ -499,7 +499,7 @@ namespace Nz }); } - m_outputStream.Clear(); + m_outputStream.str({}); EmitLine("# Exported by Nazara Engine"); EmitLine(); @@ -510,7 +510,7 @@ namespace Nz for (auto& pair : m_materials) { - const String& matName = pair.first; + const std::string& matName = pair.first; const Material& mat = pair.second; Emit("newmtl "); diff --git a/src/Nazara/Utility/Formats/OBJLoader.cpp b/src/Nazara/Utility/Formats/OBJLoader.cpp index 125fdc3d8..7967fa7ed 100644 --- a/src/Nazara/Utility/Formats/OBJLoader.cpp +++ b/src/Nazara/Utility/Formats/OBJLoader.cpp @@ -58,7 +58,7 @@ namespace Nz return false; } - std::unordered_map materialCache; + std::unordered_map materialCache; std::filesystem::path baseDir = file.GetDirectory(); for (std::size_t i = 0; i < meshCount; ++i) { diff --git a/src/Nazara/Utility/Formats/OBJParser.cpp b/src/Nazara/Utility/Formats/OBJParser.cpp index bb0bf9246..1fdb96dba 100644 --- a/src/Nazara/Utility/Formats/OBJParser.cpp +++ b/src/Nazara/Utility/Formats/OBJParser.cpp @@ -503,7 +503,7 @@ namespace Nz }); } - m_outputStream.Clear(); + m_outputStream.str({}); EmitLine("# Exported by Nazara Engine"); EmitLine(); diff --git a/src/Nazara/Utility/Formats/OBJSaver.cpp b/src/Nazara/Utility/Formats/OBJSaver.cpp index 58cf15f70..9945d5f55 100644 --- a/src/Nazara/Utility/Formats/OBJSaver.cpp +++ b/src/Nazara/Utility/Formats/OBJSaver.cpp @@ -101,11 +101,8 @@ namespace Nz { const ParameterList& matData = mesh.GetMaterialData(i); - String nzname; std::string name; - if (matData.GetStringParameter(MaterialData::Name, &nzname)) - name = nzname.ToStdString(); - else + if (!matData.GetStringParameter(MaterialData::Name, &name)) name = "material_" + std::to_string(i); // Makes sure we only have one material of that name @@ -117,10 +114,7 @@ namespace Nz MTLParser::Material* material = mtlFormat.AddMaterial(name); - String strVal; - if (matData.GetStringParameter(MaterialData::FilePath, &strVal)) - material->diffuseMap = strVal.ToStdString(); - else + if (!matData.GetStringParameter(MaterialData::FilePath, &material->diffuseMap)) { Color colorVal; double dValue; @@ -137,14 +131,9 @@ namespace Nz if (matData.GetDoubleParameter(MaterialData::Shininess, &dValue)) material->shininess = float(dValue); - if (matData.GetStringParameter(MaterialData::AlphaTexturePath, &strVal)) - material->alphaMap = strVal.ToStdString(); - - if (matData.GetStringParameter(MaterialData::DiffuseTexturePath, &strVal)) - material->diffuseMap = strVal.ToStdString(); - - if (matData.GetStringParameter(MaterialData::SpecularTexturePath, &strVal)) - material->specularMap = strVal.ToStdString(); + matData.GetStringParameter(MaterialData::AlphaTexturePath, &material->alphaMap); + matData.GetStringParameter(MaterialData::DiffuseTexturePath, &material->diffuseMap); + matData.GetStringParameter(MaterialData::SpecularTexturePath, &material->specularMap); } } diff --git a/src/Nazara/Utility/Formats/PCXLoader.cpp b/src/Nazara/Utility/Formats/PCXLoader.cpp index 61a0e1d28..1dd8e8c64 100644 --- a/src/Nazara/Utility/Formats/PCXLoader.cpp +++ b/src/Nazara/Utility/Formats/PCXLoader.cpp @@ -119,7 +119,7 @@ namespace Nz { if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } @@ -130,7 +130,7 @@ namespace Nz rle_count = rle_value - 0xc0; if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } } @@ -174,7 +174,7 @@ namespace Nz { if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } @@ -185,7 +185,7 @@ namespace Nz rle_count = rle_value - 0xc0; if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } } @@ -225,14 +225,14 @@ namespace Nz UInt8 magic; if (!stream.Read(&magic, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } /* first byte must be equal to 0x0c (12) */ if (magic != 0x0c) { - NazaraError("Colormap's first byte must be 0x0c (0x" + String::Number(magic, 16) + ')'); + NazaraError("Colormap's first byte must be 0x0c (0x" + NumberToString(magic, 16) + ')'); return nullptr; } @@ -258,7 +258,7 @@ namespace Nz { if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } @@ -269,7 +269,7 @@ namespace Nz rle_count = rle_value - 0xc0; if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } } @@ -302,7 +302,7 @@ namespace Nz { if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } @@ -313,7 +313,7 @@ namespace Nz rle_count = rle_value - 0xc0; if (!stream.Read(&rle_value, 1)) { - NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); + NazaraError("Failed to read stream (byte " + NumberToString(stream.GetCursorPos()) + ')'); return nullptr; } } @@ -329,7 +329,7 @@ namespace Nz } default: - NazaraError("Unsupported " + String::Number(bitCount) + " bitcount for pcx files"); + NazaraError("Unsupported " + NumberToString(bitCount) + " bitcount for pcx files"); return nullptr; } diff --git a/src/Nazara/Utility/Formats/STBLoader.cpp b/src/Nazara/Utility/Formats/STBLoader.cpp index 01f1bd0f4..023572033 100644 --- a/src/Nazara/Utility/Formats/STBLoader.cpp +++ b/src/Nazara/Utility/Formats/STBLoader.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include namespace Nz @@ -38,7 +38,7 @@ namespace Nz bool IsSupported(const std::string& extension) { - static std::set supportedExtensions = {"bmp", "gif", "hdr", "jpg", "jpeg", "pic", "png", "ppm", "pgm", "psd", "tga"}; + static std::unordered_set supportedExtensions = {"bmp", "gif", "hdr", "jpg", "jpeg", "pic", "png", "ppm", "pgm", "psd", "tga"}; return supportedExtensions.find(extension) != supportedExtensions.end(); } @@ -64,7 +64,7 @@ namespace Nz UInt8* ptr = stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &bpp, STBI_rgb_alpha); if (!ptr) { - NazaraError("Failed to load image: " + String(stbi_failure_reason())); + NazaraError("Failed to load image: " + std::string(stbi_failure_reason())); return nullptr; } diff --git a/src/Nazara/Utility/Formats/STBSaver.cpp b/src/Nazara/Utility/Formats/STBSaver.cpp index e4af33fb7..4dc30171a 100644 --- a/src/Nazara/Utility/Formats/STBSaver.cpp +++ b/src/Nazara/Utility/Formats/STBSaver.cpp @@ -120,7 +120,7 @@ namespace Nz ImageType type = image.GetType(); if (type != ImageType_1D && type != ImageType_2D) { - NazaraError("Image type 0x" + String::Number(type, 16) + " is not in a supported format"); + NazaraError("Image type 0x" + NumberToString(type, 16) + " is not in a supported format"); return false; } @@ -177,7 +177,7 @@ namespace Nz { if (imageQuality <= 0 || imageQuality > 100) { - NazaraError("NativeJPEGSaver_Quality value (" + Nz::String::Number(imageQuality) + ") does not fit in bounds ]0, 100], clamping..."); + NazaraError("NativeJPEGSaver_Quality value (" + Nz::NumberToString(imageQuality) + ") does not fit in bounds ]0, 100], clamping..."); imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL); } } diff --git a/src/Nazara/Utility/GuillotineImageAtlas.cpp b/src/Nazara/Utility/GuillotineImageAtlas.cpp index 2a39e7475..ee1101c91 100644 --- a/src/Nazara/Utility/GuillotineImageAtlas.cpp +++ b/src/Nazara/Utility/GuillotineImageAtlas.cpp @@ -32,7 +32,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (layers[i] >= m_layers.size()) { - NazaraWarning("Rectangle #" + String::Number(i) + " belong to an out-of-bounds layer (" + String::Number(i) + " >= " + String::Number(m_layers.size()) + ")"); + NazaraWarning("Rectangle #" + NumberToString(i) + " belong to an out-of-bounds layer (" + NumberToString(i) + " >= " + NumberToString(m_layers.size()) + ")"); continue; } #endif @@ -57,7 +57,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (layerIndex >= m_layers.size()) { - NazaraError("Layer index out of range (" + String::Number(layerIndex) + " >= " + String::Number(m_layers.size()) + ')'); + NazaraError("Layer index out of range (" + NumberToString(layerIndex) + " >= " + NumberToString(m_layers.size()) + ')'); return nullptr; } #endif diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index b45c96a2e..a74eab3cd 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -268,7 +269,7 @@ namespace Nz } catch (const std::exception& e) { - NazaraError("Failed to allocate image's level " + String::Number(i) + " (" + String(e.what()) + ')'); + NazaraError("Failed to allocate image's level " + NumberToString(i) + " (" + std::string(e.what()) + ')'); return false; } } @@ -448,7 +449,7 @@ namespace Nz unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth; if (z >= depth) { - NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')'); return false; } #endif @@ -574,7 +575,7 @@ namespace Nz if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return nullptr; } #endif @@ -583,7 +584,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (x >= width) { - NazaraError("X value exceeds width (" + String::Number(x) + " >= " + String::Number(width) + ')'); + NazaraError("X value exceeds width (" + NumberToString(x) + " >= " + NumberToString(width) + ')'); return nullptr; } #endif @@ -592,14 +593,14 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (y >= height) { - NazaraError("Y value exceeds height (" + String::Number(y) + " >= " + String::Number(height) + ')'); + NazaraError("Y value exceeds height (" + NumberToString(y) + " >= " + NumberToString(height) + ')'); return nullptr; } unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); if (z >= depth) { - NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')'); return nullptr; } #endif @@ -612,7 +613,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return 0; } #endif @@ -630,7 +631,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return 0; } #endif @@ -697,20 +698,20 @@ namespace Nz if (x >= m_sharedImage->width) { - NazaraError("X value exceeds width (" + String::Number(x) + " >= " + String::Number(m_sharedImage->width) + ')'); + NazaraError("X value exceeds width (" + NumberToString(x) + " >= " + NumberToString(m_sharedImage->width) + ')'); return Color(); } if (y >= m_sharedImage->height) { - NazaraError("Y value exceeds height (" + String::Number(y) + " >= " + String::Number(m_sharedImage->height) + ')'); + NazaraError("Y value exceeds height (" + NumberToString(y) + " >= " + NumberToString(m_sharedImage->height) + ')'); return Color(); } unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth; if (z >= depth) { - NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')'); return Color(); } #endif @@ -735,7 +736,7 @@ namespace Nz if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return nullptr; } #endif @@ -744,7 +745,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (x >= width) { - NazaraError("X value exceeds width (" + String::Number(x) + " >= " + String::Number(width) + ')'); + NazaraError("X value exceeds width (" + NumberToString(x) + " >= " + NumberToString(width) + ')'); return nullptr; } #endif @@ -753,20 +754,20 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (y >= height) { - NazaraError("Y value exceeds height (" + String::Number(y) + " >= " + String::Number(height) + ')'); + NazaraError("Y value exceeds height (" + NumberToString(y) + " >= " + NumberToString(height) + ')'); return nullptr; } unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level); if (z >= depth) { - NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')'); return nullptr; } if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return nullptr; } #endif @@ -781,7 +782,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return Vector3ui::Zero(); } #endif @@ -799,7 +800,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return 0; } #endif @@ -885,7 +886,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (type != ImageType_1D && type != ImageType_2D) { - NazaraError("Image type not handled (0x" + String::Number(type, 16) + ')'); + NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')'); return nullptr; } #endif @@ -894,12 +895,12 @@ namespace Nz if (imageSize.x % atlasSize.x != 0) { - NazaraWarning("Image width is not divisible by atlas width (" + String::Number(imageSize.x) + " mod " + String::Number(atlasSize.x) + " != 0)"); + NazaraWarning("Image width is not divisible by atlas width (" + NumberToString(imageSize.x) + " mod " + NumberToString(atlasSize.x) + " != 0)"); } if (imageSize.y % atlasSize.y != 0) { - NazaraWarning("Image height is not divisible by atlas height (" + String::Number(imageSize.y) + " mod " + String::Number(atlasSize.y) + " != 0)"); + NazaraWarning("Image height is not divisible by atlas height (" + NumberToString(imageSize.y) + " mod " + NumberToString(atlasSize.y) + " != 0)"); } Vector2ui faceSize = imageSize/atlasSize; @@ -971,7 +972,7 @@ namespace Nz ImageType type = image->GetType(); if (type != ImageType_2D) { - NazaraError("Image type not handled (0x" + String::Number(type, 16) + ')'); + NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')'); return nullptr; } #endif @@ -1216,20 +1217,20 @@ namespace Nz if (x >= m_sharedImage->width) { - NazaraError("X value exceeds width (" + String::Number(x) + " >= " + String::Number(m_sharedImage->width) + ')'); + NazaraError("X value exceeds width (" + NumberToString(x) + " >= " + NumberToString(m_sharedImage->width) + ')'); return false; } if (y >= m_sharedImage->height) { - NazaraError("Y value exceeds height (" + String::Number(y) + " >= " + String::Number(m_sharedImage->height) + ')'); + NazaraError("Y value exceeds height (" + NumberToString(y) + " >= " + NumberToString(m_sharedImage->height) + ')'); return false; } unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth; if (z >= depth) { - NazaraError("Z value exceeds depth (" + String::Number(z) + " >= " + String::Number(depth) + ')'); + NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')'); return false; } #endif @@ -1262,7 +1263,7 @@ namespace Nz if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return false; } #endif @@ -1296,7 +1297,7 @@ namespace Nz if (level >= m_sharedImage->levels.size()) { - NazaraError("Level out of bounds (" + String::Number(level) + " >= " + String::Number(m_sharedImage->levels.size()) + ')'); + NazaraError("Level out of bounds (" + NumberToString(level) + " >= " + NumberToString(m_sharedImage->levels.size()) + ')'); return false; } #endif @@ -1425,7 +1426,7 @@ namespace Nz return GetMaxLevel(width, height, depth); } - NazaraError("Image type not handled (0x" + String::Number(type, 16) + ')'); + NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')'); return 0; } diff --git a/src/Nazara/Utility/Joint.cpp b/src/Nazara/Utility/Joint.cpp index 0f93bcc90..e00ec63b1 100644 --- a/src/Nazara/Utility/Joint.cpp +++ b/src/Nazara/Utility/Joint.cpp @@ -34,7 +34,7 @@ namespace Nz return m_inverseBindMatrix; } - String Joint::GetName() const + const std::string& Joint::GetName() const { return m_name; } @@ -63,9 +63,9 @@ namespace Nz m_skinningMatrixUpdated = false; } - void Joint::SetName(const String& name) + void Joint::SetName(std::string name) { - m_name = name; + m_name = std::move(name); m_skeleton->InvalidateJointMap(); } diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 9982982f3..38ddcc512 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -613,7 +614,7 @@ namespace Nz if (matIndex >= matCount) { data.subMesh->SetMaterialIndex(0); // To prevent a crash - NazaraWarning("SubMesh " + String::Pointer(data.subMesh) + " material index is over mesh new material count (" + String::Number(matIndex) + " >= " + String::Number(matCount) + "), setting it to first material"); + NazaraWarning("SubMesh " + PointerToString(data.subMesh) + " material index is over mesh new material count (" + NumberToString(matIndex) + " >= " + NumberToString(matCount) + "), setting it to first material"); } } #endif diff --git a/src/Nazara/Utility/Node.cpp b/src/Nazara/Utility/Node.cpp index 87f076c69..015ad3aeb 100644 --- a/src/Nazara/Utility/Node.cpp +++ b/src/Nazara/Utility/Node.cpp @@ -158,7 +158,7 @@ namespace Nz return m_position; } - NazaraError("Coordinate system out of enum (0x" + String::Number(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); return Vector3f(); } @@ -184,7 +184,7 @@ namespace Nz return m_rotation; } - NazaraError("Coordinate system out of enum (0x" + String::Number(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); return Quaternionf(); } @@ -202,7 +202,7 @@ namespace Nz return m_scale; } - NazaraError("Coordinate system out of enum (0x" + String::Number(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); return Vector3f(); } diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index 649e1a27b..b169afd4f 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1440,7 +1440,7 @@ namespace Nz for (unsigned int i = 0; i <= PixelFormat_Max; ++i) { if (!s_pixelFormatInfos[i].Validate()) - NazaraWarning("Pixel format 0x" + String::Number(i, 16) + " (" + GetName(static_cast(i)) + ") failed validation tests"); + NazaraWarning("Pixel format 0x" + NumberToString(i, 16) + " (" + GetName(static_cast(i)) + ") failed validation tests"); } // Reset functions diff --git a/src/Nazara/Utility/RichTextDrawer.cpp b/src/Nazara/Utility/RichTextDrawer.cpp index befd58661..7d00c5fe0 100644 --- a/src/Nazara/Utility/RichTextDrawer.cpp +++ b/src/Nazara/Utility/RichTextDrawer.cpp @@ -55,9 +55,9 @@ namespace Nz RichTextDrawer::~RichTextDrawer() = default; - auto RichTextDrawer::AppendText(const String& str, bool forceNewBlock) -> BlockRef + auto RichTextDrawer::AppendText(const std::string& str, bool forceNewBlock) -> BlockRef { - NazaraAssert(!str.IsEmpty(), "String cannot be empty"); + NazaraAssert(!str.empty(), "String cannot be empty"); std::size_t defaultFontIndex = HandleFontAddition(m_defaultFont); @@ -80,7 +80,7 @@ namespace Nz if (!m_blocks.empty()) { Block& lastBlock = m_blocks.back(); - glyphIndex = lastBlock.glyphIndex + lastBlock.text.GetLength(); + glyphIndex = lastBlock.glyphIndex + lastBlock.text.size(); } else glyphIndex = 0; @@ -209,7 +209,7 @@ namespace Nz { NazaraAssert(index < m_blocks.size(), "Invalid block index"); - std::size_t textLength = m_blocks[index].text.GetLength(); + std::size_t textLength = m_blocks[index].text.size(); ReleaseFont(m_blocks[index].fontIndex); m_blocks.erase(m_blocks.begin() + index); @@ -376,13 +376,13 @@ namespace Nz return false; }; - void RichTextDrawer::GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const String& text) const + void RichTextDrawer::GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const std::string& text) const { - if (text.IsEmpty()) + if (text.empty()) return; ///TODO: Allow iteration on Unicode characters without allocating any buffer - std::u32string characters = text.GetUtf32String(); + std::u32string characters = ToUtf32String(text); if (characters.empty()) { NazaraError("Invalid character set"); @@ -503,7 +503,7 @@ namespace Nz auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; }); if (it == m_fonts.end()) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif @@ -525,7 +525,7 @@ namespace Nz auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; }); if (it == m_fonts.end()) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif @@ -542,7 +542,7 @@ namespace Nz auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; }); if (it == m_fonts.end()) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 2d1eedb90..2ff89df99 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -11,7 +11,7 @@ namespace Nz { void SimpleTextDrawer::Clear() { - m_text.Clear(true); + m_text.clear(); ClearGlyphs(); } @@ -182,13 +182,13 @@ namespace Nz return false; }; - void SimpleTextDrawer::GenerateGlyphs(const String& text) const + void SimpleTextDrawer::GenerateGlyphs(const std::string_view& text) const { - if (text.IsEmpty()) + if (text.empty()) return; ///TODO: Allow iteration on Unicode characters without allocating any buffer - std::u32string characters = text.GetUtf32String(); + std::u32string characters = ToUtf32String(text); if (characters.empty()) { NazaraError("Invalid character set"); @@ -290,7 +290,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (m_font != font) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif @@ -311,7 +311,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (m_font != font) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif @@ -327,7 +327,7 @@ namespace Nz #ifdef NAZARA_DEBUG if (m_font != font) { - NazaraInternalError("Not listening to " + String::Pointer(font)); + NazaraInternalError("Not listening to " + PointerToString(font)); return; } #endif diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index f8a7c7cdc..6927c27cd 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -11,7 +11,7 @@ namespace Nz { struct SkeletonImpl { - std::unordered_map jointMap; + std::unordered_map jointMap; std::vector joints; Boxf aabb; bool aabbUpdated = false; @@ -90,7 +90,7 @@ namespace Nz return m_impl->aabb; } - Joint* Skeleton::GetJoint(const String& jointName) + Joint* Skeleton::GetJoint(const std::string& jointName) { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -129,7 +129,7 @@ namespace Nz if (index >= m_impl->joints.size()) { - NazaraError("Joint index out of range (" + String::Number(index) + " >= " + String::Number(m_impl->joints.size()) + ')'); + NazaraError("Joint index out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')'); return nullptr; } #endif @@ -139,7 +139,7 @@ namespace Nz return &m_impl->joints[index]; } - const Joint* Skeleton::GetJoint(const String& jointName) const + const Joint* Skeleton::GetJoint(const std::string& jointName) const { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -176,7 +176,7 @@ namespace Nz if (index >= m_impl->joints.size()) { - NazaraError("Joint index out of range (" + String::Number(index) + " >= " + String::Number(m_impl->joints.size()) + ')'); + NazaraError("Joint index out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')'); return nullptr; } #endif @@ -223,7 +223,7 @@ namespace Nz return static_cast(m_impl->joints.size()); } - int Skeleton::GetJointIndex(const String& jointName) const + int Skeleton::GetJointIndex(const std::string& jointName) const { #if NAZARA_UTILITY_SAFE if (!m_impl) @@ -322,7 +322,7 @@ namespace Nz #if NAZARA_UTILITY_SAFE if (index >= m_impl->joints.size()) { - NazaraError("Index #" + String::Number(i) + " out of range (" + String::Number(index) + " >= " + String::Number(m_impl->joints.size()) + ')'); + NazaraError("Index #" + NumberToString(i) + " out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')'); return; } #endif @@ -409,8 +409,8 @@ namespace Nz m_impl->jointMap.clear(); for (std::size_t i = 0; i < m_impl->joints.size(); ++i) { - String name = m_impl->joints[i].GetName(); - if (!name.IsEmpty()) + const std::string& name = m_impl->joints[i].GetName(); + if (!name.empty()) { NazaraAssert(m_impl->jointMap.find(name) == m_impl->jointMap.end(), "Joint name \"" + name + "\" is already present in joint map"); diff --git a/src/Nazara/Utility/SoftwareBuffer.cpp b/src/Nazara/Utility/SoftwareBuffer.cpp index 3b3c51489..d5c9b1010 100644 --- a/src/Nazara/Utility/SoftwareBuffer.cpp +++ b/src/Nazara/Utility/SoftwareBuffer.cpp @@ -31,7 +31,7 @@ namespace Nz } catch (const std::exception& e) { - NazaraError("Failed to allocate software buffer (" + String(e.what()) + ')'); + NazaraError("Failed to allocate software buffer (" + std::string(e.what()) + ')'); return false; } diff --git a/src/Nazara/Utility/SubMesh.cpp b/src/Nazara/Utility/SubMesh.cpp index 0e020c11c..375fdebb2 100644 --- a/src/Nazara/Utility/SubMesh.cpp +++ b/src/Nazara/Utility/SubMesh.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -195,7 +194,7 @@ namespace Nz return indexCount - 2; } - NazaraError("Primitive mode not handled (0x" + String::Number(m_primitiveMode, 16) + ')'); + NazaraError("Primitive mode not handled (0x" + NumberToString(m_primitiveMode, 16) + ')'); return 0; } diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 568119f70..8fc49661b 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -43,7 +43,7 @@ namespace Nz m_components.reserve(components.size()); for (const ComponentEntry& entry : components) { - NazaraAssert(IsTypeSupported(entry.type), "Component type 0x" + String::Number(entry.type, 16) + " is not supported by vertex declarations"); + NazaraAssert(IsTypeSupported(entry.type), "Component type 0x" + NumberToString(entry.type, 16) + " is not supported by vertex declarations"); NazaraAssert(entry.componentIndex == 0 || entry.component == VertexComponent_Userdata, "Only userdata components can have non-zero component indexes"); if (entry.component != VertexComponent_Unused) @@ -91,7 +91,7 @@ namespace Nz return false; } - NazaraError("Component type not handled (0x" + String::Number(type, 16) + ')'); + NazaraError("Component type not handled (0x" + NumberToString(type, 16) + ')'); return false; } @@ -350,7 +350,7 @@ namespace Nz } catch (const std::exception& e) { - NazaraError("Failed to initialize vertex declaration: " + String(e.what())); + NazaraError("Failed to initialize vertex declaration: " + std::string(e.what())); return false; } diff --git a/src/Nazara/Utility/VertexMapper.cpp b/src/Nazara/Utility/VertexMapper.cpp index c722a14bb..97bf6cbda 100644 --- a/src/Nazara/Utility/VertexMapper.cpp +++ b/src/Nazara/Utility/VertexMapper.cpp @@ -36,7 +36,7 @@ namespace Nz if (!buffer) { - NazaraInternalError("Animation type not handled (0x" + String::Number(subMesh->GetAnimationType(), 16) + ')'); + NazaraInternalError("Animation type not handled (0x" + NumberToString(subMesh->GetAnimationType(), 16) + ')'); } m_mapper.Map(buffer, access); @@ -72,7 +72,7 @@ namespace Nz if (!buffer) { - NazaraInternalError("Animation type not handled (0x" + String::Number(subMesh->GetAnimationType(), 16) + ')'); + NazaraInternalError("Animation type not handled (0x" + NumberToString(subMesh->GetAnimationType(), 16) + ')'); } m_mapper.Map(buffer, access); diff --git a/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp b/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp index b1e29a6e4..701ffebe0 100644 --- a/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp +++ b/src/Nazara/VulkanRenderer/Utils_VulkanRenderer.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -97,7 +98,7 @@ namespace Nz break; } - return "Unknown Vulkan error (0x" + String::Number(code, 16).ToStdString() + ')'; + return "Unknown Vulkan error (0x" + NumberToString(code, 16) + ')'; } } diff --git a/src/Nazara/VulkanRenderer/VkRenderWindow.cpp b/src/Nazara/VulkanRenderer/VkRenderWindow.cpp index 5c7b6ee70..111ed0840 100644 --- a/src/Nazara/VulkanRenderer/VkRenderWindow.cpp +++ b/src/Nazara/VulkanRenderer/VkRenderWindow.cpp @@ -389,7 +389,7 @@ namespace Nz if (!framebuffers[i].Create(*m_device, frameBufferCreate)) { - NazaraError("Failed to create framebuffer for image #" + String::Number(i) + ": " + TranslateVulkanError(framebuffers[i].GetLastErrorCode())); + NazaraError("Failed to create framebuffer for image #" + NumberToString(i) + ": " + TranslateVulkanError(framebuffers[i].GetLastErrorCode())); return false; } } diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index 9f38a204d..4daa698f4 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -35,7 +35,7 @@ namespace Nz } // This cannot happen if physDevice is valid, as we retrieved every physical device - NazaraInternalError("Invalid physical device: " + String::Pointer(physDevice)); + NazaraInternalError("Invalid physical device: " + PointerToString(physDevice)); static Vk::PhysicalDevice dummy; return dummy; @@ -54,8 +54,8 @@ namespace Nz CallOnExit onExit(Vulkan::Uninitialize); - String appName = "Another application made with Nazara Engine"; - String engineName = "Nazara Engine - Vulkan Renderer"; + std::string appName = "Another application made with Nazara Engine"; + std::string engineName = "Nazara Engine - Vulkan Renderer"; UInt32 appVersion = VK_MAKE_VERSION(1, 0, 0); UInt32 engineVersion = VK_MAKE_VERSION(1, 0, 0); @@ -89,9 +89,9 @@ namespace Nz VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO, nullptr, - appName.GetConstBuffer(), + appName.c_str(), appVersion, - engineName.GetConstBuffer(), + engineName.c_str(), engineVersion, targetApiVersion }; @@ -126,18 +126,18 @@ namespace Nz } std::vector enabledExtensions; - std::vector additionalLayers; // Just to keep the String alive + std::vector additionalLayers; // Just to keep the String alive if (parameters.GetIntegerParameter("VkInstanceInfo_EnabledLayerCount", &iParam)) { additionalLayers.reserve(iParam); for (long long i = 0; i < iParam; ++i) { - Nz::String parameterName = "VkInstanceInfo_EnabledLayer" + String::Number(i); - Nz::String layer; + std::string parameterName = "VkInstanceInfo_EnabledLayer" + NumberToString(i); + std::string layer; if (parameters.GetStringParameter(parameterName, &layer)) { additionalLayers.emplace_back(std::move(layer)); - enabledLayers.push_back(additionalLayers.back().GetConstBuffer()); + enabledLayers.push_back(additionalLayers.back().c_str()); } else NazaraWarning("Parameter " + parameterName + " expected"); @@ -184,18 +184,18 @@ namespace Nz enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } - std::vector additionalExtensions; // Just to keep the String alive + std::vector additionalExtensions; // Just to keep the String alive if (parameters.GetIntegerParameter("VkInstanceInfo_EnabledExtensionCount", &iParam)) { additionalExtensions.reserve(iParam); for (int i = 0; i < iParam; ++i) { - Nz::String parameterName = "VkInstanceInfo_EnabledExtension" + String::Number(i); - Nz::String extension; + std::string parameterName = "VkInstanceInfo_EnabledExtension" + NumberToString(i); + std::string extension; if (parameters.GetStringParameter(parameterName, &extension)) { additionalExtensions.emplace_back(std::move(extension)); - enabledExtensions.push_back(additionalExtensions.back().GetConstBuffer()); + enabledExtensions.push_back(additionalExtensions.back().c_str()); } else NazaraWarning("Parameter " + parameterName + " expected"); @@ -232,7 +232,7 @@ namespace Nz Vk::PhysicalDevice deviceInfo; if (!s_instance.GetPhysicalDeviceQueueFamilyProperties(physDevice, &deviceInfo.queueFamilies)) { - NazaraWarning("Failed to query physical device queue family properties for " + String(deviceInfo.properties.deviceName) + " (0x" + String::Number(deviceInfo.properties.deviceID, 16) + ')'); + NazaraWarning("Failed to query physical device queue family properties for " + std::string(deviceInfo.properties.deviceName) + " (0x" + NumberToString(deviceInfo.properties.deviceID, 16) + ')'); continue; } @@ -249,7 +249,7 @@ namespace Nz deviceInfo.extensions.emplace(extProperty.extensionName); } else - NazaraWarning("Failed to query physical device extensions for " + String(deviceInfo.properties.deviceName) + " (0x" + String::Number(deviceInfo.properties.deviceID, 16) + ')'); + NazaraWarning("Failed to query physical device extensions for " + std::string(deviceInfo.properties.deviceName) + " (0x" + NumberToString(deviceInfo.properties.deviceID, 16) + ')'); s_physDevices.emplace_back(std::move(deviceInfo)); } @@ -322,7 +322,7 @@ namespace Nz { bool supportPresentation = false; if (!surface.GetSupportPresentation(deviceInfo.physDevice, i, &supportPresentation)) - NazaraWarning("Failed to get presentation support of queue family #" + String::Number(i)); + NazaraWarning("Failed to get presentation support of queue family #" + NumberToString(i)); if (deviceInfo.queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { @@ -422,18 +422,18 @@ namespace Nz //< Nazara default layers goes here } - std::vector additionalLayers; // Just to keep the String alive + std::vector additionalLayers; // Just to keep the string alive if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledLayerCount", &iParam)) { additionalLayers.reserve(iParam); for (long long i = 0; i < iParam; ++i) { - Nz::String parameterName = "VkDeviceInfo_EnabledLayer" + String::Number(i); - Nz::String layer; + std::string parameterName = "VkDeviceInfo_EnabledLayer" + NumberToString(i); + std::string layer; if (s_initializationParameters.GetStringParameter(parameterName, &layer)) { additionalLayers.emplace_back(std::move(layer)); - enabledLayers.push_back(additionalLayers.back().GetConstBuffer()); + enabledLayers.push_back(additionalLayers.back().c_str()); } else NazaraWarning("Parameter " + parameterName + " expected"); @@ -457,17 +457,17 @@ namespace Nz EnableIfSupported(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME); } - std::vector additionalExtensions; // Just to keep the String alive + std::vector additionalExtensions; // Just to keep the String alive if (s_initializationParameters.GetIntegerParameter("VkDeviceInfo_EnabledExtensionCount", &iParam)) { for (long long i = 0; i < iParam; ++i) { - Nz::String parameterName = "VkDeviceInfo_EnabledExtension" + String::Number(i); - Nz::String extension; + std::string parameterName = "VkDeviceInfo_EnabledExtension" + NumberToString(i); + std::string extension; if (s_initializationParameters.GetStringParameter(parameterName, &extension)) { additionalExtensions.emplace_back(std::move(extension)); - enabledExtensions.push_back(additionalExtensions.back().GetConstBuffer()); + enabledExtensions.push_back(additionalExtensions.back().c_str()); } else NazaraWarning("Parameter " + parameterName + " expected"); diff --git a/src/Nazara/VulkanRenderer/VulkanBuffer.cpp b/src/Nazara/VulkanRenderer/VulkanBuffer.cpp index 90ffe3615..e3c90c8ac 100644 --- a/src/Nazara/VulkanRenderer/VulkanBuffer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanBuffer.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include diff --git a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp index 3a29f76b9..6f1213a34 100644 --- a/src/Nazara/VulkanRenderer/VulkanRenderer.cpp +++ b/src/Nazara/VulkanRenderer/VulkanRenderer.cpp @@ -88,7 +88,7 @@ namespace Nz break; default: - NazaraWarning("Device " + device.name + " has handled device type (0x" + String::Number(physDevice.properties.deviceType, 16) + ')'); + NazaraWarning("Device " + device.name + " has handled device type (0x" + NumberToString(physDevice.properties.deviceType, 16) + ')'); // fallthrough case VK_PHYSICAL_DEVICE_TYPE_OTHER: device.type = RenderDeviceType::Unknown; diff --git a/src/Nazara/VulkanRenderer/VulkanTexture.cpp b/src/Nazara/VulkanRenderer/VulkanTexture.cpp index 968e1496e..20900d81f 100644 --- a/src/Nazara/VulkanRenderer/VulkanTexture.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTexture.cpp @@ -270,7 +270,7 @@ namespace Nz } default: - throw std::runtime_error(("Unsupported pixel format " + PixelFormatInfo::GetName(pixelFormat)).ToStdString()); + throw std::runtime_error("Unsupported pixel format " + PixelFormatInfo::GetName(pixelFormat)); } } } diff --git a/src/NazaraSDK/Application.cpp b/src/NazaraSDK/Application.cpp index 4c01e3683..148987070 100644 --- a/src/NazaraSDK/Application.cpp +++ b/src/NazaraSDK/Application.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #ifndef NDK_SERVER @@ -43,21 +44,21 @@ namespace Ndk std::string argument(argv[i]); if (std::regex_match(argument, results, valueRegex)) { - Nz::String key(results[1].str()); - Nz::String value(results[2].str()); + std::string key = Nz::ToLower(results[1].str()); + std::string value(results[2].str()); - m_parameters[key.ToLower()] = value; - NazaraDebug("Registred parameter from command-line: " + key.ToLower() + "=" + value); + m_parameters[key] = value; + NazaraDebug("Registred parameter from command-line: " + key + "=" + value); } else if (std::regex_match(argument, results, optionRegex)) { - Nz::String option(results[1].str()); + std::string option(results[1].str()); m_options.insert(option); NazaraDebug("Registred option from command-line: " + option); } else - NazaraWarning("Ignored command-line argument #" + Nz::String::Number(i) + " \"" + argument + '"'); + NazaraWarning("Ignored command-line argument #" + Nz::NumberToString(i) + " \"" + argument + '"'); } } diff --git a/src/NazaraSDK/Systems/ListenerSystem.cpp b/src/NazaraSDK/Systems/ListenerSystem.cpp index a197d7c78..9fdb2147e 100644 --- a/src/NazaraSDK/Systems/ListenerSystem.cpp +++ b/src/NazaraSDK/Systems/ListenerSystem.cpp @@ -65,7 +65,7 @@ namespace Ndk } if (activeListenerCount > 1) - NazaraWarning(Nz::String::Number(activeListenerCount) + " listeners were active in the same update loop"); + NazaraWarning(Nz::NumberToString(activeListenerCount) + " listeners were active in the same update loop"); } SystemIndex ListenerSystem::systemIndex; diff --git a/tests/Engine/Core/AlgorithmCore.cpp b/tests/Engine/Core/AlgorithmCore.cpp index 59ac435bb..cdc07db90 100644 --- a/tests/Engine/Core/AlgorithmCore.cpp +++ b/tests/Engine/Core/AlgorithmCore.cpp @@ -1,7 +1,7 @@ #include -#include - +#include #include +#include TEST_CASE("Apply", "[CORE][ALGORITHM]") { @@ -33,60 +33,60 @@ TEST_CASE("ComputeHash", "[CORE][ALGORITHM]") /*SECTION("Compute CRC32 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_CRC32, "1234"); - REQUIRE(result.ToHex().ToUpper() == "596A3B55"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "596A3B55"); } SECTION("Compute CRC64 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_CRC64, "1234"); - REQUIRE(result.ToHex().ToUpper() == "33302B9FC23855A8"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "33302B9FC23855A8"); } SECTION("Compute Fletcher16 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_Fletcher16, "1234"); - REQUIRE(result.ToHex().ToUpper() == "F5CA"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "F5CA"); }*/ SECTION("Compute MD5 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_MD5, "1234"); - REQUIRE(result.ToHex().ToUpper() == "81DC9BDB52D04DC20036DBD8313ED055"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "81DC9BDB52D04DC20036DBD8313ED055"); } SECTION("Compute SHA1 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_SHA1, "1234"); - REQUIRE(result.ToHex().ToUpper() == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220"); } SECTION("Compute SHA224 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_SHA224, "1234"); - REQUIRE(result.ToHex().ToUpper() == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319"); } SECTION("Compute SHA256 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_SHA256, "1234"); - REQUIRE(result.ToHex().ToUpper() == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4"); } SECTION("Compute SHA384 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_SHA384, "1234"); - REQUIRE(result.ToHex().ToUpper() == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C"); } SECTION("Compute SHA512 of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_SHA512, "1234"); - REQUIRE(result.ToHex().ToUpper() == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB"); } SECTION("Compute Whirlpool of '1234'") { auto result = Nz::ComputeHash(Nz::HashType_Whirlpool, "1234"); - REQUIRE(result.ToHex().ToUpper() == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8"); + REQUIRE(Nz::ToUpper(result.ToHex()) == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8"); } } diff --git a/tests/Engine/Core/Bitset.cpp b/tests/Engine/Core/Bitset.cpp index d37e8733b..7d5c17d6f 100644 --- a/tests/Engine/Core/Bitset.cpp +++ b/tests/Engine/Core/Bitset.cpp @@ -198,9 +198,9 @@ void CheckConstructor(const char* title) GIVEN("Iterator and default constructor") { - Nz::String anotherDataString("0101"); + std::string anotherDataString("0101"); Nz::Bitset defaultByte; - Nz::Bitset anotherData(anotherDataString.GetConstBuffer()); + Nz::Bitset anotherData(anotherDataString.c_str()); WHEN("We assign 'anotherData'") { @@ -344,7 +344,7 @@ void CheckReverse(const char* title) { GIVEN("A bitset") { - Nz::String bits = "010011100010001101001111"; + std::string bits = "010011100010001101001111"; Nz::Bitset expected(bits); WHEN("We reverse the order of bits") @@ -354,7 +354,9 @@ void CheckReverse(const char* title) THEN("The order of bits should be reversed") { - CHECK(bitset == Nz::Bitset(bits.Reversed())); + std::string reversedBits = bits; + std::reverse(reversedBits.begin(), reversedBits.end()); + CHECK(bitset == Nz::Bitset(reversedBits)); } AND_WHEN("We reverse the bit order again") { diff --git a/tests/Engine/Core/ByteStream.cpp b/tests/Engine/Core/ByteStream.cpp index 58c31020d..c948a6ec5 100644 --- a/tests/Engine/Core/ByteStream.cpp +++ b/tests/Engine/Core/ByteStream.cpp @@ -16,7 +16,7 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]") { int value = 5; byteStream << value; - Nz::String string = "string"; + std::string string = "string"; byteStream << string; byteStream.FlushBits(); @@ -29,7 +29,7 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]") readStream = Nz::ByteStream(ptrData, byteStream.GetSize()); int retrievedValue = 0; readStream >> retrievedValue; - Nz::String retrievedString; + std::string retrievedString; readStream >> retrievedString; CHECK(value == retrievedValue); @@ -70,4 +70,4 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]") } } } -} \ No newline at end of file +} diff --git a/tests/Engine/Core/File.cpp b/tests/Engine/Core/File.cpp index e78a812d1..cc3fa6661 100644 --- a/tests/Engine/Core/File.cpp +++ b/tests/Engine/Core/File.cpp @@ -25,11 +25,11 @@ SCENARIO("File", "[CORE][FILE]") char message[12]; REQUIRE(file.Read(message, 11) == 11); message[11] = '\0'; - REQUIRE(Nz::String(message) == "Test String"); + REQUIRE(std::string(message) == "Test String"); REQUIRE(file.Read(message, 11) == 11); message[11] = '\0'; - REQUIRE(Nz::String(message) == "Test String"); + REQUIRE(std::string(message) == "Test String"); } AND_THEN("We can get its size") @@ -70,7 +70,7 @@ SCENARIO("File", "[CORE][FILE]") WHEN("We read the first line of the file") { REQUIRE(fileTest.IsOpen()); - Nz::String content = fileTest.ReadLine(); + std::string content = fileTest.ReadLine(); THEN("The content must be 'Test'") { diff --git a/tests/Engine/Core/ParameterList.cpp b/tests/Engine/Core/ParameterList.cpp index 8ffca3097..557d4e3e1 100644 --- a/tests/Engine/Core/ParameterList.cpp +++ b/tests/Engine/Core/ParameterList.cpp @@ -1,8 +1,6 @@ #include #include -#include - void nullAction(void*) { } @@ -23,9 +21,9 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") long long intFalse = 0; parameterList.SetParameter("intFalse", intFalse); - Nz::String strTrue = "true"; + std::string strTrue = "true"; parameterList.SetParameter("strTrue", strTrue); - Nz::String strFalse = "false"; + std::string strFalse = "false"; parameterList.SetParameter("strFalse", strFalse); THEN("We can get it back") @@ -75,7 +73,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") long long intDouble = 3; parameterList.SetParameter("intDouble", intDouble); - Nz::String strDouble = "3.0"; + std::string strDouble = "3.0"; parameterList.SetParameter("strDouble", strDouble); THEN("We can get it back") @@ -113,7 +111,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") double doubleInt = 3; parameterList.SetParameter("doubleInt", doubleInt); - Nz::String strInt = "3"; + std::string strInt = "3"; parameterList.SetParameter("strInt", strInt); THEN("We can get it back") @@ -149,7 +147,7 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") WHEN("We add String 'string' and analogous") { - Nz::String string("string"); + std::string string("string"); parameterList.SetParameter("string", string); bool trueString = 1; @@ -168,14 +166,14 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") THEN("We can get it back") { - Nz::String newString; + std::string newString; CHECK(parameterList.GetStringParameter("string", &newString)); CHECK(newString == string); } THEN("Conversion from bool to str should also work") { - Nz::String retrievedValue; + std::string retrievedValue; CHECK(parameterList.GetStringParameter("trueString", &retrievedValue)); CHECK(retrievedValue == "true"); CHECK(parameterList.GetStringParameter("falseString", &retrievedValue)); @@ -184,21 +182,21 @@ SCENARIO("ParameterList", "[CORE][PARAMETERLIST]") THEN("Conversion from color to string should also work") { - Nz::String retrievedValue; + std::string retrievedValue; CHECK(parameterList.GetStringParameter("colorString", &retrievedValue)); CHECK(retrievedValue == colorString.ToString()); } THEN("Conversion from string to double should also work") { - Nz::String retrievedValue; + std::string retrievedValue; CHECK(parameterList.GetStringParameter("doubleString", &retrievedValue)); - CHECK(retrievedValue == "3"); + CHECK(retrievedValue == "3.000000"); } THEN("Conversion from string to int should also work") { - Nz::String retrievedValue; + std::string retrievedValue; CHECK(parameterList.GetStringParameter("intString", &retrievedValue)); CHECK(retrievedValue == "3"); } diff --git a/tests/Engine/Core/Serialization.cpp b/tests/Engine/Core/Serialization.cpp index cc556dec8..3aa3f86af 100644 --- a/tests/Engine/Core/Serialization.cpp +++ b/tests/Engine/Core/Serialization.cpp @@ -249,8 +249,8 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]") THEN("String") { context.stream->SetCursorPos(0); - Nz::String string = "string"; - Nz::String copy(string); + std::string string = "string"; + std::string copy(string); REQUIRE(Serialize(context, string)); string = "another"; REQUIRE(string != copy); diff --git a/tests/Engine/Core/String.cpp b/tests/Engine/Core/String.cpp deleted file mode 100644 index fe9c80c30..000000000 --- a/tests/Engine/Core/String.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -#include - -SCENARIO("String", "[CORE][STRING]") -{ - GIVEN("One string 'a'") - { - Nz::String aDefaultString(1, 'a'); - - WHEN("We add information") - { - aDefaultString.Append("Default"); - aDefaultString.Insert(aDefaultString.GetSize(), "String"); - - THEN("The result should be 'aDefaultString'") - { - REQUIRE(aDefaultString == "aDefaultString"); - REQUIRE(aDefaultString.GetSize() == 14); - REQUIRE(aDefaultString.GetCapacity() >= 14); - } - - AND_WHEN("We test Contains and Find") - { - THEN("These results are expected") - { - CHECK(aDefaultString.Contains('D')); - CHECK(aDefaultString.Contains("String", 3)); - CHECK(aDefaultString.Contains(Nz::String("sTRING"), 3, Nz::String::CaseInsensitive)); - REQUIRE(aDefaultString.FindLast('g') == aDefaultString.GetSize() - 1); - CHECK(aDefaultString.EndsWith('G', Nz::String::CaseInsensitive)); - aDefaultString.Append(" ng bla"); - REQUIRE(aDefaultString.FindWord("ng") == aDefaultString.GetSize() - 6); - //TODO REQUIRE(aDefaultString.FindWord(String("ng")) == aDefaultString.GetSize() - 6); - CHECK(aDefaultString.StartsWith("aD")); - } - } - } - - WHEN("We do operators") - { - aDefaultString[0] = 'a'; - aDefaultString += "Default"; - aDefaultString = aDefaultString + "String"; - - THEN("The result should be 'aDefaultString'") - { - REQUIRE(aDefaultString == "aDefaultString"); - REQUIRE(aDefaultString.GetSize() == 14); - REQUIRE(aDefaultString.GetCapacity() >= 14); - } - - AND_WHEN("We test Count") - { - THEN("These results are expected") - { - REQUIRE(aDefaultString.Count('D') == 1); - REQUIRE(aDefaultString.Count("t", 2) == 2); - } - } - } - } - - GIVEN("The string of number 16 in base 16") - { - Nz::String number16; - - CHECK(number16.IsEmpty()); - CHECK(number16.IsNull()); - - WHEN("We assign to number 16") - { - number16 = Nz::String::Number(16, 16); - - THEN("These results are expected") - { - CHECK(number16.IsNumber(16)); - number16.Prepend("0x"); - REQUIRE(number16.GetSize() == 4); - REQUIRE(number16.GetCapacity() >= 4); - REQUIRE(number16.SubStringFrom('x', 1) == "10"); - } - } - } - - GIVEN("One character string") - { - Nz::String characterString; - - WHEN("We set the string to one character") - { - characterString.Set('/'); - - THEN("The string must contain it") - { - REQUIRE(characterString == '/'); - } - } - } - - /* TODO - GIVEN("One unicode string") - { - String unicodeString = String::Unicode(U"àéçœÂ官話"); - - WHEN("We convert to other UTF") - { - REQUIRE(unicodeString.GetSize() == 7); - REQUIRE(unicodeString.GetCapacity() >= 7); - CHECK(unicodeString.Contains("官")); - - THEN("The result should be the identity") - { - char* utf8 = unicodeString.GetUtf8Buffer(); - String utf8String = String::Unicode(utf8); - char16_t* utf16 = unicodeString.GetUtf16Buffer(); - String utf16String = String::Unicode(utf16); - char32_t* utf32 = unicodeString.GetUtf32Buffer(); - String utf32String = String::Unicode(utf32); - - REQUIRE(utf8String == utf16String); - REQUIRE(utf16String == utf32String); - } - } - }*/ - - GIVEN("A string") - { - Nz::String replaceAny("abapeilomuky"); - Nz::String replaceAnyWithCase("abapEilOmuky"); - - WHEN("We replace any of vowels after character 3") - { - unsigned int nbrOfChanges = replaceAny.ReplaceAny("aeiouy", '$', 3); - unsigned int nbrOfChangesWithCase = replaceAnyWithCase.ReplaceAny("AEIOUY", '$', 3); - - THEN("These results are expected") - { - REQUIRE(replaceAny == "abap$$l$m$k$"); - REQUIRE(nbrOfChanges == 5); - REQUIRE(replaceAnyWithCase == "abap$il$muky"); - REQUIRE(nbrOfChangesWithCase == 2); - } - } - } -} - diff --git a/tests/Engine/Core/StringExt.cpp b/tests/Engine/Core/StringExt.cpp new file mode 100644 index 000000000..b952c90df --- /dev/null +++ b/tests/Engine/Core/StringExt.cpp @@ -0,0 +1,107 @@ +#include +#include + +SCENARIO("String", "[CORE][STRING]") +{ + std::string unicodeString(u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98\u46E1"); + + WHEN("Converting string back and forth") + { + CHECK(Nz::FromUtf16String(Nz::ToUtf16String(unicodeString)) == unicodeString); + CHECK(Nz::FromUtf32String(Nz::ToUtf32String(unicodeString)) == unicodeString); + } + + WHEN("Fetching words") + { + CHECK(Nz::GetWord({}, 0).empty()); + CHECK(Nz::GetWord(" ", 0).empty()); + + std::string sentence = u8"\nSay hello\tto Nazara\u00A0Engine\n\t! "; //< \u00A0 is a No-Break Space + CHECK(Nz::GetWord(sentence, 0) == "Say"); + CHECK(Nz::GetWord(sentence, 1) == "hello"); + CHECK(Nz::GetWord(sentence, 2) == "to"); + CHECK(Nz::GetWord(sentence, 3) == u8"Nazara\u00A0Engine"); + CHECK(Nz::GetWord(sentence, 4) == "!"); + CHECK(Nz::GetWord(sentence, 5).empty()); + + // Try the same using Unicode aware overloads + CHECK(Nz::GetWord(sentence, 0, Nz::UnicodeAware{}) == "Say"); + CHECK(Nz::GetWord(sentence, 1, Nz::UnicodeAware{}) == "hello"); + CHECK(Nz::GetWord(sentence, 2, Nz::UnicodeAware{}) == "to"); + CHECK(Nz::GetWord(sentence, 3, Nz::UnicodeAware{}) == "Nazara"); + CHECK(Nz::GetWord(sentence, 4, Nz::UnicodeAware{}) == "Engine"); + CHECK(Nz::GetWord(sentence, 5, Nz::UnicodeAware{}) == "!"); + CHECK(Nz::GetWord(sentence, 6, Nz::UnicodeAware{}).empty()); + } + + WHEN("Checking if string is number") + { + CHECK(Nz::IsNumber("123456")); + CHECK(Nz::IsNumber("-123456")); + CHECK_FALSE(Nz::IsNumber("123 ")); + CHECK_FALSE(Nz::IsNumber("Nazara Engine")); + CHECK_FALSE(Nz::IsNumber("12345Nazara Engine")); + } + + WHEN("Matching patterns") + { + CHECK(Nz::MatchPattern("Lynix", "?????")); + CHECK(Nz::MatchPattern("Lynix", "*Lynix")); + CHECK(Nz::MatchPattern("Lynox", "*Lyn?x")); + CHECK_FALSE(Nz::MatchPattern("", "?")); + CHECK_FALSE(Nz::MatchPattern("", "*")); + + const char* pattern = "Naz?ra *gine"; + CHECK(Nz::MatchPattern("Nazara Engine", pattern)); + CHECK(Nz::MatchPattern("Nazora engine", pattern)); + CHECK(Nz::MatchPattern("Nazora Biggine", pattern)); + CHECK(Nz::MatchPattern("Nazora gine", pattern)); + + CHECK_FALSE(Nz::MatchPattern("Nazaragine", pattern)); + CHECK_FALSE(Nz::MatchPattern("Nazorra Engine", pattern)); + CHECK_FALSE(Nz::MatchPattern("Nazra Engine", pattern)); + CHECK_FALSE(Nz::MatchPattern("NazaraEngine", pattern)); + } + + WHEN("Converting pointers to string") + { + CHECK(Nz::TrimRight(Nz::PointerToString(nullptr), '0') == "0x"); + + const void* ptr = reinterpret_cast(static_cast(0xDEADBEEF)); + CHECK(Nz::MatchPattern(Nz::PointerToString(ptr), "0x*DEADBEEF")); + } + + WHEN("Replacing strings") + { + std::string str = "Nazara Engine"; + REQUIRE(Nz::ReplaceStr(str, "Nazara", "Unreal") == "Unreal Engine"); + REQUIRE(Nz::ReplaceStr(str, "Engine", "Reality") == "Unreal Reality"); + REQUIRE(Nz::ReplaceStr(str, "Unreal Reality", "Ungine") == "Ungine"); + } + + WHEN("Checking if string starts with") + { + CHECK(Nz::StartsWith("Nazara Engine", "Nazara")); + CHECK(Nz::StartsWith("NAZARA Engine", "NaZaRa", Nz::CaseIndependent{})); + CHECK(Nz::StartsWith(u8"L'\u00CEle de R\u00E9", u8"l'\u00EEle", Nz::CaseIndependent{}, Nz::UnicodeAware{})); + } + + WHEN("Converting between lower and upper") + { + CHECK(Nz::ToLower("Nazara Engine") == "nazara engine"); + CHECK(Nz::ToLower(u8"L'\u00CELE DE R\u00C9", Nz::UnicodeAware{}) == u8"l'\u00EEle de r\u00E9"); + CHECK(Nz::ToUpper("Nazara Engine") == "NAZARA ENGINE"); + CHECK(Nz::ToUpper(u8"l'\u00EEle de r\u00E9", Nz::UnicodeAware{}) == u8"L'\u00CELE DE R\u00C9"); + } + + WHEN("Trimming strings") + { + CHECK(Nz::Trim(" \n Hello World\t") == "Hello World"); + CHECK(Nz::Trim("Nazara Engin", 'n') == "Nazara Engi"); + CHECK(Nz::Trim("Nazara Engin", 'n', Nz::CaseIndependent{}) == "azara Engi"); + CHECK(Nz::Trim(unicodeString, Nz::UnicodeAware{}) == unicodeString); + CHECK(Nz::Trim("\n\t" + unicodeString + "\t ", Nz::UnicodeAware{}) == unicodeString); + CHECK(Nz::Trim(unicodeString, U'\u46E1', Nz::UnicodeAware{}) == u8"\u00E0\u00E9\u00E7\u0153\u00C2\u5B98"); + CHECK(Nz::Trim(unicodeString, Nz::Unicode::Category_Letter, Nz::UnicodeAware{}) == ""); + } +} diff --git a/tests/Engine/Core/StringStream.cpp b/tests/Engine/Core/StringStream.cpp deleted file mode 100644 index ece0d352c..000000000 --- a/tests/Engine/Core/StringStream.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include - -SCENARIO("StringStream", "[CORE][STRINGSTREAM]") -{ - GIVEN("A string stream") - { - Nz::StringStream stringStream("default"); - - WHEN("We add bool and char") - { - stringStream << true; - - char valueCharSigned = 64; - stringStream << valueCharSigned; - unsigned char valueCharUnsigned = 64; - stringStream << valueCharUnsigned; - - REQUIRE(stringStream.ToString() == "defaulttrue@@"); - } - - AND_WHEN("We add short and int") - { - short valueShortSigned = -3; - stringStream << valueShortSigned; - unsigned short valueShortUnsigned = 3; - stringStream << valueShortUnsigned; - - int valueIntSigned = -3; - stringStream << valueIntSigned; - unsigned int valueIntUnsigned = 3; - stringStream << valueIntUnsigned; - - REQUIRE(stringStream.ToString() == "default-33-33"); - } - - AND_WHEN("We add long and long long") - { - long valueLongSigned = -3; - stringStream << valueLongSigned; - unsigned long valueLongUnsigned = 3; - stringStream << valueLongUnsigned; - - long long valueLongLongSigned = -3; - stringStream << valueLongLongSigned; - unsigned long long valueLongLongUnsigned = 3; - stringStream << valueLongLongUnsigned; - - REQUIRE(stringStream.ToString() == "default-33-33"); - } - - AND_WHEN("We add round floating points") - { - stringStream << 3.f; - stringStream << 3.0; - stringStream << 3.0L; - - REQUIRE(stringStream.ToString() == "default3.0000003.0000003.000000"); - } - - AND_WHEN("We add floating points") - { - stringStream << 3.5f << ' '; - stringStream << 3.65 << ' '; - stringStream << 3.6478L; - - REQUIRE(stringStream.ToString() == "default3.500000 3.650000 3.647800"); - } - - AND_WHEN("We add string and pointer") - { - stringStream << "3"; - stringStream << std::string("3"); - stringStream << Nz::String("3"); - stringStream << static_cast(nullptr); - - REQUIRE(stringStream.ToString() == (Nz::String("default333") + Nz::String::Pointer(nullptr))); - } - } -} diff --git a/tests/Engine/Network/IpAddress.cpp b/tests/Engine/Network/IpAddress.cpp index 571e7ec75..36fead7a2 100644 --- a/tests/Engine/Network/IpAddress.cpp +++ b/tests/Engine/Network/IpAddress.cpp @@ -10,10 +10,10 @@ SCENARIO("IpAddress", "[NETWORK][IPADDRESS]") WHEN("We parse localhost") { - Nz::String localhostIPv4 = "127.0.0.1"; - Nz::String localhostIPv6 = "::1"; - REQUIRE(ipAddressV4.BuildFromAddress(localhostIPv4.GetConstBuffer())); - REQUIRE(ipAddressV6.BuildFromAddress(localhostIPv6.GetConstBuffer())); + std::string localhostIPv4 = "127.0.0.1"; + std::string localhostIPv6 = "::1"; + REQUIRE(ipAddressV4.BuildFromAddress(localhostIPv4)); + REQUIRE(ipAddressV6.BuildFromAddress(localhostIPv6)); THEN("It's the loop back") { @@ -40,7 +40,7 @@ SCENARIO("IpAddress", "[NETWORK][IPADDRESS]") Nz::IpAddress google(8, 8, 8, 8); THEN("Google (DNS) is 8.8.8.8") { - Nz::String dnsAddress = Nz::IpAddress::ResolveAddress(google); + std::string dnsAddress = Nz::IpAddress::ResolveAddress(google); bool dnsCheck = dnsAddress == "google-public-dns-a.google.com" || dnsAddress == "dns.google"; CHECK(dnsCheck); }