From 466720abec025ea55b0919219313099fb3dc27a5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 18 Sep 2015 14:10:15 +0200 Subject: [PATCH] Core/String: Fix IsNull() method (thanks to Unit tests) Former-commit-id: dd4828c3c0e2d3423094cf018e70fd74deac0740 --- include/Nazara/Core/String.hpp | 2 +- src/Nazara/Core/String.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index 1efdb396b..f6e209c3f 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -307,7 +307,7 @@ class NAZARA_CORE_API NzString : public NzHashable bool FillHash(NzAbstractHash* hash) const; inline void ReleaseString(); - static std::shared_ptr GetEmptyString(); + static const std::shared_ptr& GetEmptyString(); std::shared_ptr m_sharedString; diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index a1ba87b84..1566b32a5 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -1934,7 +1934,7 @@ bool NzString::IsEmpty() const bool NzString::IsNull() const { - return !m_sharedString.get(); + return m_sharedString.get() == GetEmptyString().get(); } bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const @@ -2609,7 +2609,7 @@ NzString& NzString::Set(unsigned int rep, const char* string, unsigned int lengt if (totalSize > 0) { if (m_sharedString->capacity >= totalSize) - { + { EnsureOwnership(true); m_sharedString->size = totalSize; @@ -2642,7 +2642,7 @@ NzString& NzString::Set(const char* string, unsigned int length) if (length > 0) { if (m_sharedString->capacity >= length) - { + { EnsureOwnership(true); m_sharedString->size = length; @@ -4198,7 +4198,7 @@ bool NzString::FillHash(NzAbstractHash* hash) const return true; } -std::shared_ptr NzString::GetEmptyString() +const std::shared_ptr& NzString::GetEmptyString() { static auto emptyString = std::make_shared();