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