Documentation of SFML 2.4.0

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
String.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
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 <iterator>
34 #include <locale>
35 #include <string>
36 
37 
38 namespace sf
39 {
45 class SFML_SYSTEM_API String
46 {
47 public:
48 
50  // Types
52  typedef std::basic_string<Uint32>::iterator Iterator;
53  typedef std::basic_string<Uint32>::const_iterator ConstIterator;
54 
56  // Static member data
58  static const std::size_t InvalidPos;
59 
66  String();
67 
78  String(char ansiChar, const std::locale& locale = std::locale());
79 
86  String(wchar_t wideChar);
87 
94  String(Uint32 utf32Char);
95 
106  String(const char* ansiString, const std::locale& locale = std::locale());
107 
118  String(const std::string& ansiString, const std::locale& locale = std::locale());
119 
126  String(const wchar_t* wideString);
127 
134  String(const std::wstring& wideString);
135 
142  String(const Uint32* utf32String);
143 
150  String(const std::basic_string<Uint32>& utf32String);
151 
158  String(const String& copy);
159 
171  template <typename T>
172  static String fromUtf8(T begin, T end);
173 
185  template <typename T>
186  static String fromUtf16(T begin, T end);
187 
203  template <typename T>
204  static String fromUtf32(T begin, T end);
205 
221  operator std::string() const;
222 
236  operator std::wstring() const;
237 
253  std::string toAnsiString(const std::locale& locale = std::locale()) const;
254 
266  std::wstring toWideString() const;
267 
276  std::basic_string<Uint8> toUtf8() const;
277 
286  std::basic_string<Uint16> toUtf16() const;
287 
299  std::basic_string<Uint32> toUtf32() const;
300 
309  String& operator =(const String& right);
310 
319  String& operator +=(const String& right);
320 
332  Uint32 operator [](std::size_t index) const;
333 
345  Uint32& operator [](std::size_t index);
346 
355  void clear();
356 
365  std::size_t getSize() const;
366 
375  bool isEmpty() const;
376 
387  void erase(std::size_t position, std::size_t count = 1);
388 
399  void insert(std::size_t position, const String& str);
400 
413  std::size_t find(const String& str, std::size_t start = 0) const;
414 
427  void replace(std::size_t position, std::size_t length, const String& replaceWith);
428 
439  void replace(const String& searchFor, const String& replaceWith);
440 
456  String substring(std::size_t position, std::size_t length = InvalidPos) const;
457 
469  const Uint32* getData() const;
470 
479  Iterator begin();
480 
489  ConstIterator begin() const;
490 
503  Iterator end();
504 
517  ConstIterator end() const;
518 
519 private:
520 
521  friend SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
522  friend SFML_SYSTEM_API bool operator <(const String& left, const String& right);
523 
525  // Member data
527  std::basic_string<Uint32> m_string;
528 };
529 
540 SFML_SYSTEM_API bool operator ==(const String& left, const String& right);
541 
552 SFML_SYSTEM_API bool operator !=(const String& left, const String& right);
553 
564 SFML_SYSTEM_API bool operator <(const String& left, const String& right);
565 
576 SFML_SYSTEM_API bool operator >(const String& left, const String& right);
577 
588 SFML_SYSTEM_API bool operator <=(const String& left, const String& right);
589 
600 SFML_SYSTEM_API bool operator >=(const String& left, const String& right);
601 
612 SFML_SYSTEM_API String operator +(const String& left, const String& right);
613 
614 #include <SFML/System/String.inl>
615 
616 } // namespace sf
617 
618 
619 #endif // SFML_STRING_HPP
620 
621 
Utility string class that automatically handles conversions between types and encodings.
Definition: String.hpp:45
std::basic_string< Uint32 >::const_iterator ConstIterator
Read-only iterator type.
Definition: String.hpp:53
std::basic_string< Uint32 >::iterator Iterator
Iterator type.
Definition: String.hpp:52
static const std::size_t InvalidPos
Represents an invalid position in the string.
Definition: String.hpp:58