Loading...
Searching...
No Matches
String.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_STRING_HPP
26#define SFML_STRING_HPP
27
29// Headers
32#include <SFML/System/Utf.hpp>
33#include <locale>
34#include <string>
35
36
37namespace sf
38{
45{
46public:
47
49 // Types
51 typedef std::basic_string<Uint32>::iterator Iterator;
52 typedef std::basic_string<Uint32>::const_iterator ConstIterator;
53
55 // Static member data
57 static const std::size_t InvalidPos;
58
66
77 String(char ansiChar, const std::locale& locale = std::locale());
78
85 String(wchar_t wideChar);
86
93 String(Uint32 utf32Char);
94
105 String(const char* ansiString, const std::locale& locale = std::locale());
106
117 String(const std::string& ansiString, const std::locale& locale = std::locale());
118
125 String(const wchar_t* wideString);
126
133 String(const std::wstring& wideString);
134
141 String(const Uint32* utf32String);
142
149 String(const std::basic_string<Uint32>& utf32String);
150
157 String(const String& copy);
158
170 template <typename T>
171 static String fromUtf8(T begin, T end);
172
184 template <typename T>
185 static String fromUtf16(T begin, T end);
186
202 template <typename T>
203 static String fromUtf32(T begin, T end);
204
220 operator std::string() const;
221
235 operator std::wstring() const;
236
252 std::string toAnsiString(const std::locale& locale = std::locale()) const;
253
265 std::wstring toWideString() const;
266
275 std::basic_string<Uint8> toUtf8() const;
276
285 std::basic_string<Uint16> toUtf16() const;
286
298 std::basic_string<Uint32> toUtf32() const;
299
308 String& operator =(const String& right);
309
318 String& operator +=(const String& right);
319
331 Uint32 operator [](std::size_t index) const;
332
344 Uint32& operator [](std::size_t index);
345
354 void clear();
355
364 std::size_t getSize() const;
365
374 bool isEmpty() const;
375
386 void erase(std::size_t position, std::size_t count = 1);
387
398 void insert(std::size_t position, const String& str);
399
412 std::size_t find(const String& str, std::size_t start = 0) const;
413
426 void replace(std::size_t position, std::size_t length, const String& replaceWith);
427
438 void replace(const String& searchFor, const String& replaceWith);
439
455 String substring(std::size_t position, std::size_t length = InvalidPos) const;
456
468 const Uint32* getData() const;
469
479
489
503
517
518private:
519
520 friend SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
521 friend SFML_SYSTEM_API bool operator <(const String& left, const String& right);
522
524 // Member data
526 std::basic_string<Uint32> m_string;
527};
528
539SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
540
551SFML_SYSTEM_API bool operator !=(const String& left, const String& right);
552
563SFML_SYSTEM_API bool operator <(const String& left, const String& right);
564
575SFML_SYSTEM_API bool operator >(const String& left, const String& right);
576
587SFML_SYSTEM_API bool operator <=(const String& left, const String& right);
588
599SFML_SYSTEM_API bool operator >=(const String& left, const String& right);
600
611SFML_SYSTEM_API String operator +(const String& left, const String& right);
612
613#include <SFML/System/String.inl>
614
615} // namespace sf
616
617
618#endif // SFML_STRING_HPP
619
620
#define SFML_SYSTEM_API
Color operator+(const Color &left, const Color &right)
Overload of the binary + operator.
String(const std::string &ansiString, const std::locale &locale=std::locale())
Construct from an ANSI string and a locale.
ConstIterator begin() const
Return an iterator to the beginning of the string.
std::basic_string< Uint8 > toUtf8() const
Convert the Unicode string to a UTF-8 string.
bool isEmpty() const
Check whether the string is empty or not.
void clear()
Clear the string.
const Uint32 * getData() const
Get a pointer to the C-style array of characters.
String substring(std::size_t position, std::size_t length=InvalidPos) const
Return a part of the string.
String(const wchar_t *wideString)
Construct from null-terminated C-style wide string.
String(const char *ansiString, const std::locale &locale=std::locale())
Construct from a null-terminated C-style ANSI string and a locale.
String(const std::wstring &wideString)
Construct from a wide string.
String(const std::basic_string< Uint32 > &utf32String)
Construct from an UTF-32 string.
static String fromUtf16(T begin, T end)
Create a new sf::String from a UTF-16 encoded string.
void replace(const String &searchFor, const String &replaceWith)
Replace all occurrences of a substring with a replacement string.
std::basic_string< Uint32 >::const_iterator ConstIterator
Read-only iterator type.
Definition String.hpp:52
String(Uint32 utf32Char)
Construct from single UTF-32 character.
Iterator begin()
Return an iterator to the beginning of the string.
String()
Default constructor.
std::wstring toWideString() const
Convert the Unicode string to a wide string.
std::size_t find(const String &str, std::size_t start=0) const
Find a sequence of one or more characters in the string.
static String fromUtf8(T begin, T end)
Create a new sf::String from a UTF-8 encoded string.
void erase(std::size_t position, std::size_t count=1)
Erase one or more characters from the string.
static String fromUtf32(T begin, T end)
Create a new sf::String from a UTF-32 encoded string.
std::basic_string< Uint16 > toUtf16() const
Convert the Unicode string to a UTF-16 string.
static const std::size_t InvalidPos
Represents an invalid position in the string.
Definition String.hpp:57
Iterator end()
Return an iterator to the end of the string.
std::basic_string< Uint32 >::iterator Iterator
Iterator type.
Definition String.hpp:51
String(char ansiChar, const std::locale &locale=std::locale())
Construct from a single ANSI character and a locale.
void insert(std::size_t position, const String &str)
Insert one or more characters into the string.
void replace(std::size_t position, std::size_t length, const String &replaceWith)
Replace a substring with another string.
std::string toAnsiString(const std::locale &locale=std::locale()) const
Convert the Unicode string to an ANSI string.
std::size_t getSize() const
Get the size of the string.
String(const Uint32 *utf32String)
Construct from a null-terminated C-style UTF-32 string.
std::basic_string< Uint32 > toUtf32() const
Convert the Unicode string to a UTF-32 string.
String(wchar_t wideChar)
Construct from single wide character.
ConstIterator end() const
Return an iterator to the end of the string.
String(const String &copy)
Copy constructor.
bool operator==(const IpAddress &left, const IpAddress &right)
Overload of == operator to compare two IP addresses.
bool operator>=(const IpAddress &left, const IpAddress &right)
Overload of >= operator to compare two IP addresses.
bool operator!=(const IpAddress &left, const IpAddress &right)
Overload of != operator to compare two IP addresses.
bool operator<=(const IpAddress &left, const IpAddress &right)
Overload of <= operator to compare two IP addresses.
unsigned int Uint32
Definition Config.hpp:179
bool operator<(const IpAddress &left, const IpAddress &right)
Overload of < operator to compare two IP addresses.
bool operator>(const IpAddress &left, const IpAddress &right)
Overload of > operator to compare two IP addresses.