SFML - Simple and Fast Multimedia Library

SMFL 2.3.2

String.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 Laurent Gomila ([email protected])
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
31 #include <SFML/System/Export.hpp>
32 #include <SFML/System/Utf.hpp>
33 #include <locale>
34 #include <string>
35 
36 
37 namespace sf
38 {
44 class SFML_SYSTEM_API String
45 {
46 public:
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 
65  String();
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 
478  Iterator begin();
479 
488  ConstIterator begin() const;
489 
502  Iterator end();
503 
516  ConstIterator end() const;
517 
518 private:
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 
539 SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
540 
551 SFML_SYSTEM_API bool operator !=(const String& left, const String& right);
552 
563 SFML_SYSTEM_API bool operator <(const String& left, const String& right);
564 
575 SFML_SYSTEM_API bool operator >(const String& left, const String& right);
576 
587 SFML_SYSTEM_API bool operator <=(const String& left, const String& right);
588 
599 SFML_SYSTEM_API bool operator >=(const String& left, const String& right);
600 
611 SFML_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 
std::basic_string< Uint32 >::iterator Iterator
Iterator type.
Definition: String.hpp:51
static const std::size_t InvalidPos
Represents an invalid position in the string.
Definition: String.hpp:57
std::basic_string< Uint32 >::const_iterator ConstIterator
Read-only iterator type.
Definition: String.hpp:52
Utility string class that automatically handles conversions between types and encodings.
Definition: String.hpp:44