7 #ifndef NAZARA_STRING_HPP 8 #define NAZARA_STRING_HPP 10 #include <Nazara/Prerequesites.hpp> 11 #include <Nazara/Core/Endianness.hpp> 20 struct SerializationContext;
28 CaseInsensitive = 0x01,
35 explicit String(
char character);
36 String(std::size_t rep,
char character);
37 String(std::size_t rep,
const char*
string);
38 String(std::size_t rep,
const char*
string, std::size_t length);
40 String(
const char*
string);
41 String(
const char*
string, std::size_t length);
42 String(
const std::string&
string);
47 String& Append(
char character);
48 String& Append(
const char*
string);
49 String& Append(
const char*
string, std::size_t length);
52 void Clear(
bool keepBuffer =
false);
54 bool Contains(
char character, std::intmax_t start = 0, UInt32 flags =
None)
const;
55 bool Contains(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
56 bool Contains(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
58 unsigned int Count(
char character, std::intmax_t start = 0, UInt32 flags =
None)
const;
59 unsigned int Count(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
60 unsigned int Count(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
61 unsigned int CountAny(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
62 unsigned int CountAny(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
64 bool EndsWith(
char character, UInt32 flags =
None)
const;
65 bool EndsWith(
const char*
string, UInt32 flags =
None)
const;
66 bool EndsWith(
const char*
string, std::size_t length, UInt32 flags =
None)
const;
67 bool EndsWith(
const String&
string, UInt32 flags =
None)
const;
69 std::size_t Find(
char character, std::intmax_t start = 0, UInt32 flags =
None)
const;
70 std::size_t Find(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
71 std::size_t Find(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
72 std::size_t FindAny(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
73 std::size_t FindAny(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
74 std::size_t FindLast(
char character, std::intmax_t start = -1, UInt32 flags =
None)
const;
75 std::size_t FindLast(
const char*
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
76 std::size_t FindLast(
const String&
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
77 std::size_t FindLastAny(
const char*
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
78 std::size_t FindLastAny(
const String&
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
79 std::size_t FindLastWord(
const char*
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
80 std::size_t FindLastWord(
const String&
string, std::intmax_t start = -1, UInt32 flags =
None)
const;
81 std::size_t FindWord(
const char*
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
82 std::size_t FindWord(
const String&
string, std::intmax_t start = 0, UInt32 flags =
None)
const;
85 std::size_t GetCapacity()
const;
86 std::size_t GetCharacterPosition(std::size_t characterIndex)
const;
87 const char* GetConstBuffer()
const;
88 std::size_t GetLength()
const;
89 std::size_t GetSize()
const;
90 std::string GetUtf8String()
const;
91 std::u16string GetUtf16String()
const;
92 std::u32string GetUtf32String()
const;
93 std::wstring GetWideString()
const;
94 String GetWord(
unsigned int index, UInt32 flags =
None)
const;
95 std::size_t GetWordPosition(
unsigned int index, UInt32 flags =
None)
const;
97 String& Insert(std::intmax_t pos,
char character);
98 String& Insert(std::intmax_t pos,
const char*
string);
99 String& Insert(std::intmax_t pos,
const char*
string, std::size_t length);
100 String& Insert(std::intmax_t pos,
const String&
string);
102 bool IsEmpty()
const;
104 bool IsNumber(UInt8 radix = 10, UInt32 flags = CaseInsensitive)
const;
106 bool Match(
const char* pattern)
const;
107 bool Match(
const String& pattern)
const;
109 String& Prepend(
char character);
110 String& Prepend(
const char*
string);
111 String& Prepend(
const char*
string, std::size_t length);
114 unsigned int Replace(
char oldCharacter,
char newCharacter, std::intmax_t start = 0, UInt32 flags =
None);
115 unsigned int Replace(
const char* oldString,
const char* replaceString, std::intmax_t start = 0, UInt32 flags =
None);
116 unsigned int Replace(
const char* oldString, std::size_t oldLength,
const char* replaceString, std::size_t replaceLength, std::intmax_t start = 0, UInt32 flags =
None);
117 unsigned int Replace(
const String& oldString,
const String& replaceString, std::intmax_t start = 0, UInt32 flags =
None);
118 unsigned int ReplaceAny(
const char* oldCharacters,
char replaceCharacter, std::intmax_t start = 0, UInt32 flags =
None);
122 void Reserve(std::size_t bufferSize);
124 String& Resize(std::intmax_t size, UInt32 flags =
None);
125 String Resized(std::intmax_t size, UInt32 flags =
None)
const;
130 String& Set(
char character);
131 String& Set(std::size_t rep,
char character);
132 String& Set(std::size_t rep,
const char*
string);
133 String& Set(std::size_t rep,
const char*
string, std::size_t length);
135 String& Set(
const char*
string);
136 String& Set(
const char*
string, std::size_t length);
137 String& Set(
const std::string&
string);
144 unsigned int Split(std::vector<String>& result,
char separation =
' ', std::intmax_t start = 0, UInt32 flags =
None)
const;
145 unsigned int Split(std::vector<String>& result,
const char* separation, std::intmax_t start = 0, UInt32 flags =
None)
const;
146 unsigned int Split(std::vector<String>& result,
const char* separation, std::size_t length, std::intmax_t start = 0, UInt32 flags =
None)
const;
147 unsigned int Split(std::vector<String>& result,
const String& separation, std::intmax_t start = 0, UInt32 flags =
None)
const;
148 unsigned int SplitAny(std::vector<String>& result,
const char* separations, std::intmax_t start = 0, UInt32 flags =
None)
const;
149 unsigned int SplitAny(std::vector<String>& result,
const String& separations, std::intmax_t start = 0, UInt32 flags =
None)
const;
151 bool StartsWith(
char character, UInt32 flags =
None)
const;
152 bool StartsWith(
const char*
string, UInt32 flags =
None)
const;
153 bool StartsWith(
const String&
string, UInt32 flags =
None)
const;
155 String SubString(std::intmax_t startPos, std::intmax_t endPos = -1)
const;
156 String SubStringFrom(
char character, std::intmax_t startPos = 0,
bool fromLast =
false,
bool include =
false, UInt32 flags =
None)
const;
157 String SubStringFrom(
const char*
string, std::intmax_t startPos = 0,
bool fromLast =
false,
bool include =
false, UInt32 flags =
None)
const;
158 String SubStringFrom(
const char*
string, std::size_t length, std::intmax_t startPos = 0,
bool fromLast =
false,
bool include =
false, UInt32 flags =
None)
const;
159 String SubStringFrom(
const String&
string, std::intmax_t startPos = 0,
bool fromLast =
false,
bool include =
false, UInt32 flags =
None)
const;
160 String SubStringTo(
char character, std::intmax_t startPos = 0,
bool toLast =
false,
bool include =
false, UInt32 flags =
None)
const;
161 String SubStringTo(
const char*
string, std::intmax_t startPos = 0,
bool toLast =
false,
bool include =
false, UInt32 flags =
None)
const;
162 String SubStringTo(
const char*
string, std::size_t length, std::intmax_t startPos = 0,
bool toLast =
false,
bool include =
false, UInt32 flags =
None)
const;
163 String SubStringTo(
const String&
string, std::intmax_t startPos = 0,
bool toLast =
false,
bool include =
false, UInt32 flags =
None)
const;
167 bool ToBool(
bool* value, UInt32 flags =
None)
const;
168 bool ToDouble(
double* value)
const;
169 bool ToInteger(
long long* value, UInt8 radix = 10)
const;
174 String& Trim(
char character, UInt32 flags =
None);
176 String Trimmed(
char character, UInt32 flags =
None)
const;
180 const char* begin()
const;
182 const char* end()
const;
183 void push_front(
char c);
184 void push_back(
char c);
190 typedef const char& const_reference;
191 typedef char* iterator;
193 typedef char value_type;
196 operator std::string()
const;
198 char& operator[](std::size_t pos);
199 char operator[](std::size_t pos)
const;
201 String& operator=(
char character);
202 String& operator=(
const char*
string);
203 String& operator=(
const std::string&
string);
212 String& operator+=(
char character);
213 String& operator+=(
const char*
string);
214 String& operator+=(
const std::string&
string);
219 bool operator==(
const std::string&
string)
const;
223 bool operator!=(
const std::string&
string)
const;
226 bool operator<(
const char*
string)
const;
227 bool operator<(
const std::string&
string)
const;
231 bool operator<=(
const std::string&
string)
const;
234 bool operator>(
const char*
string)
const;
235 bool operator>(
const std::string&
string)
const;
239 bool operator>=(
const std::string&
string)
const;
241 static String Boolean(
bool boolean);
242 static int Compare(
const String& first,
const String& second);
243 static inline String Format(
const char* format, ...);
244 static String FormatVA(
const char* format, va_list arg);
245 static String Number(
float number);
246 static String Number(
double number);
247 static String Number(
long double number);
248 static String Number(
signed char number, UInt8 radix = 10);
249 static String Number(
unsigned char number, UInt8 radix = 10);
250 static String Number(
short number, UInt8 radix = 10);
251 static String Number(
unsigned short number, UInt8 radix = 10);
252 static String Number(
int number, UInt8 radix = 10);
253 static String Number(
unsigned int number, UInt8 radix = 10);
254 static String Number(
long number, UInt8 radix = 10);
255 static String Number(
unsigned long number, UInt8 radix = 10);
256 static String Number(
long long number, UInt8 radix = 10);
257 static String Number(
unsigned long long number, UInt8 radix = 10);
258 static String Pointer(
const void* ptr);
260 static String Unicode(
const char* u8String);
261 static String Unicode(
const char16_t* u16String);
262 static String Unicode(
const char32_t* u32String);
263 static String Unicode(
const wchar_t* wString);
265 NAZARA_CORE_API
friend std::istream&
operator>>(std::istream& in,
String&
string);
266 NAZARA_CORE_API
friend std::ostream& operator<<(std::ostream& out,
const String&
string);
279 NAZARA_CORE_API
friend bool operator==(
char character,
const String& nstring);
280 NAZARA_CORE_API
friend bool operator==(
const char*
string,
const String& nstring);
281 NAZARA_CORE_API
friend bool operator==(
const std::string&
string,
const String& nstring);
283 NAZARA_CORE_API
friend bool operator!=(
char character,
const String& nstring);
284 NAZARA_CORE_API
friend bool operator!=(
const char*
string,
const String& nstring);
285 NAZARA_CORE_API
friend bool operator!=(
const std::string&
string,
const String& nstring);
287 NAZARA_CORE_API
friend bool operator<(
char character,
const String& nstring);
288 NAZARA_CORE_API
friend bool operator<(
const char*
string,
const String& nstring);
289 NAZARA_CORE_API
friend bool operator<(
const std::string&
string,
const String& nstring);
291 NAZARA_CORE_API
friend bool operator<=(
char character,
const String& nstring);
292 NAZARA_CORE_API
friend bool operator<=(
const char*
string,
const String& nstring);
293 NAZARA_CORE_API
friend bool operator<=(
const std::string&
string,
const String& nstring);
295 NAZARA_CORE_API
friend bool operator>(
char character,
const String& nstring);
296 NAZARA_CORE_API
friend bool operator>(
const char*
string,
const String& nstring);
297 NAZARA_CORE_API
friend bool operator>(
const std::string&
string,
const String& nstring);
299 NAZARA_CORE_API
friend bool operator>=(
char character,
const String& nstring);
300 NAZARA_CORE_API
friend bool operator>=(
const char*
string,
const String& nstring);
301 NAZARA_CORE_API
friend bool operator>=(
const std::string&
string,
const String& nstring);
303 static const std::size_t npos;
308 String(std::shared_ptr<SharedString>&& sharedString);
310 void EnsureOwnership(
bool discardContent =
false);
311 inline void ReleaseString();
313 static const std::shared_ptr<SharedString>& GetEmptyString();
315 std::shared_ptr<SharedString> m_sharedString;
319 inline SharedString();
320 inline SharedString(std::size_t strSize);
321 inline SharedString(std::size_t strSize, std::size_t strCapacity);
323 std::size_t capacity;
325 std::unique_ptr<char[]> string;
338 NAZARA_CORE_API istream& getline(istream& is,
Nz::String& str);
339 NAZARA_CORE_API istream& getline(istream& is,
Nz::String& str,
char delim);
346 #include <Nazara/Core/String.inl> 348 #endif // NAZARA_STRING_HPP TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents the behaviour of the hash classes.
Definition: AbstractHash.hpp:18
bool operator<(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1517
bool Unserialize(SerializationContext &context, bool *value)
Unserializes a boolean.
Definition: Algorithm.inl:279
String operator+(char character, const String &string)
Concatenates the character to the string.
Definition: String.cpp:5506
bool operator>(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1566
Core class that represents a string.
Definition: String.hpp:22
bool operator!=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1503
Core class that represents a Unicode character.
Definition: Unicode.hpp:15
std::istream & operator>>(std::istream &is, String &str)
Inputs the stream into the string.
Definition: String.cpp:5458
Structure containing a serialization/unserialization context states.
Definition: SerializationContext.hpp:18
bool Serialize(SerializationContext &context, bool value)
Serializes a boolean.
Definition: Algorithm.inl:214
bool operator==(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1469
bool operator>=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1580
bool operator<=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1552