From f5400298250e7eba3433f366cf2b2ae1f1382763 Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Sun, 21 Feb 2016 14:32:17 +0100 Subject: [PATCH] Documentation for String Former-commit-id: caf1b5889604d7c2248ec88bde99a6bce0d7680f --- include/Nazara/Core/String.hpp | 12 +- include/Nazara/Core/String.inl | 42 + include/Nazara/Core/Unicode.hpp | 20 +- src/Nazara/Core/String.cpp | 1751 +++++++++++++++++++++++++++++- src/Nazara/Core/StringStream.cpp | 151 +++ src/Nazara/Core/Unicode.cpp | 58 +- 6 files changed, 1974 insertions(+), 60 deletions(-) diff --git a/include/Nazara/Core/String.hpp b/include/Nazara/Core/String.hpp index a99326bf4..70673ae8a 100644 --- a/include/Nazara/Core/String.hpp +++ b/include/Nazara/Core/String.hpp @@ -23,11 +23,11 @@ namespace Nz public: enum Flags { - None = 0x00, // Mode par défaut - CaseInsensitive = 0x01, // Insensible à la casse - HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 - TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne - TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne + 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(); @@ -71,7 +71,7 @@ namespace Nz 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 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; diff --git a/include/Nazara/Core/String.inl b/include/Nazara/Core/String.inl index 93ff32312..40c08d315 100644 --- a/include/Nazara/Core/String.inl +++ b/include/Nazara/Core/String.inl @@ -7,22 +7,42 @@ namespace Nz { + /*! + * \brief Constructs a String object with a shared string by move semantic + * + * \param sharedString Shared string to move into this + */ + inline String::String(std::shared_ptr&& sharedString) : m_sharedString(std::move(sharedString)) { } + /*! + * \brief Releases the content to the string + */ + inline void String::ReleaseString() { m_sharedString = std::move(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), @@ -31,6 +51,13 @@ namespace Nz 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), @@ -39,6 +66,14 @@ namespace Nz 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()); @@ -48,6 +83,13 @@ namespace Nz namespace std { + /*! + * \brief Specialisation of std to hash + * \return Result of the hash + * + * \param str String to hash + */ + template<> struct hash { diff --git a/include/Nazara/Core/Unicode.hpp b/include/Nazara/Core/Unicode.hpp index 631d8f8bd..a42e88e90 100644 --- a/include/Nazara/Core/Unicode.hpp +++ b/include/Nazara/Core/Unicode.hpp @@ -18,16 +18,16 @@ namespace Nz Unicode() = delete; ~Unicode() = delete; /* - Catégorie Unicode: - -Les valeurs de 0x01 à 0x80 indiquent la catégorie. - -Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie. + Unicode category: + -Values between 0x01 and 0x80 specify the category + -Values between 0x100 and 0x10000 specify the subcategory */ enum Category : UInt16 { - // Catégorie non-reconnue par Nazara + // Category not handled by Nazara Category_NoCategory = 0, - // Lettres + // Letters Category_Letter = 0x01, // L Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll Category_Letter_Modifier = Category_Letter | 0x0200, // Lm @@ -35,19 +35,19 @@ namespace Nz Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu - // Marques + // Marks Category_Mark = 0x02, // M Category_Mark_Enclosing = Category_Mark | 0x100, // Me Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc - // Nombres + // Numbers Category_Number = 0x04, // N Category_Number_DecimalDigit = Category_Number | 0x100, // Nd Category_Number_Letter = Category_Number | 0x200, // Nl Category_Number_Other = Category_Number | 0x400, // No - // Autres + // Others Category_Other = 0x08, // C Category_Other_Control = Category_Other | 0x0100, // Cc Category_Other_Format = Category_Other | 0x0200, // Cf @@ -65,13 +65,13 @@ namespace Nz Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po - // Espacements + // Spaces Category_Separator = 0x20, // Z Category_Separator_Line = Category_Separator | 0x0100, // Zl Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp Category_Separator_Space = Category_Separator | 0x0400, // Zs - // Symboles + // Symbols Category_Symbol = 0x40, // S Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc Category_Symbol_Math = Category_Symbol | 0x0200, // Sm diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index daa5cb85a..74c2afe80 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -///TODO: Réécrire une bonne partie des algorithmes employés (Relu jusqu'à 3538) +///TODO: Rewrite most of used algorithms (Reread to to line 4638) #include #include @@ -23,7 +23,7 @@ namespace Nz { namespace Detail { - // Cet algorithme est inspiré de la documentation de Qt + // This algorithm is inspired by the documentation of Qt inline std::size_t GetNewSize(std::size_t newSize) { if (newSize < 20) @@ -76,11 +76,26 @@ namespace Nz } } + /*! + * \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') @@ -92,6 +107,13 @@ namespace Nz 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) @@ -105,11 +127,26 @@ namespace Nz 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; @@ -125,16 +162,36 @@ namespace Nz 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) @@ -146,31 +203,80 @@ namespace Nz 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.c_str(), 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) @@ -182,21 +288,63 @@ namespace Nz 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) @@ -234,6 +382,15 @@ namespace Nz 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) @@ -331,11 +488,29 @@ namespace Nz 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) @@ -424,11 +599,30 @@ namespace Nz 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) @@ -437,14 +631,35 @@ namespace Nz 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' sera toujours faux + 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) @@ -461,11 +676,30 @@ namespace Nz 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) @@ -501,6 +735,15 @@ namespace Nz } } + /*! + * \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) @@ -591,11 +834,29 @@ namespace Nz 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]) @@ -674,11 +935,29 @@ namespace Nz 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) @@ -716,6 +995,15 @@ namespace Nz 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) @@ -728,14 +1016,14 @@ namespace Nz if (pos >= m_sharedString->size) return npos; - ///Algo 1.FindLast#3 (Taille du pattern inconnue) + ///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); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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; @@ -824,6 +1112,15 @@ namespace Nz 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) @@ -843,9 +1140,9 @@ namespace Nz { if (flags & HandleUtf8) { - ///Algo 1.FindLast#3 (Itérateur non-adapté) + ///Algo 1.FindLast#3 (Iterator non-adapted) if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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(); @@ -878,7 +1175,7 @@ namespace Nz } else { - ///Algo 1.FindLast#4 (Taille du pattern connue) + ///Algo 1.FindLast#4 (Size of the pattern unknown) char c = Detail::ToLower(string.m_sharedString->string[string.m_sharedString->size-1]); for (;;) { @@ -904,7 +1201,7 @@ namespace Nz } else { - ///Algo 1.FindLast#4 (Taille du pattern connue) + ///Algo 1.FindLast#4 (Size of the pattern known) for (;;) { if (*ptr == string.m_sharedString->string[string.m_sharedString->size-1]) @@ -930,6 +1227,15 @@ namespace Nz 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) @@ -1016,11 +1322,29 @@ namespace Nz 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) @@ -1033,19 +1357,19 @@ namespace Nz if (pos >= m_sharedString->size) return npos; - ///Algo 2.FindLastWord#1 (Taille du pattern inconnue) + ///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); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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 affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do { @@ -1087,7 +1411,7 @@ namespace Nz } else { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affects the iterator on argument UInt32 c = utf8::unchecked::next(t); do { @@ -1204,6 +1528,15 @@ namespace Nz 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) @@ -1222,13 +1555,13 @@ namespace Nz if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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 affecte l'itérateur en argument + const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do { @@ -1270,7 +1603,7 @@ namespace Nz } else { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument UInt32 c = utf8::unchecked::next(t); do { @@ -1313,7 +1646,7 @@ namespace Nz } else { - ///Algo 2.FindLastWord#2 (Taille du pattern connue) + ///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]); @@ -1380,6 +1713,15 @@ namespace Nz 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) @@ -1392,18 +1734,18 @@ namespace Nz if (pos >= m_sharedString->size) return npos; - ///Algo 3.FindWord#3 (Taille du pattern inconnue) + ///Algo 3.FindWord#3 (Size of the pattern unknown) const char* ptr = m_sharedString->string.get(); if (flags & HandleUtf8) { if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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 affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do @@ -1443,7 +1785,7 @@ namespace Nz } else { - const char* t = string; // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string; // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do @@ -1552,6 +1894,15 @@ namespace Nz 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) @@ -1567,15 +1918,15 @@ namespace Nz char* ptr = m_sharedString->string.get(); if (flags & HandleUtf8) { - ///Algo 3.FindWord#3 (Itérateur trop lent pour #2) + ///Algo 3.FindWord#3 (Iterator too slow for #2) if (utf8::internal::is_trail(*ptr)) - utf8::unchecked::prior(ptr); // On s'assure d'avoir un pointeur vers le début d'un caractère + 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 affecte l'itérateur en argument + const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do @@ -1615,7 +1966,7 @@ namespace Nz } else { - const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affecte l'itérateur en argument + const char* t = string.GetConstBuffer(); // utf8(::unchecked)::next affects the iterator on argument UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); do @@ -1656,7 +2007,7 @@ namespace Nz } else { - ///Algo 3.FindWord#2 (Taille du pattern connue) + ///Algo 3.FindWord#2 (Size of the pattern known) if (flags & CaseInsensitive) { char c = Detail::ToLower(string.m_sharedString->string[0]); @@ -1693,7 +2044,7 @@ namespace Nz { while ((ptr = std::strstr(ptr, string.GetConstBuffer())) != nullptr) { - // Si le mot est bien isolé + // If the word is really alone if ((ptr == m_sharedString->string.get() || std::isspace(*(ptr-1))) && (*(ptr+m_sharedString->size) == '\0' || std::isspace(*(ptr+m_sharedString->size)))) return ptr - m_sharedString->string.get(); @@ -1705,6 +2056,11 @@ namespace Nz return npos; } + /*! + * \brief Gets the raw buffer + * \return Raw buffer + */ + char* String::GetBuffer() { EnsureOwnership(); @@ -1712,31 +2068,61 @@ namespace Nz 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 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) @@ -1750,6 +2136,11 @@ namespace Nz return str; } + /*! + * \brief Gets the std::string corresponding + * \return String in UTF-32 + */ + std::u32string String::GetUtf32String() const { if (m_sharedString->size == 0) @@ -1763,6 +2154,11 @@ namespace Nz 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"); @@ -1772,7 +2168,7 @@ namespace Nz std::wstring str; str.reserve(m_sharedString->size); - if (sizeof(wchar_t) == 4) // Je veux du static_if :( + if (sizeof(wchar_t) == 4) // I want a static_if :( utf8::utf8to32(begin(), end(), std::back_inserter(str)); else { @@ -1791,6 +2187,14 @@ namespace Nz return str; } + /*! + * \brief Gets the word until next separator + * \return Word string + * + * \param start 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); @@ -1828,6 +2232,14 @@ namespace Nz return SubString(startPos, endPos); } + /*! + * \brief Gets the word position + * \return Position of the beginning of the word + * + * \param start 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) @@ -1878,16 +2290,41 @@ namespace Nz 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) @@ -1898,7 +2335,7 @@ namespace Nz std::size_t start = std::min(pos, m_sharedString->size); - // Si le buffer est déjà suffisamment grand + // If buffer is already big enough if (m_sharedString->capacity >= m_sharedString->size + length) { EnsureOwnership(); @@ -1933,21 +2370,49 @@ namespace Nz 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 @@ -2010,6 +2475,13 @@ namespace Nz 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) @@ -2057,37 +2529,91 @@ namespace Nz 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') // Dans ce cas, il faut passer par un algorithme plus complexe + if (newCharacter == '\0') // In this case, we must use a more advanced algorithm return Replace(String(oldCharacter), String(), start); if (start < 0) @@ -2146,11 +2672,33 @@ namespace Nz return count; } + /*! + * \brief Replaces the old "C string" 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(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 oldCharacter Pattern to find + * \param oldLength Length of the old string + * \param newCharacter Pattern to change for + * \param Length 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) @@ -2168,7 +2716,7 @@ namespace Nz { bool found = false; - // Si aucun changement de taille n'est nécessaire, nous pouvons alors utiliser un algorithme bien plus rapide + // If no size change is necessary, we can thus use a quicker algorithm while ((pos = Find(oldString, pos, flags)) != npos) { if (!found) @@ -2183,10 +2731,10 @@ namespace Nz ++count; } } - else ///TODO: Algorithme de remplacement sans changement de buffer (si replaceLength < oldLength) + 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) // Alors c'est que Count(oldString) == 0 + if (newSize == m_sharedString->size) // Then it's the fact that Count(oldString) == 0 return 0; auto newString = std::make_shared(newSize); @@ -2217,18 +2765,40 @@ namespace Nz return count; } + /*! + * \brief Replaces the old string 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(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 newCharacter 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: Ne gère pas l'UTF-8 + ///FIXME: Does not handle UTF-8 if (!oldCharacters || !oldCharacters[0]) return 0; - /*if (replaceCharacter == '\0') // Dans ce cas, il faut passer par un algorithme plus complexe + /*if (replaceCharacter == '\0') // In this case, we must use a more advance algorithm return ReplaceAny(String(oldCharacters), String(), start);*/ if (start < 0) @@ -2454,6 +3024,14 @@ namespace Nz } */ + /*! + * \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) @@ -2468,6 +3046,14 @@ namespace Nz 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) @@ -2510,6 +3096,14 @@ namespace Nz 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) @@ -2542,6 +3136,11 @@ namespace Nz return String(std::move(sharedStr)); } + /*! + * \brief Reverses the string + * \return A reference to this + */ + String& String::Reverse() { if (m_sharedString->size != 0) @@ -2556,6 +3155,11 @@ namespace Nz 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) @@ -2573,6 +3177,13 @@ namespace Nz 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') @@ -2597,6 +3208,15 @@ namespace Nz 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) @@ -2620,11 +3240,28 @@ namespace Nz 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; @@ -2650,16 +3287,39 @@ namespace Nz 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) @@ -2682,11 +3342,25 @@ namespace Nz 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; @@ -2694,6 +3368,13 @@ namespace Nz 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); @@ -2701,6 +3382,13 @@ namespace Nz 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) @@ -2763,11 +3451,28 @@ namespace Nz 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) @@ -2800,11 +3505,32 @@ namespace Nz 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) @@ -2848,11 +3574,31 @@ namespace Nz 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 separation List of characters of 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) @@ -2884,11 +3630,31 @@ namespace Nz return result.size()-oldSize; } + /*! + * \brief Splits the string into others + * \return The number of splits + * + * \param result Resulting tokens + * \param separation List of characters of 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) @@ -2900,6 +3666,16 @@ namespace Nz 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) @@ -2960,6 +3736,16 @@ namespace Nz 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) @@ -3009,6 +3795,14 @@ namespace Nz 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) @@ -3035,6 +3829,17 @@ namespace Nz return String(std::move(str)); } + /*! + * \brief Returns a sub string of the string from a character + * \return SubString + * + * \param charater 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') @@ -3054,11 +3859,34 @@ namespace Nz 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; @@ -3075,11 +3903,33 @@ namespace Nz 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 charater 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') @@ -3099,11 +3949,34 @@ namespace Nz 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; @@ -3120,16 +3993,41 @@ namespace Nz 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) @@ -3150,7 +4048,7 @@ namespace Nz else { if (flags & CaseInsensitive) - word = word.ToLower(); // Les mots identifiés sont en ASCII, inutile de passer le flag unicode + word = word.ToLower(); // The identified words are in ASCII, no use of Unicode flag if (word == "true") { @@ -3169,6 +4067,14 @@ namespace Nz return true; } + /*! + * \brief Converts the string to double + * \return true if successful + * + * \param value Double to convert to + * \param flags Flag for the look up + */ + bool String::ToDouble(double* value) const { if (m_sharedString->size == 0) @@ -3180,6 +4086,14 @@ namespace Nz return true; } + /*! + * \brief Converts the string to integer + * \return true if successful + * + * \param value Integer to convert to + * \param flags Flag for the look up + */ + bool String::ToInteger(long long* value, UInt8 base) const { if (value) @@ -3193,6 +4107,13 @@ namespace Nz 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) @@ -3225,6 +4146,13 @@ namespace Nz } } + /*! + * \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) @@ -3257,16 +4185,38 @@ namespace Nz } } + /*! + * \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) @@ -3331,6 +4281,14 @@ namespace Nz 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) @@ -3383,31 +4341,67 @@ namespace Nz 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); @@ -3434,11 +4428,25 @@ namespace Nz } */ + /*! + * \brief Converts the string to std::string + * \return std::string representation + */ + String::operator std::string() const { return std::string(m_sharedString->string.get(), m_sharedString->size); } + /*! + * \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(); @@ -3449,6 +4457,15 @@ namespace Nz 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 @@ -3462,31 +4479,73 @@ namespace Nz 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(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') @@ -3499,6 +4558,13 @@ namespace Nz 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]) @@ -3518,6 +4584,13 @@ namespace Nz 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()) @@ -3533,6 +4606,13 @@ namespace Nz 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) @@ -3548,26 +4628,61 @@ namespace Nz 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) @@ -3579,6 +4694,13 @@ namespace Nz 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) @@ -3590,6 +4712,13 @@ namespace Nz 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()) @@ -3601,6 +4730,13 @@ namespace Nz 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) @@ -3615,6 +4751,13 @@ namespace Nz 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) @@ -3626,6 +4769,13 @@ namespace Nz 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()) @@ -3637,6 +4787,13 @@ namespace Nz 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') @@ -3648,6 +4805,13 @@ namespace Nz 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]) @@ -3659,6 +4823,13 @@ namespace Nz 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()) @@ -3670,6 +4841,13 @@ namespace Nz 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) @@ -3681,6 +4859,13 @@ namespace Nz 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) @@ -3692,6 +4877,13 @@ namespace Nz 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) @@ -3703,6 +4895,13 @@ namespace Nz 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) @@ -3714,6 +4913,13 @@ namespace Nz 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) @@ -3725,6 +4931,13 @@ namespace Nz 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) @@ -3736,6 +4949,13 @@ namespace Nz 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') @@ -3747,6 +4967,13 @@ namespace Nz 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]) @@ -3758,6 +4985,13 @@ namespace Nz 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()) @@ -3769,6 +5003,13 @@ namespace Nz 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; @@ -3779,6 +5020,14 @@ namespace Nz return String(std::move(str)); } + /*! + * \brief Lexicographically compares the string + * \return The expected result + * + * \param first First string to use for comparison + * \parma second Second string to use for comparison + */ + int String::Compare(const String& first, const String& second) { if (first.m_sharedString->size == 0) @@ -3790,6 +5039,13 @@ namespace Nz return std::strcmp(first.GetConstBuffer(), second.GetConstBuffer()); } + /*! + * \brief Converts the number to string + * \return String representation of the number + * + * \param number Float value + */ + String String::Number(float number) { std::ostringstream oss; @@ -3799,6 +5055,13 @@ namespace Nz 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; @@ -3808,6 +5071,13 @@ namespace Nz 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; @@ -3817,56 +5087,143 @@ namespace Nz 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; @@ -3877,6 +5234,13 @@ namespace Nz 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') @@ -3898,11 +5262,25 @@ namespace Nz 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]) @@ -3914,7 +5292,7 @@ namespace Nz count++; while (*++ptr); - count *= 2; // On s'assure d'avoir la place suffisante + count *= 2; // We ensure to have enough place auto str = std::make_shared(count); @@ -3926,6 +5304,13 @@ namespace Nz 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]) @@ -3953,6 +5338,13 @@ namespace Nz 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]) @@ -3980,6 +5372,14 @@ namespace Nz 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(); @@ -4004,6 +5404,14 @@ namespace Nz return is; } + /*! + * \brief Output operator + * \return The stream + * + * \param out The stream + * \param str The string to output + */ + std::ostream& operator<<(std::ostream& os, const String& str) { if (str.IsEmpty()) @@ -4012,6 +5420,14 @@ namespace Nz 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') @@ -4027,6 +5443,14 @@ namespace Nz 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 string String in the right hand side + */ + String operator+(const char* string, const String& nstring) { if (!string || !string[0]) @@ -4045,6 +5469,14 @@ namespace Nz 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 string String in the right hand side + */ + String operator+(const std::string& string, const String& nstring) { if (string.empty()) @@ -4062,6 +5494,14 @@ namespace Nz 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) @@ -4076,11 +5516,27 @@ namespace Nz 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) @@ -4092,111 +5548,285 @@ namespace Nz 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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 second 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) @@ -4212,12 +5842,25 @@ namespace Nz } } + /*! + * \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 the string + * \return true if successful + * + * \param context Context of serialization + * \param string String to serialize + */ + bool Serialize(SerializationContext& context, const String& string) { if (!Serialize(context, string.GetSize())) @@ -4226,6 +5869,14 @@ namespace Nz return context.stream->Write(string.GetConstBuffer(), string.GetSize()) == string.GetSize(); } + /*! + * \brief Unserializes the string + * \return true if successful + * + * \param context Context of unserialization + * \param string String to unserialize + */ + bool Unserialize(SerializationContext& context, String* string) { UInt32 size; @@ -4241,6 +5892,14 @@ namespace Nz 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) { str.Clear(); @@ -4248,7 +5907,7 @@ namespace std char c; for (;;) - { + { is.get(c); if (c != '\n' && c != '\0') str += c; @@ -4259,6 +5918,15 @@ namespace std return is; } + /*! + * \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(); @@ -4277,6 +5945,13 @@ namespace std 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/StringStream.cpp b/src/Nazara/Core/StringStream.cpp index 2c2a8db24..a76dc9d86 100644 --- a/src/Nazara/Core/StringStream.cpp +++ b/src/Nazara/Core/StringStream.cpp @@ -7,17 +7,37 @@ namespace Nz { + /*! + * \class Nz::StringStream + * \brief Core class that represents a stream of strings + */ + + /*! + * \brief Constructs a StringStream object by default + */ + StringStream::StringStream() : m_bufferSize(0) { } + /*! + * \brief Constructs a StringStream object with a string + * + * \param str First value of the stream + */ + StringStream::StringStream(const String& str) : m_bufferSize(str.GetSize()) { m_strings.push_back(str); } + /*! + * \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 { String string; @@ -29,6 +49,13 @@ namespace Nz return string; } + /*! + * \brief Adds the representation of the boolean + * \return A reference to this + * + * \param boolean Boolean value + */ + StringStream& StringStream::operator<<(bool boolean) { m_strings.push_back(String::Boolean(boolean)); @@ -37,6 +64,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the short + * \return A reference to this + * + * \param number Short value + */ + StringStream& StringStream::operator<<(short number) { m_strings.push_back(String::Number(number)); @@ -45,6 +79,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -53,6 +94,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the int + * \return A reference to this + * + * \param number Int value + */ + StringStream& StringStream::operator<<(int number) { m_strings.push_back(String::Number(number)); @@ -61,6 +109,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -69,6 +124,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the long + * \return A reference to this + * + * \param number Long value + */ + StringStream& StringStream::operator<<(long number) { m_strings.push_back(String::Number(number)); @@ -77,6 +139,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -85,6 +154,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -93,6 +169,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -101,6 +184,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the float + * \return A reference to this + * + * \param number Float value + */ + StringStream& StringStream::operator<<(float number) { m_strings.push_back(String::Number(number)); @@ -109,6 +199,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the double + * \return A reference to this + * + * \param number Double value + */ + StringStream& StringStream::operator<<(double number) { m_strings.push_back(String::Number(number)); @@ -117,6 +214,13 @@ namespace Nz 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) { m_strings.push_back(String::Number(number)); @@ -125,6 +229,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the char + * \return A reference to this + * + * \param character Char value + */ + StringStream& StringStream::operator<<(char character) { m_strings.push_back(String(character)); @@ -133,6 +244,13 @@ namespace Nz 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_strings.push_back(String(static_cast(character))); @@ -141,6 +259,13 @@ namespace Nz 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_strings.push_back(string); @@ -149,6 +274,13 @@ namespace Nz 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_strings.push_back(string); @@ -157,6 +289,13 @@ namespace Nz 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_strings.push_back(string); @@ -165,6 +304,13 @@ namespace Nz return *this; } + /*! + * \brief Adds the representation of the pointer + * \return A reference to this + * + * \param ptr Pointer value + */ + StringStream& StringStream::operator<<(const void* ptr) { m_strings.push_back(String::Pointer(ptr)); @@ -173,6 +319,11 @@ namespace Nz 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/Unicode.cpp b/src/Nazara/Core/Unicode.cpp index c5b0d6917..9168e855e 100644 --- a/src/Nazara/Core/Unicode.cpp +++ b/src/Nazara/Core/Unicode.cpp @@ -11,20 +11,32 @@ namespace Nz { struct Character { - UInt16 category; // Le type du caractère - UInt8 direction; // Le sens de lecure du caractère - UInt32 lowerCase; // Le caractère correspondant en minuscule - UInt32 titleCase; // Le caractère correspondant en titre - UInt32 upperCase; // Le caractère correspondant en majuscule + UInt16 category; // The type of the character + UInt8 direction; // The reading way of the character + UInt32 lowerCase; // The corresponding lower character + UInt32 titleCase; // The corresponding title character + UInt32 upperCase; // The corresponding upper character }; } #include -#else // Implémentation supportant la table ASCII +#else // Implementation handling ASCII table namespace Nz { + /*! + * \class Nz::Unicode + * \brief Core class that represents a Unicode character + */ + + /*! + * \brief Gets the category of the character + * \return Unicode category + * + * \param character Character to get assignated category + */ + Unicode::Category Unicode::GetCategory(char32_t character) { switch (character) @@ -188,6 +200,13 @@ namespace Nz return Category_NoCategory; } + /*! + * \brief Gets the direction of reading of the character + * \return Unicode direction + * + * \param character Character to get assignated direction + */ + Unicode::Direction Unicode::GetDirection(char32_t character) { switch (character) @@ -347,6 +366,15 @@ namespace Nz return Direction_Boundary_Neutral; } + /*! + * \brief Gets the lower case of the character + * \return Unicode lower + * + * \param character Character to get assignated lower case + * + * \remark Only handling ASCII + */ + char32_t Unicode::GetLowercase(char32_t character) { if (character >= 'A' && character <= 'Z') @@ -355,11 +383,29 @@ namespace Nz return character; } + /*! + * \brief Gets the title case of the character + * \return Unicode title + * + * \param character Character to get assignated title case + * + * \remark Only handling ASCII + */ + char32_t Unicode::GetTitlecase(char32_t character) { return GetUppercase(character); } + /*! + * \brief Gets the upper case of the character + * \return Unicode upper + * + * \param character Character to get assignated upper case + * + * \remark Only handling ASCII + */ + char32_t Unicode::GetUppercase(char32_t character) { if (character >= 'a' && character <= 'z')