Remove Nz::String and Nz::StringStream
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
#define NAZARA_ABSTRACTLOGGER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_ALGORITHM_CORE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/SerializationContext.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
@@ -18,7 +19,6 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractHash;
|
||||
class ByteArray;
|
||||
|
||||
template<typename T> constexpr T Align(T offset, T alignment);
|
||||
@@ -30,6 +30,7 @@ namespace Nz
|
||||
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
||||
template<typename T, std::size_t N> constexpr std::size_t CountOf(T(&name)[N]) noexcept;
|
||||
template<typename T> std::size_t CountOf(const T& c);
|
||||
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
|
||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||
template<typename T> bool IsPowerOfTwo(T value);
|
||||
template<typename T> T ReverseBits(T integer);
|
||||
|
||||
@@ -192,6 +192,12 @@ namespace Nz
|
||||
return c.size();
|
||||
}
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const std::string_view& v)
|
||||
{
|
||||
hash->Append(reinterpret_cast<const UInt8*>(v.data()), v.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Combines two hash in one
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
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<typename T> Bitset(T value);
|
||||
Bitset(Bitset&& bitset) noexcept = default;
|
||||
~Bitset() noexcept = default;
|
||||
@@ -81,7 +82,7 @@ namespace Nz
|
||||
bool TestNone() const;
|
||||
|
||||
template<typename T> 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<typename T> Bitset& operator=(T value);
|
||||
Bitset& operator=(Bitset&& bitset) noexcept = default;
|
||||
|
||||
|
||||
@@ -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<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>::Bitset(const String& bits) :
|
||||
Bitset(bits.GetConstBuffer(), bits.GetSize())
|
||||
Bitset<Block, Allocator>::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<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>::Bitset(const std::string& bits) :
|
||||
Bitset(bits.data(), bits.size())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -883,9 +893,9 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename Block, class Allocator>
|
||||
String Bitset<Block, Allocator>::ToString() const
|
||||
std::string Bitset<Block, Allocator>::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<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(const String& bits)
|
||||
Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(const std::string_view& bits)
|
||||
{
|
||||
Bitset bitset(bits);
|
||||
std::swap(*this, bitset);
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#define NAZARA_BYTEARRAY_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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<const char*>(GetConstBuffer()), GetSize());
|
||||
return std::string(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_COLOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
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<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
|
||||
|
||||
if (a != 255)
|
||||
@@ -93,7 +94,7 @@ namespace Nz
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
#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();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -135,18 +135,12 @@ namespace Nz
|
||||
* \return A string representation of the object "ObjectHandle(object representation) or Null"
|
||||
*/
|
||||
template<typename T>
|
||||
Nz::String ObjectHandle<T>::ToString() const
|
||||
std::string ObjectHandle<T>::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<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle)
|
||||
{
|
||||
out << handle.ToString();
|
||||
out << "ObjectHandle(";
|
||||
if (handle.IsValid())
|
||||
out << handle->ToString();
|
||||
else
|
||||
out << "Null";
|
||||
|
||||
out << ')';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
@@ -25,18 +25,18 @@ namespace Nz
|
||||
|
||||
static void Clear();
|
||||
|
||||
static ObjectRef<Type> Get(const String& name);
|
||||
static bool Has(const String& name);
|
||||
static ObjectRef<Type> Get(const std::string& name);
|
||||
static bool Has(const std::string& name);
|
||||
|
||||
static void Register(const String& name, ObjectRef<Type> object);
|
||||
static ObjectRef<Type> Query(const String& name);
|
||||
static void Unregister(const String& name);
|
||||
static void Register(const std::string& name, ObjectRef<Type> object);
|
||||
static ObjectRef<Type> Query(const std::string& name);
|
||||
static void Unregister(const std::string& name);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
using LibraryMap = std::unordered_map<String, ObjectRef<Type>>;
|
||||
using LibraryMap = std::unordered_map<std::string, ObjectRef<Type>>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Nz
|
||||
* \remark Produces a NazaraError if object not found
|
||||
*/
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Get(const String& name)
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Get(const std::string& name)
|
||||
{
|
||||
ObjectRef<Type> ref = Query(name);
|
||||
if (!ref)
|
||||
@@ -46,7 +46,7 @@ namespace Nz
|
||||
* \return true if it the case
|
||||
*/
|
||||
template<typename Type>
|
||||
bool ObjectLibrary<Type>::Has(const String& name)
|
||||
bool ObjectLibrary<Type>::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<typename Type>
|
||||
void ObjectLibrary<Type>::Register(const String& name, ObjectRef<Type> object)
|
||||
void ObjectLibrary<Type>::Register(const std::string& name, ObjectRef<Type> object)
|
||||
{
|
||||
Type::s_library.emplace(name, object);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace Nz
|
||||
* \param name Name of the object
|
||||
*/
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Query(const String& name)
|
||||
ObjectRef<Type> ObjectLibrary<Type>::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<typename Type>
|
||||
void ObjectLibrary<Type>::Unregister(const String& name)
|
||||
void ObjectLibrary<Type>::Unregister(const std::string& name)
|
||||
{
|
||||
Type::s_library.erase(name);
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
@@ -28,33 +28,33 @@ namespace Nz
|
||||
|
||||
void Clear();
|
||||
|
||||
inline void ForEach(const std::function<bool(const ParameterList& list, const String& name)>& callback);
|
||||
inline void ForEach(const std::function<void(const ParameterList& list, const String& name)>& callback) const;
|
||||
inline void ForEach(const std::function<bool(const ParameterList& list, const std::string& name)>& callback);
|
||||
inline void ForEach(const std::function<void(const ParameterList& list, const std::string& name)>& 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<String, Parameter>;
|
||||
using ParameterMap = std::unordered_map<std::string, Parameter>;
|
||||
ParameterMap m_parameters;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<bool(const ParameterList& list, const String& name)>& callback)
|
||||
inline void ParameterList::ForEach(const std::function<bool(const ParameterList& list, const std::string& name)>& 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<void(const ParameterList& list, const String& name)>& callback) const
|
||||
inline void ParameterList::ForEach(const std::function<void(const ParameterList& list, const std::string& name)>& callback) const
|
||||
{
|
||||
for (auto& pair : m_parameters)
|
||||
callback(*this, pair.first);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
@@ -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 <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <cstdarg>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<String>& result, char separation = ' ', std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const char* separation, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const char* separation, std::size_t length, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const String& separation, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<String>& result, const char* separations, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<String>& 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>&& sharedString);
|
||||
|
||||
void EnsureOwnership(bool discardContent = false);
|
||||
inline void ReleaseString();
|
||||
|
||||
static const std::shared_ptr<SharedString>& GetEmptyString();
|
||||
|
||||
std::shared_ptr<SharedString> 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<char[]> string;
|
||||
};
|
||||
};
|
||||
|
||||
class AbstractHash;
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const String& string);
|
||||
NAZARA_CORE_API bool Serialize(SerializationContext& context, const String& string, TypeTag<String>);
|
||||
NAZARA_CORE_API bool Unserialize(SerializationContext& context, String* string, TypeTag<String>);
|
||||
}
|
||||
|
||||
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<Nz::String>;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/String.inl>
|
||||
|
||||
#endif // NAZARA_STRING_HPP
|
||||
@@ -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 <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
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>&& 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<const UInt8*>(string.GetConstBuffer()), string.GetSize());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Nz::String>
|
||||
{
|
||||
/*!
|
||||
* \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<size_t>(*ptr);
|
||||
while (*++ptr);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp> //< FIXME
|
||||
#include <string>
|
||||
|
||||
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<typename... Args> 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<typename F> bool SplitString(const std::string_view& str, const std::string_view& token, F&& func);
|
||||
template<typename F> 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 <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<typename... Args> 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>(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 <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -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 <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user