Documentation for String

Former-commit-id: caf1b5889604d7c2248ec88bde99a6bce0d7680f
This commit is contained in:
Gawaboumga 2016-02-21 14:32:17 +01:00
parent c163d65da7
commit f540029825
6 changed files with 1974 additions and 60 deletions

View File

@ -23,11 +23,11 @@ namespace Nz
public: public:
enum Flags enum Flags
{ {
None = 0x00, // Mode par défaut None = 0x00, // Default mode
CaseInsensitive = 0x01, // Insensible à la casse CaseInsensitive = 0x01, // Case insensitive
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8 HandleUtf8 = 0x02, // Considers bytes as a list of UTF-8 characters
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne TrimOnlyLeft = 0x04, // Trim(med), only cut the left part of the string
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne TrimOnlyRight = 0x08 // Trim(med), only cut the right part of the string
}; };
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 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 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(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 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 char* string, std::intmax_t start = -1, UInt32 flags = None) const;
std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const; std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;

View File

@ -7,22 +7,42 @@
namespace Nz 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>&& sharedString) : inline String::String(std::shared_ptr<SharedString>&& sharedString) :
m_sharedString(std::move(sharedString)) m_sharedString(std::move(sharedString))
{ {
} }
/*!
* \brief Releases the content to the string
*/
inline void String::ReleaseString() inline void String::ReleaseString()
{ {
m_sharedString = std::move(GetEmptyString()); m_sharedString = std::move(GetEmptyString());
} }
/*!
* \brief Constructs a SharedString object by default
*/
inline String::SharedString::SharedString() : // Special case: empty string inline String::SharedString::SharedString() : // Special case: empty string
capacity(0), capacity(0),
size(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) : inline String::SharedString::SharedString(std::size_t strSize) :
capacity(strSize), capacity(strSize),
size(strSize), size(strSize),
@ -31,6 +51,13 @@ namespace Nz
string[strSize] = '\0'; 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) : inline String::SharedString::SharedString(std::size_t strSize, std::size_t strCapacity) :
capacity(strCapacity), capacity(strCapacity),
size(strSize), size(strSize),
@ -39,6 +66,14 @@ namespace Nz
string[strSize] = '\0'; 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) inline bool HashAppend(AbstractHash* hash, const String& string)
{ {
hash->Append(reinterpret_cast<const UInt8*>(string.GetConstBuffer()), string.GetSize()); hash->Append(reinterpret_cast<const UInt8*>(string.GetConstBuffer()), string.GetSize());
@ -48,6 +83,13 @@ namespace Nz
namespace std namespace std
{ {
/*!
* \brief Specialisation of std to hash
* \return Result of the hash
*
* \param str String to hash
*/
template<> template<>
struct hash<Nz::String> struct hash<Nz::String>
{ {

View File

@ -18,16 +18,16 @@ namespace Nz
Unicode() = delete; Unicode() = delete;
~Unicode() = delete; ~Unicode() = delete;
/* /*
Catégorie Unicode: Unicode category:
-Les valeurs de 0x01 à 0x80 indiquent la catégorie. -Values between 0x01 and 0x80 specify the category
-Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie. -Values between 0x100 and 0x10000 specify the subcategory
*/ */
enum Category : UInt16 enum Category : UInt16
{ {
// Catégorie non-reconnue par Nazara // Category not handled by Nazara
Category_NoCategory = 0, Category_NoCategory = 0,
// Lettres // Letters
Category_Letter = 0x01, // L Category_Letter = 0x01, // L
Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll
Category_Letter_Modifier = Category_Letter | 0x0200, // Lm Category_Letter_Modifier = Category_Letter | 0x0200, // Lm
@ -35,19 +35,19 @@ namespace Nz
Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt
Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu
// Marques // Marks
Category_Mark = 0x02, // M Category_Mark = 0x02, // M
Category_Mark_Enclosing = Category_Mark | 0x100, // Me Category_Mark_Enclosing = Category_Mark | 0x100, // Me
Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn
Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc
// Nombres // Numbers
Category_Number = 0x04, // N Category_Number = 0x04, // N
Category_Number_DecimalDigit = Category_Number | 0x100, // Nd Category_Number_DecimalDigit = Category_Number | 0x100, // Nd
Category_Number_Letter = Category_Number | 0x200, // Nl Category_Number_Letter = Category_Number | 0x200, // Nl
Category_Number_Other = Category_Number | 0x400, // No Category_Number_Other = Category_Number | 0x400, // No
// Autres // Others
Category_Other = 0x08, // C Category_Other = 0x08, // C
Category_Other_Control = Category_Other | 0x0100, // Cc Category_Other_Control = Category_Other | 0x0100, // Cc
Category_Other_Format = Category_Other | 0x0200, // Cf Category_Other_Format = Category_Other | 0x0200, // Cf
@ -65,13 +65,13 @@ namespace Nz
Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps
Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po
// Espacements // Spaces
Category_Separator = 0x20, // Z Category_Separator = 0x20, // Z
Category_Separator_Line = Category_Separator | 0x0100, // Zl Category_Separator_Line = Category_Separator | 0x0100, // Zl
Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp
Category_Separator_Space = Category_Separator | 0x0400, // Zs Category_Separator_Space = Category_Separator | 0x0400, // Zs
// Symboles // Symbols
Category_Symbol = 0x40, // S Category_Symbol = 0x40, // S
Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc
Category_Symbol_Math = Category_Symbol | 0x0200, // Sm Category_Symbol_Math = Category_Symbol | 0x0200, // Sm

File diff suppressed because it is too large Load Diff

View File

@ -7,17 +7,37 @@
namespace Nz namespace Nz
{ {
/*!
* \class Nz::StringStream
* \brief Core class that represents a stream of strings
*/
/*!
* \brief Constructs a StringStream object by default
*/
StringStream::StringStream() : StringStream::StringStream() :
m_bufferSize(0) m_bufferSize(0)
{ {
} }
/*!
* \brief Constructs a StringStream object with a string
*
* \param str First value of the stream
*/
StringStream::StringStream(const String& str) : StringStream::StringStream(const String& str) :
m_bufferSize(str.GetSize()) m_bufferSize(str.GetSize())
{ {
m_strings.push_back(str); 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 StringStream::ToString() const
{ {
String string; String string;
@ -29,6 +49,13 @@ namespace Nz
return string; return string;
} }
/*!
* \brief Adds the representation of the boolean
* \return A reference to this
*
* \param boolean Boolean value
*/
StringStream& StringStream::operator<<(bool boolean) StringStream& StringStream::operator<<(bool boolean)
{ {
m_strings.push_back(String::Boolean(boolean)); m_strings.push_back(String::Boolean(boolean));
@ -37,6 +64,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the short
* \return A reference to this
*
* \param number Short value
*/
StringStream& StringStream::operator<<(short number) StringStream& StringStream::operator<<(short number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -45,6 +79,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(unsigned short number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -53,6 +94,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the int
* \return A reference to this
*
* \param number Int value
*/
StringStream& StringStream::operator<<(int number) StringStream& StringStream::operator<<(int number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -61,6 +109,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(unsigned int number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -69,6 +124,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the long
* \return A reference to this
*
* \param number Long value
*/
StringStream& StringStream::operator<<(long number) StringStream& StringStream::operator<<(long number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -77,6 +139,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(unsigned long number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -85,6 +154,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(long long number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -93,6 +169,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(unsigned long long number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -101,6 +184,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the float
* \return A reference to this
*
* \param number Float value
*/
StringStream& StringStream::operator<<(float number) StringStream& StringStream::operator<<(float number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -109,6 +199,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the double
* \return A reference to this
*
* \param number Double value
*/
StringStream& StringStream::operator<<(double number) StringStream& StringStream::operator<<(double number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -117,6 +214,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(long double number)
{ {
m_strings.push_back(String::Number(number)); m_strings.push_back(String::Number(number));
@ -125,6 +229,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the char
* \return A reference to this
*
* \param character Char value
*/
StringStream& StringStream::operator<<(char character) StringStream& StringStream::operator<<(char character)
{ {
m_strings.push_back(String(character)); m_strings.push_back(String(character));
@ -133,6 +244,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(unsigned char character)
{ {
m_strings.push_back(String(static_cast<char>(character))); m_strings.push_back(String(static_cast<char>(character)));
@ -141,6 +259,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(const char* string)
{ {
m_strings.push_back(string); m_strings.push_back(string);
@ -149,6 +274,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(const std::string& string)
{ {
m_strings.push_back(string); m_strings.push_back(string);
@ -157,6 +289,13 @@ namespace Nz
return *this; 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) StringStream& StringStream::operator<<(const String& string)
{ {
m_strings.push_back(string); m_strings.push_back(string);
@ -165,6 +304,13 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Adds the representation of the pointer
* \return A reference to this
*
* \param ptr Pointer value
*/
StringStream& StringStream::operator<<(const void* ptr) StringStream& StringStream::operator<<(const void* ptr)
{ {
m_strings.push_back(String::Pointer(ptr)); m_strings.push_back(String::Pointer(ptr));
@ -173,6 +319,11 @@ namespace Nz
return *this; return *this;
} }
/*!
* \brief Converts this to Nz::String
* \return The string representation of the stream
*/
StringStream::operator String() const StringStream::operator String() const
{ {
return ToString(); return ToString();

View File

@ -11,20 +11,32 @@ namespace Nz
{ {
struct Character struct Character
{ {
UInt16 category; // Le type du caractère UInt16 category; // The type of the character
UInt8 direction; // Le sens de lecure du caractère UInt8 direction; // The reading way of the character
UInt32 lowerCase; // Le caractère correspondant en minuscule UInt32 lowerCase; // The corresponding lower character
UInt32 titleCase; // Le caractère correspondant en titre UInt32 titleCase; // The corresponding title character
UInt32 upperCase; // Le caractère correspondant en majuscule UInt32 upperCase; // The corresponding upper character
}; };
} }
#include <Nazara/Core/UnicodeData.hpp> #include <Nazara/Core/UnicodeData.hpp>
#else // Implémentation supportant la table ASCII #else // Implementation handling ASCII table
namespace Nz 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) Unicode::Category Unicode::GetCategory(char32_t character)
{ {
switch (character) switch (character)
@ -188,6 +200,13 @@ namespace Nz
return Category_NoCategory; 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) Unicode::Direction Unicode::GetDirection(char32_t character)
{ {
switch (character) switch (character)
@ -347,6 +366,15 @@ namespace Nz
return Direction_Boundary_Neutral; 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) char32_t Unicode::GetLowercase(char32_t character)
{ {
if (character >= 'A' && character <= 'Z') if (character >= 'A' && character <= 'Z')
@ -355,11 +383,29 @@ namespace Nz
return character; 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) char32_t Unicode::GetTitlecase(char32_t character)
{ {
return GetUppercase(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) char32_t Unicode::GetUppercase(char32_t character)
{ {
if (character >= 'a' && character <= 'z') if (character >= 'a' && character <= 'z')