TGUI  0.9.1
String.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2021 Bruno Van de Velde (vdv_b@tgui.eu)
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 
26 #ifndef TGUI_STRING_HPP
27 #define TGUI_STRING_HPP
28 
29 #include <TGUI/Config.hpp>
30 #include <TGUI/Utf.hpp>
31 #include <string>
32 #include <vector>
33 #include <cstring>
34 #include <locale>
35 #include <iomanip>
36 #include <ostream>
37 #include <sstream>
38 
39 #if TGUI_HAS_BACKEND_SFML
40  #include <SFML/System/String.hpp>
41 #endif
42 
44 
45 namespace tgui
46 {
50  TGUI_API bool isWhitespace(char character);
51 
52 
56  TGUI_API bool isWhitespace(char32_t character);
57 
58 
73  class TGUI_API String
74  {
75  private:
76  std::u32string m_string;
77 
78  public:
79 
80  static const decltype(std::u32string::npos) npos;
81 
82  using iterator = std::u32string::iterator;
83  using const_iterator = std::u32string::const_iterator;
84  using reverse_iterator = std::u32string::reverse_iterator;
85  using const_reverse_iterator = std::u32string::const_reverse_iterator;
86 
87  using value_type = char32_t;
88  using reference = char32_t&;
89  using const_reference = const char32_t&;
90 
91 
92  public:
93 
101  bool attemptToInt(int& result) const;
102 
103 
111  bool attemptToUInt(unsigned int& result) const;
112 
113 
121  bool attemptToFloat(float& result) const;
122 
123 
131  int toInt(int defaultValue = 0) const;
132 
133 
141  unsigned int toUInt(unsigned int defaultValue = 0) const;
142 
143 
151  float toFloat(float defaultValue = 0) const;
152 
153 
159  String trim() const;
160 
161 
167  String toLower() const;
168 
169 
175  String toUpper() const;
176 
177 
185  bool equalIgnoreCase(const String& other) const;
186 
187 
195  bool startsWith(const String& substring) const;
196 
197 
205  bool endsWith(const String& substring) const;
206 
207 
216  String& replace(const String& searchFor, const String& replaceWith);
217 
218 
224  std::vector<String> split(char32_t delimiter) const;
225 
226 
233  static String join(const std::vector<String>& segments, const String& separator);
234 
235 
243  template <typename T>
244  static String fromNumber(T value)
245  {
246  std::ostringstream oss;
247  oss.imbue(std::locale::classic());
248  oss << value;
249  return String(oss.str());
250  }
251 
252 
261  template <typename T>
262  static String fromNumberRounded(T value, int decimals)
263  {
264  std::ostringstream oss;
265  oss.imbue(std::locale::classic());
266  oss << std::fixed << std::setprecision(decimals);
267  oss << value;
268  return String(oss.str());
269  }
270 
272  public:
273 
274  String() = default;
275 
276  String(const std::string& str);
277  String(const std::wstring& str);
278  String(const std::u16string& str);
279  String(const std::u32string& str);
280 
281  String(std::u32string&& str) :
282  m_string{std::move(str)}
283  {
284  }
285 
286  String(char ansiChar);
287  String(wchar_t wideChar);
288  String(char16_t utfChar);
289  String(char32_t utfChar);
290 
291  String(const char* str);
292  String(const wchar_t* str);
293  String(const char16_t* str);
294  String(const char32_t* str) :
295  m_string{str}
296  {
297  }
298 
299  // Constructor to initialize the string from a number (integer or float)
300  template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
301  explicit String(T number) :
302  String{fromNumber(number)}
303  {
304  }
305 
306  String(std::size_t count, char ch);
307  String(std::size_t count, wchar_t ch);
308  String(std::size_t count, char16_t ch);
309  String(std::size_t count, char32_t ch);
310 
311  String(const std::string& str, std::size_t pos);
312  String(const std::wstring& str, std::size_t pos);
313  String(const std::u16string& str, std::size_t pos);
314  String(const std::u32string& str, std::size_t pos);
315 
316  String(const std::string& str, std::size_t pos, std::size_t count);
317  String(const std::wstring& str, std::size_t pos, std::size_t count);
318  String(const std::u16string& str, std::size_t pos, std::size_t count);
319  String(const std::u32string& str, std::size_t pos, std::size_t count);
320 
321  String(const char* str, std::size_t count);
322  String(const wchar_t* str, std::size_t count);
323  String(const char16_t* str, std::size_t count);
324  String(const char32_t* str, std::size_t count);
325 
326  explicit String(std::initializer_list<char> chars);
327  explicit String(std::initializer_list<wchar_t> chars);
328  explicit String(std::initializer_list<char16_t> chars);
329  explicit String(std::initializer_list<char32_t> chars);
330 
331  // Constructors using iterators have to be explicit to prevent {"1", "2"} to be ambiguous between String and std::vector<String>.
332  // The reason these constructors were considered a candicate to clang is due to a private constructor in the iterator class.
333  explicit String(std::string::const_iterator first, std::string::const_iterator last);
334  explicit String(std::wstring::const_iterator first, std::wstring::const_iterator last);
335  explicit String(std::u16string::const_iterator first, std::u16string::const_iterator last);
336  explicit String(std::u32string::const_iterator first, std::u32string::const_iterator last);
337 
338 #if TGUI_HAS_BACKEND_SFML
339  // This constructor has to be explicit or it will cause MSVC to no longer compile code that performs sf::String + std::string
340  explicit String(const sf::String& str)
341  : m_string{reinterpret_cast<const char32_t*>(str.toUtf32().c_str())}
342  {
343  }
344 
345  explicit operator sf::String() const
346  {
347  return sf::String::fromUtf32(m_string.begin(), m_string.end());
348  }
349 #endif
350 
351  explicit operator std::string() const;
352  explicit operator std::wstring() const;
353  explicit operator std::u16string() const;
354  explicit operator const std::u32string&() const
355  {
356  return m_string;
357  }
358 
359  TGUI_DEPRECATED("Use toStdString instead") std::string toAnsiString() const;
360  std::string toStdString() const;
361  std::wstring toWideString() const;
362  std::u16string toUtf16() const;
363  const std::u32string& toUtf32() const
364  {
365  return m_string;
366  }
367 
368 #if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201811L)
369  std::u8string toUtf8() const
370  {
371  return utf::convertUtf32toUtf8(m_string);
372  }
373 #else
374  TGUI_DEPRECATED("Use toStdString instead") std::string toUtf8() const
375  {
376  return toStdString();
377  }
378 #endif
379 
380  String& assign(std::size_t count, char ch);
381  String& assign(std::size_t count, wchar_t ch);
382  String& assign(std::size_t count, char16_t ch);
383  String& assign(std::size_t count, char32_t ch);
384 
385  String& assign(const std::string& str);
386  String& assign(const std::wstring& str);
387  String& assign(const std::u16string& str);
388  String& assign(const std::u32string& str);
389  String& assign(const String& str);
390 
391  String& assign(const std::string& str, std::size_t pos, std::size_t count = npos);
392  String& assign(const std::wstring& str, std::size_t pos, std::size_t count = npos);
393  String& assign(const std::u16string& str, std::size_t pos, std::size_t count = npos);
394  String& assign(const std::u32string& str, std::size_t pos, std::size_t count = npos);
395  String& assign(const String& str, std::size_t pos, std::size_t count = npos);
396 
397  String& assign(std::string&& str);
398  String& assign(std::wstring&& str);
399  String& assign(std::u16string&& str);
400  String& assign(std::u32string&& str);
401  String& assign(String&& str);
402 
403  String& assign(const char* str, std::size_t count);
404  String& assign(const wchar_t* str, std::size_t count);
405  String& assign(const char16_t* str, std::size_t count);
406  String& assign(const char32_t* str, std::size_t count);
407 
408  String& assign(const char* str);
409  String& assign(const wchar_t* str);
410  String& assign(const char16_t* str);
411  String& assign(const char32_t* str);
412 
413  String& assign(std::initializer_list<char> chars);
414  String& assign(std::initializer_list<wchar_t> chars);
415  String& assign(std::initializer_list<char16_t> chars);
416  String& assign(std::initializer_list<char32_t> chars);
417 
418  String& assign(std::string::const_iterator first, std::string::const_iterator last);
419  String& assign(std::wstring::const_iterator first, std::wstring::const_iterator last);
420  String& assign(std::u16string::const_iterator first, std::u16string::const_iterator last);
421  String& assign(std::u32string::const_iterator first, std::u32string::const_iterator last);
422 
423  reference at(std::size_t pos);
424  const_reference at(std::size_t pos) const;
425 
426  const_reference operator [](std::size_t index) const;
427  reference operator [](std::size_t index);
428 
429  reference front();
430  const_reference front() const;
431 
432  reference back();
433  const_reference back() const;
434 
435  const char32_t* data() const noexcept
436  {
437  return m_string.data();
438  }
439 
440 #if __cplusplus >= 201703L
441  char32_t* data() noexcept
442  {
443  return m_string.data();
444  }
445 #endif
446  const char32_t* c_str() const noexcept
447  {
448  return m_string.c_str();
449  }
450 
451  iterator begin() noexcept;
452  const_iterator begin() const noexcept;
453  const_iterator cbegin() const noexcept;
454 
455  iterator end() noexcept;
456  const_iterator end() const noexcept;
457  const_iterator cend() const noexcept;
458 
459  reverse_iterator rbegin() noexcept;
460  const_reverse_iterator rbegin() const noexcept;
461  const_reverse_iterator crbegin() const noexcept;
462 
463  reverse_iterator rend() noexcept;
464  const_reverse_iterator rend() const noexcept;
465  const_reverse_iterator crend() const noexcept;
466 
467  bool empty() const noexcept
468  {
469  return m_string.empty();
470  }
471 
472  std::size_t size() const noexcept
473  {
474  return m_string.size();
475  }
476 
477  std::size_t length() const noexcept
478  {
479  return m_string.length();
480  }
481 
482  std::size_t max_size() const noexcept;
483 
484  void reserve(std::size_t newCap);
485  std::size_t capacity() const noexcept;
486  void shrink_to_fit();
487 
488  void clear() noexcept;
489 
490  String& insert(std::size_t index, std::size_t count, char ch);
491  String& insert(std::size_t index, std::size_t count, wchar_t ch);
492  String& insert(std::size_t index, std::size_t count, char16_t ch);
493  String& insert(std::size_t index, std::size_t count, char32_t ch);
494 
495  String& insert(std::size_t index, const std::string& str);
496  String& insert(std::size_t index, const std::wstring& str);
497  String& insert(std::size_t index, const std::u16string& str);
498  String& insert(std::size_t index, const std::u32string& str);
499  String& insert(std::size_t index, const String& str);
500 
501  String& insert(std::size_t index, const std::string& str, std::size_t pos, std::size_t count = npos);
502  String& insert(std::size_t index, const std::wstring& str, std::size_t pos, std::size_t count = npos);
503  String& insert(std::size_t index, const std::u16string& str, std::size_t pos, std::size_t count = npos);
504  String& insert(std::size_t index, const std::u32string& str, std::size_t pos, std::size_t count = npos);
505  String& insert(std::size_t index, const String& str, std::size_t pos, std::size_t count = npos);
506 
507  String& insert(std::size_t index, const char* str, std::size_t count);
508  String& insert(std::size_t index, const wchar_t* str, std::size_t count);
509  String& insert(std::size_t index, const char16_t* str, std::size_t count);
510  String& insert(std::size_t index, const char32_t* str, std::size_t count);
511 
512  String& insert(std::size_t index, const char* str);
513  String& insert(std::size_t index, const wchar_t* str);
514  String& insert(std::size_t index, const char16_t* str);
515  String& insert(std::size_t index, const char32_t* str);
516 
517  iterator insert(const_iterator pos, char ch);
518  iterator insert(const_iterator pos, wchar_t ch);
519  iterator insert(const_iterator pos, char16_t ch);
520  iterator insert(const_iterator pos, char32_t ch);
521 
522  iterator insert(const_iterator pos, std::size_t count, char ch);
523  iterator insert(const_iterator pos, std::size_t count, wchar_t ch);
524  iterator insert(const_iterator pos, std::size_t count, char16_t ch);
525  iterator insert(const_iterator pos, std::size_t count, char32_t ch);
526 
527  iterator insert(const_iterator pos, std::initializer_list<char> chars);
528  iterator insert(const_iterator pos, std::initializer_list<wchar_t> chars);
529  iterator insert(const_iterator pos, std::initializer_list<char16_t> chars);
530  iterator insert(const_iterator pos, std::initializer_list<char32_t> chars);
531 
532  iterator insert(const_iterator pos, std::string::const_iterator first, std::string::const_iterator last);
533  iterator insert(const_iterator pos, std::wstring::const_iterator first, std::wstring::const_iterator last);
534  iterator insert(const_iterator pos, std::u16string::const_iterator first, std::u16string::const_iterator last);
535  iterator insert(const_iterator pos, std::u32string::const_iterator first, std::u32string::const_iterator last);
536 
537  String& erase(std::size_t index = 0, std::size_t count = npos);
538 
539  iterator erase(const_iterator position);
540  iterator erase(const_iterator first, const_iterator last);
541 
542  void push_back(char ch);
543  void push_back(wchar_t ch);
544  void push_back(char16_t ch);
545  void push_back(char32_t ch);
546 
547  void pop_back();
548 
549  String& append(std::size_t count, char ch);
550  String& append(std::size_t count, wchar_t ch);
551  String& append(std::size_t count, char16_t ch);
552  String& append(std::size_t count, char32_t ch);
553 
554  String& append(const std::string& str);
555  String& append(const std::wstring& str);
556  String& append(const std::u16string& str);
557  String& append(const std::u32string& str);
558  String& append(const String& str);
559 
560  String& append(const std::string& str, std::size_t pos, std::size_t count = npos);
561  String& append(const std::wstring& str, std::size_t pos, std::size_t count = npos);
562  String& append(const std::u16string& str, std::size_t pos, std::size_t count = npos);
563  String& append(const std::u32string& str, std::size_t pos, std::size_t count = npos);
564  String& append(const String& str, std::size_t pos, std::size_t count = npos);
565 
566  String& append(const char* str, std::size_t count);
567  String& append(const wchar_t* str, std::size_t count);
568  String& append(const char16_t* str, std::size_t count);
569  String& append(const char32_t* str, std::size_t count);
570 
571  String& append(const char* str);
572  String& append(const wchar_t* str);
573  String& append(const char16_t* str);
574  String& append(const char32_t* str);
575 
576  String& append(std::string::const_iterator first, std::string::const_iterator last);
577  String& append(std::wstring::const_iterator first, std::wstring::const_iterator last);
578  String& append(std::u16string::const_iterator first, std::u16string::const_iterator last);
579  String& append(std::u32string::const_iterator first, std::u32string::const_iterator last);
580 
581  String& append(std::initializer_list<char> chars);
582  String& append(std::initializer_list<wchar_t> chars);
583  String& append(std::initializer_list<char16_t> chars);
584  String& append(std::initializer_list<char32_t> chars);
585 
586  String& operator+=(const String& str);
587 
588  int compare(const std::string& str) const noexcept;
589  int compare(const std::wstring& str) const noexcept;
590  int compare(const std::u16string& str) const noexcept;
591  int compare(const std::u32string& str) const noexcept;
592  int compare(const String& str) const noexcept;
593 
594  int compare(std::size_t pos1, std::size_t count1, const std::string& str) const;
595  int compare(std::size_t pos1, std::size_t count1, const std::wstring& str) const;
596  int compare(std::size_t pos1, std::size_t count1, const std::u16string& str) const;
597  int compare(std::size_t pos1, std::size_t count1, const std::u32string& str) const;
598  int compare(std::size_t pos1, std::size_t count1, const String& str) const;
599 
600  int compare(std::size_t pos1, std::size_t count1, const std::string& str, std::size_t pos2, std::size_t count2 = npos) const;
601  int compare(std::size_t pos1, std::size_t count1, const std::wstring& str, std::size_t pos2, std::size_t count2 = npos) const;
602  int compare(std::size_t pos1, std::size_t count1, const std::u16string& str, std::size_t pos2, std::size_t count2 = npos) const;
603  int compare(std::size_t pos1, std::size_t count1, const std::u32string& str, std::size_t pos2, std::size_t count2 = npos) const;
604  int compare(std::size_t pos1, std::size_t count1, const String& str, std::size_t pos2, std::size_t count2 = npos) const;
605 
606  int compare(const char* s) const;
607  int compare(const wchar_t* s) const;
608  int compare(const char16_t* s) const;
609  int compare(const char32_t* s) const;
610 
611  int compare(std::size_t pos1, std::size_t count1, const char* s) const;
612  int compare(std::size_t pos1, std::size_t count1, const wchar_t* s) const;
613  int compare(std::size_t pos1, std::size_t count1, const char16_t* s) const;
614  int compare(std::size_t pos1, std::size_t count1, const char32_t* s) const;
615 
616  int compare(std::size_t pos1, std::size_t count1, const char* s, std::size_t count2) const;
617  int compare(std::size_t pos1, std::size_t count1, const wchar_t* s, std::size_t count2) const;
618  int compare(std::size_t pos1, std::size_t count1, const char16_t* s, std::size_t count2) const;
619  int compare(std::size_t pos1, std::size_t count1, const char32_t* s, std::size_t count2) const;
620 
621  String& replace(std::size_t pos, std::size_t count, const std::string& str);
622  String& replace(std::size_t pos, std::size_t count, const std::wstring& str);
623  String& replace(std::size_t pos, std::size_t count, const std::u16string& str);
624  String& replace(std::size_t pos, std::size_t count, const std::u32string& str);
625  String& replace(std::size_t pos, std::size_t count, const String& str);
626 
627  String& replace(const_iterator first, const_iterator last, const std::string& str);
628  String& replace(const_iterator first, const_iterator last, const std::wstring& str);
629  String& replace(const_iterator first, const_iterator last, const std::u16string& str);
630  String& replace(const_iterator first, const_iterator last, const std::u32string& str);
631  String& replace(const_iterator first, const_iterator last, const String& str);
632 
633  String& replace(std::size_t pos, std::size_t count, const std::string& str, std::size_t pos2, std::size_t count2 = npos);
634  String& replace(std::size_t pos, std::size_t count, const std::wstring& str, std::size_t pos2, std::size_t count2 = npos);
635  String& replace(std::size_t pos, std::size_t count, const std::u16string& str, std::size_t pos2, std::size_t count2 = npos);
636  String& replace(std::size_t pos, std::size_t count, const std::u32string& str, std::size_t pos2, std::size_t count2 = npos);
637  String& replace(std::size_t pos, std::size_t count, const String& str, std::size_t pos2, std::size_t count2 = npos);
638 
639  String& replace(const_iterator first, const_iterator last, std::string::const_iterator first2, std::string::const_iterator last2);
640  String& replace(const_iterator first, const_iterator last, std::wstring::const_iterator first2, std::wstring::const_iterator last2);
641  String& replace(const_iterator first, const_iterator last, std::u16string::const_iterator first2, std::u16string::const_iterator last2);
642  String& replace(const_iterator first, const_iterator last, std::u32string::const_iterator first2, std::u32string::const_iterator last2);
643 
644  String& replace(std::size_t pos, std::size_t count, const char* cstr, std::size_t count2);
645  String& replace(std::size_t pos, std::size_t count, const wchar_t* cstr, std::size_t count2);
646  String& replace(std::size_t pos, std::size_t count, const char16_t* cstr, std::size_t count2);
647  String& replace(std::size_t pos, std::size_t count, const char32_t* cstr, std::size_t count2);
648 
649  String& replace(const_iterator first, const_iterator last, const char* cstr, std::size_t count2);
650  String& replace(const_iterator first, const_iterator last, const wchar_t* cstr, std::size_t count2);
651  String& replace(const_iterator first, const_iterator last, const char16_t* cstr, std::size_t count2);
652  String& replace(const_iterator first, const_iterator last, const char32_t* cstr, std::size_t count2);
653 
654  String& replace(std::size_t pos, std::size_t count, const char* cstr);
655  String& replace(std::size_t pos, std::size_t count, const wchar_t* cstr);
656  String& replace(std::size_t pos, std::size_t count, const char16_t* cstr);
657  String& replace(std::size_t pos, std::size_t count, const char32_t* cstr);
658 
659  String& replace(const_iterator first, const_iterator last, const char* cstr);
660  String& replace(const_iterator first, const_iterator last, const wchar_t* cstr);
661  String& replace(const_iterator first, const_iterator last, const char16_t* cstr);
662  String& replace(const_iterator first, const_iterator last, const char32_t* cstr);
663 
664  String& replace(std::size_t pos, std::size_t count, std::size_t count2, char ch);
665  String& replace(std::size_t pos, std::size_t count, std::size_t count2, wchar_t ch);
666  String& replace(std::size_t pos, std::size_t count, std::size_t count2, char16_t ch);
667  String& replace(std::size_t pos, std::size_t count, std::size_t count2, char32_t ch);
668 
669  String& replace(const_iterator first, const_iterator last, std::size_t count2, char ch);
670  String& replace(const_iterator first, const_iterator last, std::size_t count2, wchar_t ch);
671  String& replace(const_iterator first, const_iterator last, std::size_t count2, char16_t ch);
672  String& replace(const_iterator first, const_iterator last, std::size_t count2, char32_t ch);
673 
674  String& replace(const_iterator first, const_iterator last, std::initializer_list<char> chars);
675  String& replace(const_iterator first, const_iterator last, std::initializer_list<wchar_t> chars);
676  String& replace(const_iterator first, const_iterator last, std::initializer_list<char16_t> chars);
677  String& replace(const_iterator first, const_iterator last, std::initializer_list<char32_t> chars);
678 
679  String substr(std::size_t pos = 0, std::size_t count = npos) const;
680 
681  std::size_t copy(char32_t* dest, std::size_t count, std::size_t pos = 0) const;
682 
683  void resize(std::size_t count);
684  void resize(std::size_t count, char ch);
685  void resize(std::size_t count, wchar_t ch);
686  void resize(std::size_t count, char16_t ch);
687  void resize(std::size_t count, char32_t ch);
688 
689  void swap(String& other);
690 
691  std::size_t find(const std::string& str, std::size_t pos = 0) const noexcept;
692  std::size_t find(const std::wstring& str, std::size_t pos = 0) const noexcept;
693  std::size_t find(const std::u16string& str, std::size_t pos = 0) const noexcept;
694  std::size_t find(const std::u32string& str, std::size_t pos = 0) const noexcept;
695  std::size_t find(const String& str, std::size_t pos = 0) const noexcept;
696 
697  std::size_t find(const char* s, std::size_t pos, std::size_t count) const;
698  std::size_t find(const wchar_t* s, std::size_t pos, std::size_t count) const;
699  std::size_t find(const char16_t* s, std::size_t pos, std::size_t count) const;
700  std::size_t find(const char32_t* s, std::size_t pos, std::size_t count) const;
701 
702  std::size_t find(const char* s, std::size_t pos = 0) const;
703  std::size_t find(const wchar_t* s, std::size_t pos = 0) const;
704  std::size_t find(const char16_t* s, std::size_t pos = 0) const;
705  std::size_t find(const char32_t* s, std::size_t pos = 0) const;
706 
707  std::size_t find(char ch, std::size_t pos = 0) const noexcept;
708  std::size_t find(wchar_t ch, std::size_t pos = 0) const noexcept;
709  std::size_t find(char16_t ch, std::size_t pos = 0) const noexcept;
710  std::size_t find(char32_t ch, std::size_t pos = 0) const noexcept;
711 
712  std::size_t find_first_of(const std::string& str, std::size_t pos = 0) const noexcept;
713  std::size_t find_first_of(const std::wstring& str, std::size_t pos = 0) const noexcept;
714  std::size_t find_first_of(const std::u16string& str, std::size_t pos = 0) const noexcept;
715  std::size_t find_first_of(const std::u32string& str, std::size_t pos = 0) const noexcept;
716  std::size_t find_first_of(const String& str, std::size_t pos = 0) const noexcept;
717 
718  std::size_t find_first_of(const char* s, std::size_t pos, std::size_t count) const;
719  std::size_t find_first_of(const wchar_t* s, std::size_t pos, std::size_t count) const;
720  std::size_t find_first_of(const char16_t* s, std::size_t pos, std::size_t count) const;
721  std::size_t find_first_of(const char32_t* s, std::size_t pos, std::size_t count) const;
722 
723  std::size_t find_first_of(const char* s, std::size_t pos = 0) const;
724  std::size_t find_first_of(const wchar_t* s, std::size_t pos = 0) const;
725  std::size_t find_first_of(const char16_t* s, std::size_t pos = 0) const;
726  std::size_t find_first_of(const char32_t* s, std::size_t pos = 0) const;
727 
728  std::size_t find_first_of(char ch, std::size_t pos = 0) const noexcept;
729  std::size_t find_first_of(wchar_t ch, std::size_t pos = 0) const noexcept;
730  std::size_t find_first_of(char16_t ch, std::size_t pos = 0) const noexcept;
731  std::size_t find_first_of(char32_t ch, std::size_t pos = 0) const noexcept;
732 
733  std::size_t find_first_not_of(const std::string& str, std::size_t pos = 0) const noexcept;
734  std::size_t find_first_not_of(const std::wstring& str, std::size_t pos = 0) const noexcept;
735  std::size_t find_first_not_of(const std::u16string& str, std::size_t pos = 0) const noexcept;
736  std::size_t find_first_not_of(const std::u32string& str, std::size_t pos = 0) const noexcept;
737  std::size_t find_first_not_of(const String& str, std::size_t pos = 0) const noexcept;
738 
739  std::size_t find_first_not_of(const char* s, std::size_t pos, std::size_t count) const;
740  std::size_t find_first_not_of(const wchar_t* s, std::size_t pos, std::size_t count) const;
741  std::size_t find_first_not_of(const char16_t* s, std::size_t pos, std::size_t count) const;
742  std::size_t find_first_not_of(const char32_t* s, std::size_t pos, std::size_t count) const;
743 
744  std::size_t find_first_not_of(const char* s, std::size_t pos = 0) const;
745  std::size_t find_first_not_of(const wchar_t* s, std::size_t pos = 0) const;
746  std::size_t find_first_not_of(const char16_t* s, std::size_t pos = 0) const;
747  std::size_t find_first_not_of(const char32_t* s, std::size_t pos = 0) const;
748 
749  std::size_t find_first_not_of(char ch, std::size_t pos = 0) const noexcept;
750  std::size_t find_first_not_of(wchar_t ch, std::size_t pos = 0) const noexcept;
751  std::size_t find_first_not_of(char16_t ch, std::size_t pos = 0) const noexcept;
752  std::size_t find_first_not_of(char32_t ch, std::size_t pos = 0) const noexcept;
753 
754  std::size_t rfind(const std::string& str, std::size_t pos = npos) const noexcept;
755  std::size_t rfind(const std::wstring& str, std::size_t pos = npos) const noexcept;
756  std::size_t rfind(const std::u16string& str, std::size_t pos = npos) const noexcept;
757  std::size_t rfind(const std::u32string& str, std::size_t pos = npos) const noexcept;
758  std::size_t rfind(const String& str, std::size_t pos = npos) const noexcept;
759 
760  std::size_t rfind(const char* s, std::size_t pos, std::size_t count) const;
761  std::size_t rfind(const wchar_t* s, std::size_t pos, std::size_t count) const;
762  std::size_t rfind(const char16_t* s, std::size_t pos, std::size_t count) const;
763  std::size_t rfind(const char32_t* s, std::size_t pos, std::size_t count) const;
764 
765  std::size_t rfind(const char* s, std::size_t pos = npos) const;
766  std::size_t rfind(const wchar_t* s, std::size_t pos = npos) const;
767  std::size_t rfind(const char16_t* s, std::size_t pos = npos) const;
768  std::size_t rfind(const char32_t* s, std::size_t pos = npos) const;
769 
770  std::size_t rfind(char ch, std::size_t pos = npos) const noexcept;
771  std::size_t rfind(wchar_t ch, std::size_t pos = npos) const noexcept;
772  std::size_t rfind(char16_t ch, std::size_t pos = npos) const noexcept;
773  std::size_t rfind(char32_t ch, std::size_t pos = npos) const noexcept;
774 
775  std::size_t find_last_of(const std::string& str, std::size_t pos = npos) const noexcept;
776  std::size_t find_last_of(const std::wstring& str, std::size_t pos = npos) const noexcept;
777  std::size_t find_last_of(const std::u16string& str, std::size_t pos = npos) const noexcept;
778  std::size_t find_last_of(const std::u32string& str, std::size_t pos = npos) const noexcept;
779  std::size_t find_last_of(const String& str, std::size_t pos = npos) const noexcept;
780 
781  std::size_t find_last_of(const char* s, std::size_t pos, std::size_t count) const;
782  std::size_t find_last_of(const wchar_t* s, std::size_t pos, std::size_t count) const;
783  std::size_t find_last_of(const char16_t* s, std::size_t pos, std::size_t count) const;
784  std::size_t find_last_of(const char32_t* s, std::size_t pos, std::size_t count) const;
785 
786  std::size_t find_last_of(const char* s, std::size_t pos = npos) const;
787  std::size_t find_last_of(const wchar_t* s, std::size_t pos = npos) const;
788  std::size_t find_last_of(const char16_t* s, std::size_t pos = npos) const;
789  std::size_t find_last_of(const char32_t* s, std::size_t pos = npos) const;
790 
791  std::size_t find_last_of(char ch, std::size_t pos = npos) const noexcept;
792  std::size_t find_last_of(wchar_t ch, std::size_t pos = npos) const noexcept;
793  std::size_t find_last_of(char16_t ch, std::size_t pos = npos) const noexcept;
794  std::size_t find_last_of(char32_t ch, std::size_t pos = npos) const noexcept;
795 
796  std::size_t find_last_not_of(const std::string& str, std::size_t pos = npos) const noexcept;
797  std::size_t find_last_not_of(const std::wstring& str, std::size_t pos = npos) const noexcept;
798  std::size_t find_last_not_of(const std::u16string& str, std::size_t pos = npos) const noexcept;
799  std::size_t find_last_not_of(const std::u32string& str, std::size_t pos = npos) const noexcept;
800  std::size_t find_last_not_of(const String& str, std::size_t pos = npos) const noexcept;
801 
802  std::size_t find_last_not_of(const char* s, std::size_t pos, std::size_t count) const;
803  std::size_t find_last_not_of(const wchar_t* s, std::size_t pos, std::size_t count) const;
804  std::size_t find_last_not_of(const char16_t* s, std::size_t pos, std::size_t count) const;
805  std::size_t find_last_not_of(const char32_t* s, std::size_t pos, std::size_t count) const;
806 
807  std::size_t find_last_not_of(const char* s, std::size_t pos = npos) const;
808  std::size_t find_last_not_of(const wchar_t* s, std::size_t pos = npos) const;
809  std::size_t find_last_not_of(const char16_t* s, std::size_t pos = npos) const;
810  std::size_t find_last_not_of(const char32_t* s, std::size_t pos = npos) const;
811 
812  std::size_t find_last_not_of(char ch, std::size_t pos = npos) const noexcept;
813  std::size_t find_last_not_of(wchar_t ch, std::size_t pos = npos) const noexcept;
814  std::size_t find_last_not_of(char16_t ch, std::size_t pos = npos) const noexcept;
815  std::size_t find_last_not_of(char32_t ch, std::size_t pos = npos) const noexcept;
816 
817  friend bool operator==(const String& left, const String& right);
818  friend bool operator!=(const String& left, const String& right);
819  friend bool operator<(const String& left, const String& right);
820  friend bool operator<=(const String& left, const String& right);
821  friend bool operator>(const String& left, const String& right);
822  friend bool operator>=(const String& left, const String& right);
823  friend String operator+(const String& left, const String& right);
824  friend String operator+(const String& left, String&& right);
825  friend String operator+(String&& left, const String& right);
826  friend String operator+(String&& left, String&& right);
827 
828 #if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201811L)
829  String(const std::u8string& str);
830  String(char8_t utfChar);
831  String(const char8_t* str);
832  String(std::size_t count, char8_t ch);
833  String(const std::u8string& str, std::size_t pos);
834  String(const std::u8string& str, std::size_t pos, std::size_t count);
835  String(const char8_t* str, std::size_t count);
836  String(std::initializer_list<char8_t> chars);
837  String(std::u8string::const_iterator first, std::u8string::const_iterator last);
838 
839  explicit operator std::u8string() const;
840 
841  String& assign(std::size_t count, char8_t ch);
842  String& assign(const std::u8string& str);
843  String& assign(const std::u8string& str, std::size_t pos, std::size_t count = npos);
844  String& assign(std::u8string&& str);
845  String& assign(const char8_t* str, std::size_t count);
846  String& assign(const char8_t* str);
847  String& assign(std::initializer_list<char8_t> chars);
848  String& assign(std::u8string::const_iterator first, std::u8string::const_iterator last);
849 
850  String& insert(std::size_t index, std::size_t count, char8_t ch);
851  String& insert(std::size_t index, const std::u8string& str);
852  String& insert(std::size_t index, const std::u8string& str, std::size_t pos, std::size_t count = npos);
853  String& insert(std::size_t index, const char8_t* str, std::size_t count);
854  String& insert(std::size_t index, const char8_t* str);
855  iterator insert(const_iterator pos, char8_t ch);
856  iterator insert(const_iterator pos, std::size_t count, char8_t ch);
857  iterator insert(const_iterator pos, std::initializer_list<char8_t> chars);
858  iterator insert(const_iterator pos, std::u8string::const_iterator first, std::u8string::const_iterator last);
859 
860  String& append(std::size_t count, char8_t ch);
861  String& append(const std::u8string& str);
862  String& append(const std::u8string& str, std::size_t pos, std::size_t count = npos);
863  String& append(const char8_t* str, std::size_t count);
864  String& append(const char8_t* str);
865  String& append(std::initializer_list<char8_t> chars);
866  String& append(std::u8string::const_iterator first, std::u8string::const_iterator last);
867 
868  int compare(const std::u8string& str) const noexcept;
869  int compare(std::size_t pos1, std::size_t count1, const std::u8string& str) const;
870  int compare(std::size_t pos1, std::size_t count1, const std::u8string& str, std::size_t pos2, std::size_t count2 = npos) const;
871  int compare(const char8_t* s) const;
872  int compare(std::size_t pos1, std::size_t count1, const char8_t* s) const;
873  int compare(std::size_t pos1, std::size_t count1, const char8_t* s, std::size_t count2) const;
874 
875  String& replace(std::size_t pos, std::size_t count, const std::u8string& str);
876  String& replace(const_iterator first, const_iterator last, const std::u8string& str);
877  String& replace(std::size_t pos, std::size_t count, const std::u8string& str, std::size_t pos2, std::size_t count2 = npos);
878  String& replace(const_iterator first, const_iterator last, std::u8string::const_iterator first2, std::u8string::const_iterator last2);
879  String& replace(std::size_t pos, std::size_t count, const char8_t* cstr, std::size_t count2);
880  String& replace(const_iterator first, const_iterator last, const char8_t* cstr, std::size_t count2);
881  String& replace(std::size_t pos, std::size_t count, const char8_t* cstr);
882  String& replace(const_iterator first, const_iterator last, const char8_t* cstr);
883  String& replace(std::size_t pos, std::size_t count, std::size_t count2, char8_t ch);
884  String& replace(const_iterator first, const_iterator last, std::size_t count2, char8_t ch);
885  String& replace(const_iterator first, const_iterator last, std::initializer_list<char8_t> chars);
886 
887  void resize(std::size_t count, char8_t ch);
888 
889  std::size_t find(const std::u8string& str, std::size_t pos = 0) const noexcept;
890  std::size_t find(const char8_t* s, std::size_t pos, std::size_t count) const;
891  std::size_t find(const char8_t* s, std::size_t pos = 0) const;
892  std::size_t find(char8_t ch, std::size_t pos = 0) const noexcept;
893 
894  std::size_t find_first_of(const std::u8string& str, std::size_t pos = 0) const noexcept;
895  std::size_t find_first_of(const char8_t* s, std::size_t pos, std::size_t count) const;
896  std::size_t find_first_of(const char8_t* s, std::size_t pos = 0) const;
897  std::size_t find_first_of(char8_t ch, std::size_t pos = 0) const noexcept;
898 
899  std::size_t find_first_not_of(const std::u8string& str, std::size_t pos = 0) const noexcept;
900  std::size_t find_first_not_of(const char8_t* s, std::size_t pos, std::size_t count) const;
901  std::size_t find_first_not_of(const char8_t* s, std::size_t pos = 0) const;
902  std::size_t find_first_not_of(char8_t ch, std::size_t pos = 0) const noexcept;
903 
904  std::size_t rfind(const std::u8string& str, std::size_t pos = npos) const noexcept;
905  std::size_t rfind(const char8_t* s, std::size_t pos, std::size_t count) const;
906  std::size_t rfind(const char8_t* s, std::size_t pos = npos) const;
907  std::size_t rfind(char8_t ch, std::size_t pos = npos) const noexcept;
908 
909  std::size_t find_last_of(const std::u8string& str, std::size_t pos = npos) const noexcept;
910  std::size_t find_last_of(const char8_t* s, std::size_t pos, std::size_t count) const;
911  std::size_t find_last_of(const char8_t* s, std::size_t pos = npos) const;
912  std::size_t find_last_of(char8_t ch, std::size_t pos = npos) const noexcept;
913 
914  std::size_t find_last_not_of(const std::u8string& str, std::size_t pos = npos) const noexcept;
915  std::size_t find_last_not_of(const char8_t* s, std::size_t pos, std::size_t count) const;
916  std::size_t find_last_not_of(const char8_t* s, std::size_t pos = npos) const;
917  std::size_t find_last_not_of(char8_t ch, std::size_t pos = npos) const noexcept;
918 
919  //friend std::basic_ostream<char8_t>& operator<<(std::basic_ostream<char8_t>& os, const String& str);
920 #endif
921  };
922 
924 
925  inline bool operator==(const String& left, const String& right)
926  {
927  return left.m_string == right.m_string;
928  }
929 
930  inline bool operator!=(const String& left, const String& right)
931  {
932  return left.m_string != right.m_string;
933  }
934 
935  inline bool operator<(const String& left, const String& right)
936  {
937  return left.m_string < right.m_string;
938  }
939 
940  inline bool operator<=(const String& left, const String& right)
941  {
942  return left.m_string <= right.m_string;
943  }
944 
945  inline bool operator>(const String& left, const String& right)
946  {
947  return left.m_string > right.m_string;
948  }
949 
950  inline bool operator>=(const String& left, const String& right)
951  {
952  return left.m_string >= right.m_string;
953  }
954 
955  inline String operator+(const String& left, const String& right)
956  {
957  return String(left.m_string + right.m_string);
958  }
959  inline String operator+(String&& left, String&& right)
960  {
961  return String(std::move(left.m_string) + std::move(right.m_string));
962  }
963  inline String operator+(String&& left, const String& right)
964  {
965  return String(std::move(left.m_string) + right.m_string);
966  }
967  inline String operator+(const String& left, String&& right)
968  {
969  return String(left.m_string + std::move(right.m_string));
970  }
971 
972  TGUI_API std::basic_ostream<char>& operator<<(std::basic_ostream<char>& os, const String& str);
973  TGUI_API std::basic_ostream<wchar_t>& operator<<(std::basic_ostream<wchar_t>& os, const String& str);
974  //TGUI_API std::basic_ostream<char16_t>& operator<<(std::basic_ostream<char16_t>& os, const String& str);
975  //TGUI_API std::basic_ostream<char32_t>& operator<<(std::basic_ostream<char32_t>& os, const String& str);
976 
977 
978  // UTF-8 function are defined in the header so that they can be enabled/disabled based on
979  // the compiler settings without having to recompile TGUI with a different c++ standard.
980 #if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201811L)
981  inline String::String(const std::u8string& str) :
982  m_string(utf::convertUtf8toUtf32(str.begin(), str.end()))
983  {
984  }
985 
986  inline String::String(char8_t utfChar)
987  : m_string(1, static_cast<char32_t>(utfChar))
988  {
989  }
990 
991  inline String::String(const char8_t* str)
992  : String{utf::convertUtf8toUtf32(str, str + std::char_traits<char8_t>::length(str))}
993  {
994  }
995 
996  inline String::String(std::size_t count, char8_t ch)
997  : m_string(count, static_cast<char32_t>(ch))
998  {
999  }
1000 
1001  inline String::String(const std::u8string& str, std::size_t pos)
1002  : String{std::u8string(str, pos)}
1003  {
1004  }
1005 
1006  inline String::String(const std::u8string& str, std::size_t pos, std::size_t count)
1007  : String{std::u8string(str, pos, count)}
1008  {
1009  }
1010 
1011  inline String::String(const char8_t* str, std::size_t count)
1012  : String{std::u8string{str, count}}
1013  {
1014  }
1015 
1016  inline String::String(std::initializer_list<char8_t> chars)
1017  : String(std::u8string(chars.begin(), chars.end()))
1018  {
1019  }
1020 
1021  inline String::String(std::u8string::const_iterator first, std::u8string::const_iterator last)
1022  : String{std::u8string(first, last)}
1023  {
1024  }
1025 
1026  inline String::operator std::u8string() const
1027  {
1028  return toUtf8();
1029  }
1030 
1031  inline String& String::assign(std::size_t count, char8_t ch)
1032  {
1033  m_string.assign(count, static_cast<char32_t>(ch));
1034  return *this;
1035  }
1036 
1037  inline String& String::assign(const std::u8string& str)
1038  {
1039  return *this = str;
1040  }
1041 
1042  inline String& String::assign(const std::u8string& str, std::size_t pos, std::size_t count)
1043  {
1044  return *this = {str, pos, count};
1045  }
1046 
1047  inline String& String::assign(std::u8string&& str)
1048  {
1049  return *this = std::move(str);
1050  }
1051 
1052  inline String& String::assign(const char8_t* str, std::size_t count)
1053  {
1054  return *this = {str, count};
1055  }
1056 
1057  inline String& String::assign(const char8_t* str)
1058  {
1059  return *this = str;
1060  }
1061 
1062  inline String& String::assign(std::initializer_list<char8_t> chars)
1063  {
1064  return *this = chars;
1065  }
1066 
1067  inline String& String::assign(std::u8string::const_iterator first, std::u8string::const_iterator last)
1068  {
1069  return *this = {first, last};
1070  }
1071 
1072  inline String& String::insert(std::size_t index, std::size_t count, char8_t ch)
1073  {
1074  m_string.insert(index, count, static_cast<char32_t>(ch));
1075  return *this;
1076  }
1077 
1078  inline String& String::insert(std::size_t index, const std::u8string& str)
1079  {
1080  m_string.insert(index, String{str}.m_string);
1081  return *this;
1082  }
1083 
1084  inline String& String::insert(std::size_t index, const std::u8string& str, std::size_t pos, std::size_t count)
1085  {
1086  m_string.insert(index, String{str, pos, count}.m_string);
1087  return *this;
1088  }
1089 
1090  inline String& String::insert(std::size_t index, const char8_t* str, std::size_t count)
1091  {
1092  m_string.insert(index, String{str, count}.m_string);
1093  return *this;
1094  }
1095 
1096  inline String& String::insert(std::size_t index, const char8_t* str)
1097  {
1098  m_string.insert(index, String{str}.m_string);
1099  return *this;
1100  }
1101 
1102  inline String::iterator String::insert(String::const_iterator pos, char8_t ch)
1103  {
1104  return m_string.insert(pos, static_cast<char32_t>(ch));
1105  }
1106 
1107  inline String::iterator String::insert(String::const_iterator pos, std::size_t count, char8_t ch)
1108  {
1109  return m_string.insert(pos, count, static_cast<char32_t>(ch));
1110  }
1111 
1112  inline String::iterator String::insert(String::const_iterator pos, std::initializer_list<char8_t> chars)
1113  {
1114  auto tmpStr = String{chars};
1115  return m_string.insert(pos, tmpStr.begin(), tmpStr.end());
1116  }
1117 
1118  inline String::iterator String::insert(String::const_iterator pos, std::u8string::const_iterator first, std::u8string::const_iterator last)
1119  {
1120  auto tmpStr = String{first, last};
1121  return m_string.insert(pos, tmpStr.begin(), tmpStr.end());
1122  }
1123 
1124  inline String& String::append(std::size_t count, char8_t ch)
1125  {
1126  return append(String(count, ch));
1127  }
1128 
1129  inline String& String::append(const std::u8string& str)
1130  {
1131  return append(String{str});
1132  }
1133 
1134  inline String& String::append(const std::u8string& str, std::size_t pos, std::size_t count)
1135  {
1136  return append(String{str, pos, count});
1137  }
1138 
1139  inline String& String::append(const char8_t* str, std::size_t count)
1140  {
1141  return append(String{str, count});
1142  }
1143 
1144  inline String& String::append(const char8_t* str)
1145  {
1146  return append(String{str});
1147  }
1148 
1149  inline String& String::append(std::initializer_list<char8_t> chars)
1150  {
1151  return append(String{chars});
1152  }
1153 
1154  inline String& String::append(std::u8string::const_iterator first, std::u8string::const_iterator last)
1155  {
1156  return append(String{first, last});
1157  }
1158 
1159  inline int String::compare(const std::u8string& str) const noexcept
1160  {
1161  return m_string.compare(String{str}.m_string);
1162  }
1163 
1164  inline int String::compare(std::size_t pos1, std::size_t count1, const std::u8string& str) const
1165  {
1166  return m_string.compare(pos1, count1, String{str}.m_string);
1167  }
1168 
1169  inline int String::compare(std::size_t pos1, std::size_t count1, const std::u8string& str, std::size_t pos2, std::size_t count2) const
1170  {
1171  return m_string.compare(pos1, count1, String{str, pos2, count2}.m_string);
1172  }
1173 
1174  inline int String::compare(const char8_t* s) const
1175  {
1176  return m_string.compare(String{s}.m_string);
1177  }
1178 
1179  inline int String::compare(std::size_t pos1, std::size_t count1, const char8_t* s) const
1180  {
1181  return m_string.compare(pos1, count1, String{s}.m_string);
1182  }
1183 
1184  inline int String::compare(std::size_t pos1, std::size_t count1, const char8_t* s, std::size_t count2) const
1185  {
1186  return m_string.compare(pos1, count1, String{s, count2}.m_string);
1187  }
1188 
1189  inline String& String::replace(std::size_t pos, std::size_t count, const std::u8string& str)
1190  {
1191  m_string.replace(pos, count, String{str}.m_string);
1192  return *this;
1193  }
1194 
1195  inline String& String::replace(const_iterator first, const_iterator last, const std::u8string& str)
1196  {
1197  m_string.replace(first, last, String{str}.m_string);
1198  return *this;
1199  }
1200 
1201  inline String& String::replace(std::size_t pos, std::size_t count, const std::u8string& str, std::size_t pos2, std::size_t count2)
1202  {
1203  m_string.replace(pos, count, String{str, pos2, count2}.m_string);
1204  return *this;
1205  }
1206 
1207  inline String& String::replace(const_iterator first, const_iterator last, std::u8string::const_iterator first2, std::u8string::const_iterator last2)
1208  {
1209  m_string.replace(first, last, String{first2, last2}.m_string);
1210  return *this;
1211  }
1212 
1213  inline String& String::replace(std::size_t pos, std::size_t count, const char8_t* cstr, std::size_t count2)
1214  {
1215  m_string.replace(pos, count, String{cstr, count2}.m_string);
1216  return *this;
1217  }
1218 
1219  inline String& String::replace(const_iterator first, const_iterator last, const char8_t* cstr, std::size_t count2)
1220  {
1221  m_string.replace(first, last, String{cstr, count2}.m_string);
1222  return *this;
1223  }
1224 
1225  inline String& String::replace(std::size_t pos, std::size_t count, const char8_t* cstr)
1226  {
1227  m_string.replace(pos, count, String{cstr}.m_string);
1228  return *this;
1229  }
1230 
1231  inline String& String::replace(const_iterator first, const_iterator last, const char8_t* cstr)
1232  {
1233  m_string.replace(first, last, String{cstr}.m_string);
1234  return *this;
1235  }
1236 
1237  inline String& String::replace(std::size_t pos, std::size_t count, std::size_t count2, char8_t ch)
1238  {
1239  m_string.replace(pos, count, String(count2, ch).m_string);
1240  return *this;
1241  }
1242 
1243  inline String& String::replace(const_iterator first, const_iterator last, std::size_t count2, char8_t ch)
1244  {
1245  m_string.replace(first, last, String(count2, ch).m_string);
1246  return *this;
1247  }
1248 
1249  inline String& String::replace(const_iterator first, const_iterator last, std::initializer_list<char8_t> chars)
1250  {
1251  m_string.replace(first, last, String{chars}.m_string);
1252  return *this;
1253  }
1254 
1255  inline void String::resize(std::size_t count, char8_t ch)
1256  {
1257  m_string.resize(count, static_cast<char32_t>(ch));
1258  }
1259 
1260  inline std::size_t String::find(const std::u8string& str, std::size_t pos) const noexcept
1261  {
1262  return m_string.find(String{str}.m_string, pos);
1263  }
1264 
1265  inline std::size_t String::find(const char8_t* s, std::size_t pos, std::size_t count) const
1266  {
1267  return m_string.find(String{s, count}.m_string, pos);
1268  }
1269 
1270  inline std::size_t String::find(const char8_t* s, std::size_t pos) const
1271  {
1272  return m_string.find(String{s}.m_string, pos);
1273  }
1274 
1275  inline std::size_t String::find(char8_t ch, std::size_t pos) const noexcept
1276  {
1277  return m_string.find(static_cast<char32_t>(ch), pos);
1278  }
1279 
1280  inline std::size_t String::find_first_of(const std::u8string& str, std::size_t pos) const noexcept
1281  {
1282  return m_string.find_first_of(String{str}.m_string, pos);
1283  }
1284 
1285  inline std::size_t String::find_first_of(const char8_t* s, std::size_t pos, std::size_t count) const
1286  {
1287  return m_string.find_first_of(String{s, count}.m_string, pos);
1288  }
1289 
1290  inline std::size_t String::find_first_of(const char8_t* s, std::size_t pos) const
1291  {
1292  return m_string.find_first_of(String{s}.m_string, pos);
1293  }
1294 
1295  inline std::size_t String::find_first_of(char8_t ch, std::size_t pos) const noexcept
1296  {
1297  return m_string.find_first_of(static_cast<char32_t>(ch), pos);
1298  }
1299 
1300  inline std::size_t String::find_first_not_of(const std::u8string& str, std::size_t pos) const noexcept
1301  {
1302  return m_string.find_first_not_of(String{str}.m_string, pos);
1303  }
1304 
1305  inline std::size_t String::find_first_not_of(const char8_t* s, std::size_t pos, std::size_t count) const
1306  {
1307  return m_string.find_first_not_of(String{s, count}.m_string, pos);
1308  }
1309 
1310  inline std::size_t String::find_first_not_of(const char8_t* s, std::size_t pos) const
1311  {
1312  return m_string.find_first_not_of(String{s}.m_string, pos);
1313  }
1314 
1315  inline std::size_t String::find_first_not_of(char8_t ch, std::size_t pos) const noexcept
1316  {
1317  return m_string.find_first_not_of(static_cast<char32_t>(ch), pos);
1318  }
1319 
1320  inline std::size_t String::rfind(const std::u8string& str, std::size_t pos) const noexcept
1321  {
1322  return m_string.rfind(String{str}.m_string, pos);
1323  }
1324 
1325  inline std::size_t String::rfind(const char8_t* s, std::size_t pos, std::size_t count) const
1326  {
1327  return m_string.rfind(String{s, count}.m_string, pos);
1328  }
1329 
1330  inline std::size_t String::rfind(const char8_t* s, std::size_t pos) const
1331  {
1332  return m_string.rfind(String{s}.m_string, pos);
1333  }
1334 
1335  inline std::size_t String::rfind(char8_t ch, std::size_t pos) const noexcept
1336  {
1337  return m_string.rfind(static_cast<char32_t>(ch), pos);
1338  }
1339 
1340  inline std::size_t String::find_last_of(const std::u8string& str, std::size_t pos) const noexcept
1341  {
1342  return m_string.find_last_of(String{str}.m_string, pos);
1343  }
1344 
1345  inline std::size_t String::find_last_of(const char8_t* s, std::size_t pos, std::size_t count) const
1346  {
1347  return m_string.find_last_of(String{s, count}.m_string, pos);
1348  }
1349 
1350  inline std::size_t String::find_last_of(const char8_t* s, std::size_t pos) const
1351  {
1352  return m_string.find_last_of(String{s}.m_string, pos);
1353  }
1354 
1355  inline std::size_t String::find_last_of(char8_t ch, std::size_t pos) const noexcept
1356  {
1357  return m_string.find_last_of(static_cast<char32_t>(ch), pos);
1358  }
1359 
1360  inline std::size_t String::find_last_not_of(const std::u8string& str, std::size_t pos) const noexcept
1361  {
1362  return m_string.find_last_not_of(String{str}.m_string, pos);
1363  }
1364 
1365  inline std::size_t String::find_last_not_of(const char8_t* s, std::size_t pos, std::size_t count) const
1366  {
1367  return m_string.find_last_not_of(String{s, count}.m_string, pos);
1368  }
1369 
1370  inline std::size_t String::find_last_not_of(const char8_t* s, std::size_t pos) const
1371  {
1372  return m_string.find_last_not_of(String{s}.m_string, pos);
1373  }
1374 
1375  inline std::size_t String::find_last_not_of(char8_t ch, std::size_t pos) const noexcept
1376  {
1377  return m_string.find_last_not_of(static_cast<char8_t>(ch), pos);
1378  }
1379 
1380  // Doesn't compile with libc++
1381  //inline std::basic_ostream<char8_t>& operator<<(std::basic_ostream<char8_t>& os, const String& str)
1382  //{
1383  // os << std::u8string(str);
1384  // return os;
1385  //}
1386 #endif
1387 
1389 }
1390 
1392 
1393 #endif // TGUI_STRING_HPP
Wrapper class to store strings.
Definition: String.hpp:74
bool attemptToFloat(float &result) const
Converts the string to a float.
float toFloat(float defaultValue=0) const
Converts the string to a float.
static String fromNumberRounded(T value, int decimals)
Construct the string from a floating point number, keeping only a certain amount of decimals behind t...
Definition: String.hpp:262
bool equalIgnoreCase(const String &other) const
Compares this string to another and checks if they are equal if ASCII letters would have been lowerca...
bool startsWith(const String &substring) const
Checks whether the first part of the string matches the given substring.
static String fromNumber(T value)
Construct the string from a number.
Definition: String.hpp:244
String & replace(const String &searchFor, const String &replaceWith)
Replaces all occurrences of a substring with a replacement string.
static String join(const std::vector< String > &segments, const String &separator)
Joins multiple string segments into a single string.
bool endsWith(const String &substring) const
Checks whether the last part of the string matches the given substring.
bool attemptToUInt(unsigned int &result) const
Converts the string to an unsigned int.
String trim() const
Returns a string with the whitespace at the start and end of this string removed.
unsigned int toUInt(unsigned int defaultValue=0) const
Converts the string to an unsigned int.
int toInt(int defaultValue=0) const
Converts the string to an integer.
String toLower() const
Converts the ASCII characters in the string to lowercase.
std::vector< String > split(char32_t delimiter) const
Splits the string into multiple substrings given the delimiter that separates them.
bool attemptToInt(int &result) const
Converts the string to an integer.
String toUpper() const
Converts the ASCII characters in the string to uppercase.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_API bool isWhitespace(char character)
Checks if a character is a whitespace character (space, tab, carriage return or line feed)