xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
ustring.h
Go to the documentation of this file.
1 #pragma once
4 
6 #define __XTD_CORE_INTERNAL__
7 #include "internal/__generic_stream_output.h"
8 #include "internal/__format_information.h"
9 #include "internal/__format_stringer.h"
10 #include "internal/__sprintf.h"
11 #undef __XTD_CORE_INTERNAL__
12 
14 #include <string>
15 #include "string_comparison.h"
16 #include "string_split_options.h"
17 #include "types.h"
18 #include "object.h"
19 #include "parse.h"
20 #include "to_string.h"
21 
22 #if !defined(_WIN32)
23 #include <cxxabi.h>
24 #endif
25 
27 namespace xtd {
28  class ustring;
29 }
30 template<typename ...args_t>
31 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& format, args_t&&... args);
32 void __throw_ustring_format_exception();
33 void __throw_ustring_format_exception_close_bracket();
34 void __throw_ustring_format_exception_open_bracket();
35 void __throw_ustring_format_exception_start_colon();
37 
38 namespace xtd {
48  class ustring : public object, public std::basic_string<char> {
49  public:
51  ustring() noexcept;
54  explicit ustring(const allocator_type& allocator) noexcept;
55 
60  ustring(size_t count, value_type character);
66  ustring(size_t count, value_type character, const allocator_type& allocator);
71  ustring(size_t count, char8_t character);
77  ustring(size_t count, char8_t character, const allocator_type& allocator);
82  ustring(size_t count, char16_t character);
88  ustring(size_t count, char16_t character, const allocator_type& allocator);
93  ustring(size_t count, char32_t character);
99  ustring(size_t count, char32_t character, const allocator_type& allocator);
104  ustring(size_t count, wchar_t character);
110  ustring(size_t count, wchar_t character, const allocator_type& allocator);
111 
116  ustring(const ustring& str, size_t index, size_t count);
122  ustring(const ustring& str, size_t index, size_t count, const allocator_type& allocator);
126  ustring(const ustring& str, size_t index);
131  ustring(const ustring& str, size_t index, const allocator_type& allocator);
132 
135  ustring(const value_type* str, size_t count);
140  ustring(const value_type* str, size_t count, const allocator_type& allocator);
141 
143  ustring(const value_type* str);
147  ustring(const value_type* str, const allocator_type& allocator);
148 
150  ustring(value_type* str);
154  ustring(value_type* str, const allocator_type& allocator);
155 
158  ustring(const ustring& str) noexcept;
162  ustring(const ustring& str, const allocator_type& allocator) noexcept;
163 
166  ustring(const std::string& str) noexcept;
170  ustring(const std::string& str, const allocator_type& allocator) noexcept;
171 
174  ustring(const std::u8string& str) noexcept;
178  ustring(const std::u8string& str, const allocator_type& allocator) noexcept;
179 
181  ustring(const char8_t* str);
185  ustring(const char8_t* str, const allocator_type& allocator);
186 
188  ustring(char8_t* str);
192  ustring(char8_t* str, const allocator_type& allocator);
193 
196  ustring(const std::u16string& str) noexcept;
200  ustring(const std::u16string& str, const allocator_type& allocator) noexcept;
201 
203  ustring(const char16_t* str);
207  ustring(const char16_t* str, const allocator_type& allocator);
208 
210  ustring(char16_t* str);
214  ustring(char16_t* str, const allocator_type& allocator);
215 
218  ustring(const std::u32string& str) noexcept;
222  ustring(const std::u32string& str, const allocator_type& allocator) noexcept;
223 
225  ustring(const char32_t* str);
229  ustring(const char32_t* str, const allocator_type& allocator);
230 
232  ustring(char32_t* str);
236  ustring(char32_t* str, const allocator_type& allocator);
237 
240  ustring(const std::wstring& str) noexcept;
244  ustring(const std::wstring& str, const allocator_type& allocator) noexcept;
245 
247  ustring(const wchar_t* str);
251  ustring(const wchar_t* str, const allocator_type& allocator);
252 
254  ustring(wchar_t* str);
258  ustring(wchar_t* str, const allocator_type& allocator);
259 
262  ustring(ustring&& str) noexcept;
266  ustring(ustring&& str, const allocator_type& allocator) noexcept;
267 
271  template<typename input_iterator_t>
272  ustring(input_iterator_t first, input_iterator_t last) : std::basic_string<value_type>(first, last) {}
277  template<typename input_iterator_t>
278  ustring(input_iterator_t first, input_iterator_t last, const allocator_type& allocator) : std::basic_string<value_type>(first, last, allocator) {}
279 
282  ustring(std::initializer_list<value_type> il);
286  ustring(std::initializer_list<value_type> il, const allocator_type& allocator);
287 
290  ustring(std::initializer_list<char8_t> il);
294  ustring(std::initializer_list<char8_t> il, const allocator_type& allocator);
295 
298  ustring(std::initializer_list<char16_t> il);
302  ustring(std::initializer_list<char16_t> il, const allocator_type& allocator);
303 
306  ustring(std::initializer_list<char32_t> il);
310  ustring(std::initializer_list<char32_t> il, const allocator_type& allocator);
311 
314  ustring(std::initializer_list<wchar_t> il);
318  ustring(std::initializer_list<wchar_t> il, const allocator_type& allocator);
319 
321  /*
322  template<typename type_t>
323  ustring(const type_t& object) : std::basic_string<value_type>(object) {}
324  template<typename type_t>
325  ustring(const type_t& object, const allocator_type& allocator) : std::basic_string<value_type>(object, allocator) {}
326  template<typename type_t>
327  ustring(const type_t& object, size_t index, size_t count) : std::basic_string<value_type>(object, index, count) {}
328  template<typename type_t>
329  ustring(const type_t& object, size_t index, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, index, count, allocator) {}
330  template<typename type_t>
331  ustring(const type_t& object, size_t count) : std::basic_string<value_type>(object, 0, count) {}
332  template<typename type_t>
333  ustring(const type_t& object, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, 0, count, allocator) {}
334  */
335 
336  ustring& operator=(const ustring& str);
337  ustring& operator=(const std::string& str);
338  ustring& operator=(const value_type* str);
339  ustring& operator=(const std::u8string& str);
340  ustring& operator=(const char8_t* str);
341  ustring& operator=(const std::u16string& str);
342  ustring& operator=(const char16_t* str);
343  ustring& operator=(const std::u32string& str);
344  ustring& operator=(const char32_t* str);
345  ustring& operator=(const std::wstring& str);
346  ustring& operator=(const wchar_t* str);
347  ustring& operator=(ustring&& str) noexcept;
348 
349  ustring& operator=(value_type character);
350  ustring& operator=(char8_t character);
351  ustring& operator=(char16_t character);
352  ustring& operator=(char32_t character);
353  ustring& operator=(wchar_t character);
354  ustring& operator=(const std::initializer_list<value_type>& il);
355  ustring& operator=(const std::initializer_list<char8_t>& il);
356  ustring& operator=(const std::initializer_list<char16_t>& il);
357  ustring& operator=(const std::initializer_list<char32_t>& il);
358  ustring& operator=(const std::initializer_list<wchar_t>& il);
359  //template<typename type_t>
360  //ustring& operator=(const type_t& object) {return std::basic_string<value_type>::assign(object);}
361 
362  template<typename type_t>
363  ustring operator+(const type_t& object) const {
364  ustring result(*this);
365  result.append(object);
366  return result;
367  }
368 
369  ustring& operator+=(const ustring& str);
370  ustring& operator+=(const std::string& str);
371  ustring& operator+=(const value_type* str);
372  ustring& operator+=(const std::u8string& str);
373  ustring& operator+=(const char8_t* str);
374  ustring& operator+=(const std::u16string& str);
375  ustring& operator+=(const char16_t* str);
376  ustring& operator+=(const std::u32string& str);
377  ustring& operator+=(const char32_t* str);
378  ustring& operator+=(const std::wstring& str);
379  ustring& operator+=(const wchar_t* str);
380  ustring& operator+=(value_type character);
381  ustring& operator+=(char8_t character);
382  ustring& operator+=(char16_t character);
383  ustring& operator+=(char32_t character);
384  ustring& operator+=(wchar_t character);
385  ustring& operator+=(const std::initializer_list<value_type>& il);
386  ustring& operator+=(const std::initializer_list<char8_t>& il);
387  ustring& operator+=(const std::initializer_list<char16_t>& il);
388  ustring& operator+=(const std::initializer_list<char32_t>& il);
389  ustring& operator+=(const std::initializer_list<wchar_t>& il);
390  template<typename type_t>
391  ustring& operator+=(const type_t& object) {
392  *this = *this + ustring(object);
393  return *this;
394  }
395 
396  bool operator==(const ustring& other) const;
397  bool operator!=(const ustring& other) const;
398  bool operator==(const std::string other) const;
399  bool operator!=(const std::string other) const;
400  bool operator==(const value_type* other) const;
401  bool operator!=(const value_type* other) const;
402  bool operator==(const std::u8string other) const;
403  bool operator!=(const std::u8string other) const;
404  bool operator==(const char8_t* other) const;
405  bool operator!=(const char8_t* other) const;
406  bool operator==(const std::u16string other) const;
407  bool operator!=(const std::u16string other) const;
408  bool operator==(const char16_t* other) const;
409  bool operator!=(const char16_t* other) const;
410  bool operator==(const std::u32string other) const;
411  bool operator!=(const std::u32string other) const;
412  bool operator==(const char32_t* other) const;
413  bool operator!=(const char32_t* other) const;
414  bool operator==(const std::wstring other) const;
415  bool operator!=(const std::wstring other) const;
416  bool operator==(const wchar_t* other) const;
417  bool operator!=(const wchar_t* other) const;
418  const value_type& operator[](size_t index);
419  const value_type& operator[](size_t index) const;
420  ustring substr(size_type index = 0, size_type count = npos) const;
422 
426  template<typename object_t>
427  static ustring full_class_name() {return demangle(typeid(object_t).name());}
428 
432  template<typename object_t>
433  static ustring full_class_name(const object_t& object) {return demangle(typeid(object).name());}
434 
438  static ustring full_class_name(const std::type_info& info) {return demangle(info.name());}
439 
443  template<typename object_t>
444  static ustring class_name() {return get_class_name(full_class_name<object_t>());}
445 
449  template<typename object_t>
450  static ustring class_name(const object_t& object) {return get_class_name(full_class_name(object));}
451 
455  static ustring class_name(const std::type_info& info) {return get_class_name(full_class_name(info));}
456 
457  using std::basic_string<value_type>::compare;
467  static int compare(const ustring& str_a, const ustring& str_b) noexcept;
478  static int compare(const ustring& str_a, const ustring& str_b, bool ignore_case) noexcept;
479 
490  static int compare(const ustring& str_a, const ustring& str_b, xtd::string_comparison comparison_type) noexcept;
503  static int compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length) noexcept;
517  static int compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length, bool ignore_case) noexcept;
531  static int compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length, xtd::string_comparison comparison_type) noexcept;
532 
539  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c, const ustring& str_d) noexcept;
540 
547  template<typename object_a_t, typename object_b_t, typename object_c_t, typename object_d_t>
548  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c, object_d_t obj_d) noexcept {
549  return format("{}{}{}{}", obj_a, obj_b, obj_c, obj_d);
550  }
551 
557  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c) noexcept;
558 
564  template<typename object_a_t, typename object_b_t, typename object_c_t>
565  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c) noexcept {
566  return format("{}{}{}", obj_a, obj_b, obj_c);
567  }
568 
573  static ustring concat(const ustring& str_a, const ustring& str_b) noexcept;
574 
579  template<typename object_a_t, typename object_b_t>
580  static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept {
581  return format("{}{}", obj_a, obj_b);
582  }
583 
587  static ustring concat(const std::vector<ustring>& values) noexcept;
588 
590  static ustring concat(const std::vector<const value_type*>& values) noexcept;
591  static ustring concat(const std::vector<const char8_t*>& values) noexcept;
592  static ustring concat(const std::initializer_list<ustring>& values) noexcept;
593  static ustring concat(const std::initializer_list<const value_type*>& values) noexcept;
594  static ustring concat(const std::initializer_list<const char8_t*>& values) noexcept;
596 
600  template<typename object_t>
601  static ustring concat(const std::vector<object_t>& args) noexcept {
602  ustring result;
603  for (const auto& arg : args)
604  result += format("{}", arg);
605  return result;
606  }
607 
609  template<typename object_t>
610  static ustring concat(const std::initializer_list<object_t>& args) noexcept {
611  ustring result;
612  for (const auto& arg : args)
613  result += format("{}", arg);
614  return result;
615  }
617 
621  template<typename value_t>
622  static ustring concat(value_t value) noexcept {
623  return format("{}", value);
624  }
625 
628  static ustring demangle(const ustring& name) {
629 #if defined(_WIN32)
630  ustring result = name;
631  for (auto& item : {"enum ", "class ", "union ", "struct "})
632  result = result.replace(item, "");
633  return result;
634 #else
635  class auto_delete_char_pointer {
636  public:
637  auto_delete_char_pointer(char* value) : value_(value) {}
638  ~auto_delete_char_pointer() {free(value_);}
639  char* operator()() const {return value_;}
640  private:
641  char* value_;
642  };
643  int32_t status = 0;
644  return auto_delete_char_pointer(abi::__cxa_demangle(name.c_str(), 0, 0, &status))();
645 #endif
646  }
647 
651  bool contains(const ustring& value) const noexcept;
652 
655  static ustring empty_string() noexcept;
656 
660  bool ends_with(value_type value) const noexcept;
661 
665  bool ends_with(char8_t value) const noexcept;
666 
670  bool ends_with(const ustring& value) const noexcept;
671 
675  bool ends_with(const ustring& value, bool ignore_case) const noexcept;
676 
680  bool ends_with(const ustring& value, xtd::string_comparison comparison_type) const noexcept;
681 
688  template<typename ...args_t>
689  static ustring format(const ustring& fmt, args_t&&... args) {
690  ustring result;
691  size_t index = 0;
692  std::vector<__format_information<char>> formats;
693  typename ustring::const_iterator begin_format_iterator = fmt.cend();
694  typename ustring::const_iterator end_format_iterator = fmt.cend();
695  for (typename ustring::const_iterator iterator = fmt.cbegin(); iterator != fmt.cend(); ++iterator) {
696  if (*iterator == '{') {
697  ++iterator;
698  if (*iterator == '{')
699  result += *iterator;
700  else {
701  begin_format_iterator = iterator;
702  while (*iterator != '}' && iterator != fmt.end()) ++iterator;
703  if (iterator == fmt.end())
704  __throw_ustring_format_exception_open_bracket();
705  end_format_iterator = iterator;
706  __format_information<char> fi;
707  fi.location = result.size();
708  std::string format {begin_format_iterator, end_format_iterator};
709  if (format.size() == 0)
710  fi.index = index++;
711  else {
712  size_t index_alignment_separator = ustring(format).index_of(',');
713  size_t index_format_separator = ustring(format).index_of(u8':');
714 
715  if (index_alignment_separator != std::string::npos && index_format_separator != std::string::npos && index_alignment_separator > index_format_separator)
716  index_alignment_separator = std::string::npos;
717 
718  if (index_alignment_separator != std::string::npos)
719  fi.alignment = format.substr(index_alignment_separator + 1, index_format_separator != std::string::npos ? index_format_separator - index_alignment_separator - 1 : std::string::npos);
720 
721  if (index_format_separator != std::string::npos)
722  fi.format = format.substr(index_format_separator + 1);
723 
724  if (index_alignment_separator == 0 || index_format_separator == 0)
725  fi.index = index++;
726  else {
727  std::string index_str;
728  if (index_alignment_separator != std::string::npos)
729  index_str = format.substr(0, index_alignment_separator);
730  else if (index_format_separator != std::string::npos)
731  index_str = format.substr(0, index_format_separator);
732  else
733  index_str = format;
734  try {
735  for (auto c : index_str)
736  if (!std::isdigit(c)) __throw_ustring_format_exception_start_colon();
737  fi.index = std::stoi(index_str);
738  } catch(...) {
739  __throw_ustring_format_exception_start_colon();
740  }
741  }
742  }
743  formats.push_back(fi);
744  }
745  } else if (*iterator == '}') {
746  if (++iterator == fmt.cend())
747  __throw_ustring_format_exception_close_bracket();
748  if (*iterator != '}')
749  __throw_ustring_format_exception_close_bracket();
750  result += *iterator;
751  } else
752  result += *iterator;
753  }
754 
755  __ustring_extract_format_arg(result, formats, std::forward<args_t>(args)...);
756  return result.c_str();
757  }
758 
761  size_t get_hash_code() const noexcept override;
762 
766  size_t index_of(value_type value) const noexcept;
767 
771  size_t index_of(const ustring& value) const noexcept;
772 
777  size_t index_of(value_type value, size_t start_index) const noexcept;
778 
783  size_t index_of(const ustring& value, size_t start_index) const noexcept;
784 
790  size_t index_of(value_type value, size_t start_index, size_t count) const noexcept;
791 
797  size_t index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
798 
802  size_t index_of_any(const std::vector<value_type>& values) const noexcept;
803 
808  size_t index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
809 
815  size_t index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
816 
818  size_t index_of_any(const std::initializer_list<value_type>& values) const noexcept;
819  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
820  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
822 
829  ustring insert(size_t start_index, const ustring& value) const noexcept;
830 
834  [[deprecated("Replaced by xtd::ustring::is_empty(const xtd::ustring&) - Will be removed in version 0.4.0")]]
835  bool is_empty() const noexcept {return is_empty(*this);}
836 
840  static bool is_empty(const xtd::ustring& string) noexcept;
841 
848  template<typename collection_t>
849  static ustring join(const ustring separator, const collection_t& values) noexcept {return join(separator, values, 0, values.size());}
850 
858  template<typename collection_t>
859  static ustring join(const ustring& separator, const collection_t& values, size_t index) noexcept {return join(separator, values, index, values.size()-index);}
860 
869  template<typename collection_t>
870  static ustring join(const ustring& separator, const collection_t& values, size_t index, size_t count) noexcept {
871  size_t i = 0;
872  ustring result;
873  for (const auto& item : values) {
874  if (i >= index) {
875  if (i != index) result += separator;
876  result += format("{}", item);
877  }
878  if (++i >= index + count) break;
879  }
880  return result;
881  }
882 
884  template<typename value_t>
885  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values) noexcept {return join(separator, std::vector<value_t>(values));}
886  template<typename value_t>
887  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values, size_t index) noexcept {return join(separator, std::vector<value_t>(values), index);}
888  template<typename value_t>
889  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values, size_t index, size_t count) noexcept {return join(separator, std::vector<value_t>(values), index, count);}
891 
895  size_t last_index_of(value_type value) const noexcept;
896 
900  size_t last_index_of(const ustring& value) const noexcept;
901 
906  size_t last_index_of(value_type value, size_t start_index) const noexcept;
907 
912  size_t last_index_of(const ustring& value, size_t start_index) const noexcept;
913 
920  size_t last_index_of(value_type value, size_t start_index, size_t count) const noexcept;
921 
927  size_t last_index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
928 
932  size_t last_index_of_any(const std::vector<value_type>& values) const noexcept;
933 
938  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
939 
945  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
946 
948  size_t last_index_of_any(const std::initializer_list<value_type>& values) const noexcept;
949  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
950  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
952 
958  ustring pad_left(size_t total_width) const noexcept;
959 
966  ustring pad_left(size_t total_width, value_type padding_char) const noexcept;
967 
973  ustring pad_right(size_t total_width) const noexcept;
974 
981  ustring pad_right(size_t total_width, value_type padding_char) const noexcept;
982 
986  ustring remove(size_t start_index) const noexcept;
987 
992  ustring remove(size_t start_index, size_t count) const noexcept;
993 
998  ustring replace(value_type old_char, value_type new_char) const noexcept;
999 
1005  ustring replace(const ustring& old_string, const ustring& new_string) const noexcept;
1006 
1018  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count, string_split_options options) const noexcept;
1019 
1024  std::vector<ustring> split() const noexcept;
1025 
1031  std::vector<ustring> split(const std::vector<value_type>& separators) const noexcept;
1032 
1049  std::vector<ustring> split(const std::vector<value_type>& separators, string_split_options options) const noexcept;
1050 
1059  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count) const noexcept;
1060 
1120  template<typename ... args_t>
1121  static ustring sprintf(const ustring& fmt, args_t&& ... args) noexcept {return __sprintf(fmt.c_str(), convert_param(std::forward<args_t>(args)) ...);}
1122 
1127  bool starts_with(value_type value) const noexcept;
1128 
1134  bool starts_with(value_type value, bool ignore_case) const noexcept;
1135 
1140  bool starts_with(const ustring& value) const noexcept;
1141 
1147  bool starts_with(const ustring& value, bool ignore_case) const noexcept;
1148 
1153  ustring substring(size_t start_index) const noexcept;
1154 
1159  ustring substring(size_t start_index, size_t length) const noexcept;
1160 
1163  std::vector<value_type> to_array() const noexcept;
1164 
1168  std::vector<value_type> to_array(size_t start_index) const noexcept;
1169 
1174  std::vector<value_type> to_array(size_t start_index, size_t length) const noexcept;
1175 
1178  ustring to_lower() const noexcept;
1179 
1180  //ustring to_string() const noexcept override;
1181  ustring to_string() const noexcept override;
1182 
1185  ustring to_upper() const noexcept;
1186 
1191  ustring trim() const noexcept;
1192 
1197  ustring trim(value_type trim_char) const noexcept;
1198 
1203  ustring trim(const std::vector<value_type>& trim_chars) const noexcept;
1204 
1209  ustring trim_end() const noexcept;
1210 
1215  ustring trim_end(value_type trim_char) const noexcept;
1216 
1221  ustring trim_end(const std::vector<value_type>& trim_chars) const noexcept;
1222 
1227  ustring trim_start() const noexcept;
1228 
1233  ustring trim_start(value_type trim_char) const noexcept;
1234 
1239  ustring trim_start(const std::vector<value_type>& trim_chars) const noexcept;
1240 
1241  template<typename value_t>
1242  static value_t parse(const ustring& str) {
1243  return xtd::parse<value_t>(str);
1244  }
1245 
1246  template<typename value_t>
1247  static bool try_parse(const ustring& str, value_t& value) {
1248  try {
1249  value = parse<value_t>(str);
1250  return true;
1251  } catch(...) {
1252  return false;
1253  }
1254  }
1255 
1257  friend std::ostream& operator<<(std::ostream& stream, const ustring& str) {return stream << str.c_str();}
1258  friend std::istream& operator>>(std::istream& stream, ustring& str) {
1259  std::string s;
1260  stream >> s;
1261  str = s;
1262  return stream;
1263  }
1264 
1265  friend ustring operator+(const ustring& str_a, const ustring& str_b) {
1266  ustring result = str_a;
1267  result.append(str_b);
1268  return result;
1269  }
1270 
1271  friend ustring operator+(const ustring& str_a, const std::string& str_b) {
1272  ustring result = str_a;
1273  result.append(ustring(str_b));
1274  return result;
1275  }
1276 
1277  friend ustring operator+(const ustring& str_a, const value_type* str_b) {
1278  ustring result = str_a;
1279  result.append(ustring(str_b));
1280  return result;
1281  }
1282 
1283  friend ustring operator+(const ustring& str_a, const std::u8string& str_b) {
1284  ustring result = str_a;
1285  result.append(ustring(str_b));
1286  return result;
1287  }
1288 
1289  friend ustring operator+(const ustring& str_a, const char8_t* str_b) {
1290  ustring result = str_a;
1291  result.append(ustring(str_b));
1292  return result;
1293  }
1294 
1295  friend ustring operator+(const ustring& str_a, const std::u16string& str_b) {
1296  ustring result = str_a;
1297  result.append(ustring(str_b));
1298  return result;
1299  }
1300 
1301  friend ustring operator+(const ustring& str_a, const char16_t* str_b) {
1302  ustring result = str_a;
1303  result.append(ustring(str_b));
1304  return result;
1305  }
1306 
1307  friend ustring operator+(const ustring& str_a, const std::u32string& str_b) {
1308  ustring result = str_a;
1309  result.append(ustring(str_b));
1310  return result;
1311  }
1312 
1313  friend ustring operator+(const ustring& str_a, const char32_t* str_b) {
1314  ustring result = str_a;
1315  result.append(ustring(str_b));
1316  return result;
1317  }
1318 
1319  friend ustring operator+(const ustring& str_a, const std::wstring& str_b) {
1320  ustring result = str_a;
1321  result.append(ustring(str_b));
1322  return result;
1323  }
1324 
1325  friend ustring operator+(const ustring& str_a, const wchar_t* str_b) {
1326  ustring result = str_a;
1327  result.append(ustring(str_b));
1328  return result;
1329  }
1330 
1331  friend ustring operator+(const ustring& str_a, value_type character) {
1332  ustring result = str_a;
1333  result.append(ustring(1, character));
1334  return result;
1335  }
1336 
1337  friend ustring operator+(const ustring& str_a, char8_t character) {
1338  ustring result = str_a;
1339  result.append(ustring(1, character));
1340  return result;
1341  }
1342 
1343  friend ustring operator+(const ustring& str_a, char16_t character) {
1344  ustring result = str_a;
1345  result.append(ustring(1, character));
1346  return result;
1347  }
1348 
1349  friend ustring operator+(const ustring& str_a, char32_t character) {
1350  ustring result = str_a;
1351  result.append(ustring(1, character));
1352  return result;
1353  }
1354 
1355  friend ustring operator+(const ustring& str_a, wchar_t character) {
1356  ustring result = str_a;
1357  result.append(ustring(1, character));
1358  return result;
1359  }
1360 
1361  friend ustring operator+(const ustring& str_a, const std::initializer_list<value_type>& il) {
1362  ustring result = str_a;
1363  result.append(ustring(il));
1364  return result;
1365  }
1366 
1367  friend ustring operator+(const ustring& str_a, const std::initializer_list<char8_t>& il) {
1368  ustring result = str_a;
1369  result.append(ustring(il));
1370  return result;
1371  }
1372 
1373  friend ustring operator+(const ustring& str_a, const std::initializer_list<char16_t>& il) {
1374  ustring result = str_a;
1375  result.append(ustring(il));
1376  return result;
1377  }
1378 
1379  friend ustring operator+(const ustring& str_a, const std::initializer_list<char32_t>& il) {
1380  ustring result = str_a;
1381  result.append(ustring(il));
1382  return result;
1383  }
1384 
1385  friend ustring operator+(const ustring& str_a, const std::initializer_list<wchar_t>& il) {
1386  ustring result = str_a;
1387  result.append(ustring(il));
1388  return result;
1389  }
1390 
1391  friend ustring operator+(const std::string& str_a, const ustring& str_b) {
1392  ustring result(str_a);
1393  result.append(str_b);
1394  return result;
1395  }
1396 
1397  friend ustring operator+(const value_type* str_a, const ustring& str_b) {
1398  ustring result(str_a);
1399  result.append(str_b);
1400  return result;
1401  }
1402 
1403  friend ustring operator+(const std::u8string& str_a, const ustring& str_b) {
1404  ustring result(str_a);
1405  result.append(str_b);
1406  return result;
1407  }
1408 
1409  friend ustring operator+(const char8_t* str_a, const ustring& str_b) {
1410  ustring result(str_a);
1411  result.append(str_b);
1412  return result;
1413  }
1414 
1415  friend ustring operator+(const std::u16string& str_a, const ustring& str_b) {
1416  ustring result(str_a);
1417  result.append(str_b);
1418  return result;
1419  }
1420 
1421  friend ustring operator+(const char16_t* str_a, const ustring& str_b) {
1422  ustring result(str_a);
1423  result.append(str_b);
1424  return result;
1425  }
1426 
1427  friend ustring operator+(const std::u32string& str_a, const ustring& str_b) {
1428  ustring result(str_a);
1429  result.append(str_b);
1430  return result;
1431  }
1432 
1433  friend ustring operator+(const char32_t* str_a, const ustring& str_b) {
1434  ustring result(str_a);
1435  result.append(str_b);
1436  return result;
1437  }
1438 
1439  friend ustring operator+(const std::wstring& str_a, const ustring& str_b) {
1440  ustring result(str_a);
1441  result.append(str_b);
1442  return result;
1443  }
1444 
1445  friend ustring operator+(const wchar_t* str_a, const ustring& str_b) {
1446  ustring result(str_a);
1447  result.append(str_b);
1448  return result;
1449  }
1450 
1451  friend ustring operator+(value_type character, const ustring& str_b) {
1452  ustring result(1, character);
1453  result.append(str_b);
1454  return result;
1455  }
1456 
1457  friend ustring operator+(char8_t character, const ustring& str_b) {
1458  ustring result(1, character);
1459  result.append(str_b);
1460  return result;
1461  }
1462 
1463  friend ustring operator+(char16_t character, const ustring& str_b) {
1464  ustring result(1, character);
1465  result.append(str_b);
1466  return result;
1467  }
1468 
1469  friend ustring operator+(char32_t character, const ustring& str_b) {
1470  ustring result(1, character);
1471  result.append(str_b);
1472  return result;
1473  }
1474 
1475  friend ustring operator+(wchar_t character, const ustring& str_b) {
1476  ustring result(1, character);
1477  result.append(str_b);
1478  return result;
1479  }
1480 
1481  friend ustring operator+(const std::initializer_list<value_type>& il, const ustring& str_b) {
1482  ustring result(il);
1483  result.append(str_b);
1484  return result;
1485  }
1486 
1487  friend ustring operator+(const std::initializer_list<char8_t>& il, const ustring& str_b) {
1488  ustring result(il);
1489  result.append(str_b);
1490  return result;
1491  }
1492 
1493  friend ustring operator+(const std::initializer_list<char16_t>& il, const ustring& str_b) {
1494  ustring result(il);
1495  result.append(str_b);
1496  return result;
1497  }
1498 
1499  friend ustring operator+(const std::initializer_list<char32_t>& il, const ustring& str_b) {
1500  ustring result(il);
1501  result.append(str_b);
1502  return result;
1503  }
1504 
1505  friend ustring operator+(const std::initializer_list<wchar_t>& il, const ustring& str_b) {
1506  ustring result(il);
1507  result.append(str_b);
1508  return result;
1509  }
1511 
1512  private:
1513  template<typename arg_t>
1514  static auto convert_param(arg_t&& arg) noexcept {
1515  if constexpr (std::is_same<std::remove_cv_t<std::remove_reference_t<arg_t>>, std::string>::value) return std::forward<arg_t>(arg).c_str();
1516  else if constexpr (std::is_same<std::remove_cv_t<std::remove_reference_t<arg_t>>, std::wstring>::value) return std::forward<arg_t>(arg).c_str();
1517  else return std::forward<arg_t>(arg);
1518  }
1519 
1520  static ustring get_class_name(const ustring& full_name);
1521 
1522  using std::basic_string<value_type>::assign;
1523  using std::basic_string<value_type>::reserve;
1524  using std::basic_string<value_type>::shrink_to_fit;
1525  using std::basic_string<value_type>::clear;
1526  using std::basic_string<value_type>::erase;
1527  using std::basic_string<value_type>::push_back;
1528  using std::basic_string<value_type>::pop_back;
1529  using std::basic_string<value_type>::append;
1530  using std::basic_string<value_type>::replace;
1531  using std::basic_string<value_type>::resize;
1532  };
1533 
1537  ustring to_ustring(int val);
1541  ustring to_ustring(unsigned val);
1545  ustring to_ustring(long val);
1549  ustring to_ustring(unsigned long val);
1553  ustring to_ustring(long long val);
1557  ustring to_ustring(unsigned long long val);
1561  ustring to_ustring(float val);
1565  ustring to_ustring(double val);
1569  ustring to_ustring(long double val);
1573  template <typename type_t>
1574  ustring to_ustring(type_t val) {
1575  return ustring::format("{}", val);
1576  }
1577 }
1578 
1580 template<typename arg_t>
1581 void __ustring_extract_format_arg(std::string& fmt, size_t& index, std::vector<__format_information<char>>& formats, arg_t&& arg) {
1582  size_t offset = 0;
1583  for (auto& format : formats) {
1584  format.location += offset;
1585  if (format.index == index) {
1586  xtd::ustring arg_str = format.format.empty() ? __format_stringer<char, arg_t>(arg) : xtd::to_string(arg, format.format);
1587 
1588  if (!format.alignment.empty()) {
1589  int alignment = 0;
1590  try {
1591  alignment = std::stoi(format.alignment);
1592  } catch(...) {
1593  __throw_ustring_format_exception();
1594  }
1595  if (alignment > 0) arg_str = arg_str.pad_left(alignment);
1596  else if (alignment < 0) arg_str = arg_str.pad_right(-alignment);
1597  }
1598  fmt.insert(format.location, arg_str);
1599  offset += arg_str.size();
1600  }
1601  }
1602  ++index;
1603 }
1604 
1605 template <typename ...args_t>
1606 void __xtd_ustrings_unused(args_t&& ... args) {}
1607 
1608 template<typename ...args_t>
1609 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& formats, args_t&&... args) {
1610  size_t index = 0;
1611  (__ustring_extract_format_arg(fmt, index, formats, args),...);
1612  __xtd_ustrings_unused(index); // workaround to mute gcc warning: unused-but-set-variable
1613 }
size_t last_index_of(value_type value) const noexcept
Reports the index of the last occurrence of the specified character in this tring.
Contains xtd fundamental types.
static ustring full_class_name(const object_t &object)
Gets the fully qualified class name of the specified object, including the namespace of the specified...
Definition: ustring.h:433
ustring trim_start() const noexcept
Removes all leading occurrences of white-space characters from the specified String.
value_t parse(const std::string &str)
Convert a type into a string.
Definition: parse.h:22
ustring trim_end() const noexcept
Removes all trailing occurrences of white-space characters from the specified String.
size_t index_of(value_type value) const noexcept
Reports the index of the first occurrence of the specified character in this string.
static ustring concat(const std::vector< object_t > &args) noexcept
Concatenates the string representations of the elements in a specified object array.
Definition: ustring.h:601
Contains xtd::parse methods.
string_split_options
Specifies whether applicable xtd::ustring::split method overloads include or omit empty substrings fr...
Definition: string_split_options.h:17
ustring pad_right(size_t total_width) const noexcept
Left-aligns the characters in this string, padding with spaces on the right for a specified total len...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
ustring replace(value_type old_char, value_type new_char) const noexcept
Replaces all occurrences of a specified char_t in this string with another specified char_t...
size_type
Specifies how rows or columns of user interface (UI) elements should be sized relative to their conta...
Definition: size_type.h:18
bool try_parse(const std::basic_string< char_t > &str, value_t &value)
Convert a type into a string.
Definition: parse.h:354
static ustring join(const ustring &separator, const collection_t &values, size_t index, size_t count) noexcept
Concatenates a specified separator string between each element of a specified Object array...
Definition: ustring.h:870
ustring(input_iterator_t first, input_iterator_t last, const allocator_type &allocator)
Initializes a new instance of xtd::ustring with specified first and last iterators of substring and a...
Definition: ustring.h:278
string_comparison
Specifies the culture, case, and sort rules to be used by certain overloads of the xtd::ustring::comp...
Definition: string_comparison.h:17
static int compare(const ustring &str_a, const ustring &str_b) noexcept
Compares two specified string objects and returns an integer that indicates their relative position i...
static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept
Concatenates two specified instances of object.
Definition: ustring.h:580
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::to_string methods.
ustring() noexcept
Initializes a new instance of xtd::ustring.
bool ends_with(value_type value) const noexcept
Determines whether the end of this string matches the specified character.
ustring substring(size_t start_index) const noexcept
Retrieves a substring from this instance. The substring starts at a specified character position and ...
bool contains(const ustring &value) const noexcept
Returns a value indicating whether a specified substring occurs within this string.
static ustring class_name(const std::type_info &info)
Gets the class name of the specified object.
Definition: ustring.h:455
ustring trim() const noexcept
Removes all leading and trailing occurrences of white-space characters from the specified String...
size_t index_of_any(const std::vector< value_type > &values) const noexcept
Reports the index of the first occurrence in this instance of any character in a specified array of c...
static ustring sprintf(const ustring &fmt, args_t &&... args) noexcept
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:1121
ustring to_lower() const noexcept
Returns a copy of the current string converted to lowercase.
static ustring class_name(const object_t &object)
Gets the class name of the specified object.
Definition: ustring.h:450
static ustring concat(const ustring &str_a, const ustring &str_b, const ustring &str_c, const ustring &str_d) noexcept
Concatenates four specified instances of string.
ustring pad_left(size_t total_width) const noexcept
Right-aligns the characters in this string, padding with spaces on the left for a specified total len...
static ustring full_class_name(const std::type_info &info)
Gets the fully qualified class name of the specified object, including the namespace of the specified...
Definition: ustring.h:438
size_t get_hash_code() const noexcept override
Returns the hash code for this string.
ustring insert(size_t start_index, const ustring &value) const noexcept
Inserts a specified instance of string at a specified index position in this instance.
bool is_empty() const noexcept
Indicates whether this string is an empty string ("").
Definition: ustring.h:835
std::vector< ustring > split() const noexcept
Splits this string into substrings that are based on the default white-space characters. White-space characters are defined by the c++ standard and return true if they are passed to the std::isspace() or std::iswspace() method.
ustring(input_iterator_t first, input_iterator_t last)
Initializes a new instance of xtd::ustring with specified first and last iterators of substring...
Definition: ustring.h:272
static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c) noexcept
Concatenates three specified instances of object.
Definition: ustring.h:565
ustring to_upper() const noexcept
Returns a copy of the current string converted to uppercase.
The Separator key.
static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c, object_d_t obj_d) noexcept
Concatenates four specified instances of object.
Definition: ustring.h:548
bool starts_with(value_type value) const noexcept
Determines whether the beginning of this instance of String matches a specified String.
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
Contains xtd::string_split_options enum class.
static ustring class_name()
Gets the class name of the object_t.
Definition: ustring.h:444
size_t last_index_of_any(const std::vector< value_type > &values) const noexcept
Reports the index of the last occurrence in this instance of any character in a specified array of ch...
static ustring full_class_name()
Gets the fully qualified class name of the objec_t, including the namespace of the objec_t...
Definition: ustring.h:427
static ustring join(const ustring &separator, const collection_t &values, size_t index) noexcept
Concatenates a specified separator string between each element of a specified object array...
Definition: ustring.h:859
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
std::vector< value_type > to_array() const noexcept
Copies the characters in this instance to a Unicode character array.
ustring to_string() const noexcept override
Returns a std::string that represents the current object.
ustring to_ustring(int val)
Converts a signed integer to xtd::ustring.
static ustring concat(value_t value) noexcept
Creates the string representation of a specified object.
Definition: ustring.h:622
Contains xtd::string_comparison enum class.
static ustring join(const ustring separator, const collection_t &values) noexcept
Concatenates a specified separator string between each element of a specified object array...
Definition: ustring.h:849
static ustring demangle(const ustring &name)
Gets demangled string of name,.
Definition: ustring.h:628
static ustring empty_string() noexcept
Represents the empty string.
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37