xtd - Reference Guide 0.2.0
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 <ostream>
15 #include <string>
16 #include "icomparable.h"
17 #include "iequatable.h"
18 #include "string_comparison.h"
19 #include "string_split_options.h"
20 #include "types.h"
21 #include "object.h"
22 #include "parse.h"
23 #include "to_string.h"
24 #include "types.h"
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 xtd::icomparable<ustring>, public std::basic_string<char> {
49  public:
51 
55  static const ustring empty_string;
57 
59 
62  ustring() noexcept;
65  explicit ustring(const allocator_type& allocator) noexcept;
66 
71  ustring(size_t count, value_type character);
77  ustring(size_t count, value_type character, const allocator_type& allocator);
82  ustring(size_t count, char8 character);
88  ustring(size_t count, char8 character, const allocator_type& allocator);
93  ustring(size_t count, char16 character);
99  ustring(size_t count, char16 character, const allocator_type& allocator);
104  ustring(size_t count, char32 character);
110  ustring(size_t count, char32 character, const allocator_type& allocator);
115  ustring(size_t count, wchar character);
121  ustring(size_t count, wchar character, const allocator_type& allocator);
122 
127  ustring(const ustring& str, size_t index, size_t count);
133  ustring(const ustring& str, size_t index, size_t count, const allocator_type& allocator);
137  ustring(const ustring& str, size_t index);
142  ustring(const ustring& str, size_t index, const allocator_type& allocator);
143 
146  ustring(const value_type* str, size_t count);
151  ustring(const value_type* str, size_t count, const allocator_type& allocator);
152 
154  ustring(const value_type* str); // Can't be explicit by design.
158  ustring(const value_type* str, const allocator_type& allocator);
159 
161  ustring(value_type* str); // Can't be explicit by design.
165  ustring(value_type* str, const allocator_type& allocator);
166 
169  ustring(const ustring& str) noexcept;
173  ustring(const ustring& str, const allocator_type& allocator) noexcept;
174 
177  ustring(const std::string& str) noexcept; // Can't be explicit by design.
181  ustring(const std::string& str, const allocator_type& allocator) noexcept;
182 
185  ustring(const std::u8string& str) noexcept; // Can't be explicit by design.
189  ustring(const std::u8string& str, const allocator_type& allocator) noexcept;
190 
192  ustring(const char8* str); // Can't be explicit by design.
196  ustring(const char8* str, const allocator_type& allocator);
197 
199  ustring(char8* str); // Can't be explicit by design.
203  ustring(char8* str, const allocator_type& allocator);
204 
207  ustring(const std::u16string& str) noexcept; // Can't be explicit by design.
211  ustring(const std::u16string& str, const allocator_type& allocator) noexcept;
212 
214  ustring(const char16* str); // Can't be explicit by design.
218  ustring(const char16* str, const allocator_type& allocator);
219 
221  ustring(char16* str); // Can't be explicit by design.
225  ustring(char16* str, const allocator_type& allocator);
226 
229  ustring(const std::u32string& str) noexcept; // Can't be explicit by design.
233  ustring(const std::u32string& str, const allocator_type& allocator) noexcept;
234 
236  ustring(const char32* str); // Can't be explicit by design.
240  ustring(const char32* str, const allocator_type& allocator);
241 
243  ustring(char32* str); // Can't be explicit by design.
247  ustring(char32* str, const allocator_type& allocator);
248 
251  ustring(const std::wstring& str) noexcept; // Can't be explicit by design.
255  ustring(const std::wstring& str, const allocator_type& allocator) noexcept;
256 
258  ustring(const wchar* str); // Can't be explicit by design.
262  ustring(const wchar* str, const allocator_type& allocator);
263 
265  ustring(wchar* str); // Can't be explicit by design.
269  ustring(wchar* str, const allocator_type& allocator);
270 
273  ustring(ustring&& str) noexcept;
277  ustring(ustring&& str, const allocator_type& allocator) noexcept;
278 
282  template<typename input_iterator_t>
283  ustring(input_iterator_t first, input_iterator_t last) : std::basic_string<value_type>(first, last) {}
288  template<typename input_iterator_t>
289  ustring(input_iterator_t first, input_iterator_t last, const allocator_type& allocator) : std::basic_string<value_type>(first, last, allocator) {}
290 
294  template<typename string_view_like_t>
295  explicit constexpr ustring(const string_view_like_t& string_view, const allocator_type& allocator = allocator_type()) : std::basic_string<value_type>(string_view, allocator) {}
296 
302  template<typename string_view_like_t>
303  constexpr ustring(const string_view_like_t& string_view, size_type index, size_type count, const allocator_type& allocator = allocator_type()) : std::basic_string<value_type>(string_view, index, count, allocator) {}
304 
307  ustring(std::initializer_list<value_type> il);
311  ustring(std::initializer_list<value_type> il, const allocator_type& allocator);
312 
315  ustring(std::initializer_list<char8> il);
319  ustring(std::initializer_list<char8> il, const allocator_type& allocator);
320 
323  ustring(std::initializer_list<char16> il);
327  ustring(std::initializer_list<char16> il, const allocator_type& allocator);
328 
331  ustring(std::initializer_list<char32> il);
335  ustring(std::initializer_list<char32> il, const allocator_type& allocator);
336 
339  ustring(std::initializer_list<wchar> il);
343  ustring(std::initializer_list<wchar> il, const allocator_type& allocator);
345 
347  /*
348  template<typename type_t>
349  ustring(const type_t& object) : std::basic_string<value_type>(object) {}
350  template<typename type_t>
351  ustring(const type_t& object, const allocator_type& allocator) : std::basic_string<value_type>(object, allocator) {}
352  template<typename type_t>
353  ustring(const type_t& object, size_t index, size_t count) : std::basic_string<value_type>(object, index, count) {}
354  template<typename type_t>
355  ustring(const type_t& object, size_t index, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, index, count, allocator) {}
356  template<typename type_t>
357  ustring(const type_t& object, size_t count) : std::basic_string<value_type>(object, 0, count) {}
358  template<typename type_t>
359  ustring(const type_t& object, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, 0, count, allocator) {}
360  */
361 
362  ustring& operator =(const ustring& str);
363  ustring& operator =(const std::string& str);
364  ustring& operator =(const value_type* str);
365  ustring& operator =(const std::u8string& str);
366  ustring& operator =(const char8* str);
367  ustring& operator =(const std::u16string& str);
368  ustring& operator =(const char16* str);
369  ustring& operator =(const std::u32string& str);
370  ustring& operator =(const char32* str);
371  ustring& operator =(const std::wstring& str);
372  ustring& operator =(const wchar* str);
373  ustring& operator =(ustring&& str) noexcept;
374 
375  ustring& operator =(value_type character);
376  ustring& operator =(char8 character);
377  ustring& operator =(char16 character);
378  ustring& operator =(char32 character);
379  ustring& operator =(wchar character);
380  ustring& operator =(const std::initializer_list<value_type>& il);
381  ustring& operator =(const std::initializer_list<char8>& il);
382  ustring& operator =(const std::initializer_list<char16>& il);
383  ustring& operator =(const std::initializer_list<char32>& il);
384  ustring& operator =(const std::initializer_list<wchar>& il);
385  //template<typename type_t>
386  //ustring& operator =(const type_t& object) {return std::basic_string<value_type>::assign(object);}
387 
388  template<typename type_t>
389  ustring operator +(const type_t& object) const {
390  ustring result(*this);
391  result.append(object);
392  return result;
393  }
394 
395  ustring& operator +=(const ustring& str);
396  ustring& operator +=(const std::string& str);
397  ustring& operator +=(const value_type* str);
398  ustring& operator +=(const std::u8string& str);
399  ustring& operator +=(const char8* str);
400  ustring& operator +=(const std::u16string& str);
401  ustring& operator +=(const char16* str);
402  ustring& operator +=(const std::u32string& str);
403  ustring& operator +=(const char32* str);
404  ustring& operator +=(const std::wstring& str);
405  ustring& operator +=(const wchar* str);
406  ustring& operator +=(value_type character);
407  ustring& operator +=(char8 character);
408  ustring& operator +=(char16 character);
409  ustring& operator +=(char32 character);
410  ustring& operator +=(wchar character);
411  ustring& operator +=(const std::initializer_list<value_type>& il);
412  ustring& operator +=(const std::initializer_list<char8>& il);
413  ustring& operator +=(const std::initializer_list<char16>& il);
414  ustring& operator +=(const std::initializer_list<char32>& il);
415  ustring& operator +=(const std::initializer_list<wchar>& il);
416  template<typename type_t>
417  ustring& operator +=(const type_t& object) {
418  *this = *this + ustring(object);
419  return *this;
420  }
421 
422  bool operator ==(const ustring& other) const;
423  bool operator !=(const ustring& other) const;
424  bool operator ==(const std::string& other) const;
425  bool operator !=(const std::string& other) const;
426  bool operator ==(const value_type* other) const;
427  bool operator !=(const value_type* other) const;
428  bool operator ==(const std::u8string& other) const;
429  bool operator !=(const std::u8string& other) const;
430  bool operator ==(const char8* other) const;
431  bool operator !=(const char8* other) const;
432  bool operator ==(const std::u16string& other) const;
433  bool operator !=(const std::u16string& other) const;
434  bool operator ==(const char16* other) const;
435  bool operator !=(const char16* other) const;
436  bool operator ==(const std::u32string& other) const;
437  bool operator !=(const std::u32string& other) const;
438  bool operator ==(const char32* other) const;
439  bool operator !=(const char32* other) const;
440  bool operator ==(const std::wstring& other) const;
441  bool operator !=(const std::wstring& other) const;
442  bool operator ==(const wchar* other) const;
443  bool operator !=(const wchar* other) const;
444  const value_type& operator [](size_t index);
445  const value_type& operator [](size_t index) const;
446  ustring substr(size_type index = 0, size_type count = npos) const;
448 
450 
455  template<typename object_t>
456  static ustring class_name() {return get_class_name(full_class_name<object_t>());}
457 
461  template<typename object_t>
462  static ustring class_name(const object_t& object) {return get_class_name(full_class_name(object));}
463 
467  static ustring class_name(const std::type_info& info);
468 
469  using std::basic_string<value_type>::compare;
479  static int32 compare(const ustring& str_a, const ustring& str_b) noexcept;
490  static int32 compare(const ustring& str_a, const ustring& str_b, bool ignore_case) noexcept;
491 
502  static int32 compare(const ustring& str_a, const ustring& str_b, xtd::string_comparison comparison_type) noexcept;
515  static int32 compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length) noexcept;
529  static int32 compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length, bool ignore_case) noexcept;
543  static int32 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;
544 
545  int32 compare_to(const ustring& tzi) const noexcept override;
546 
553  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c, const ustring& str_d) noexcept;
554 
561  template<typename object_a_t, typename object_b_t, typename object_c_t, typename object_d_t>
562  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c, object_d_t obj_d) noexcept {
563  return format("{}{}{}{}", obj_a, obj_b, obj_c, obj_d);
564  }
565 
571  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c) noexcept;
572 
578  template<typename object_a_t, typename object_b_t, typename object_c_t>
579  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c) noexcept {
580  return format("{}{}{}", obj_a, obj_b, obj_c);
581  }
582 
587  static ustring concat(const ustring& str_a, const ustring& str_b) noexcept;
588 
593  template<typename object_a_t, typename object_b_t>
594  static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept {
595  return format("{}{}", obj_a, obj_b);
596  }
597 
601  static ustring concat(const std::vector<ustring>& values) noexcept;
602 
604  static ustring concat(const std::vector<const value_type*>& values) noexcept;
605  static ustring concat(const std::vector<const char8*>& values) noexcept;
606  static ustring concat(const std::initializer_list<ustring>& values) noexcept;
607  static ustring concat(const std::initializer_list<const value_type*>& values) noexcept;
608  static ustring concat(const std::initializer_list<const char8*>& values) noexcept;
610 
614  template<typename object_t>
615  static ustring concat(const std::vector<object_t>& args) noexcept {
616  ustring result;
617  for (const auto& arg : args)
618  result += format("{}", arg);
619  return result;
620  }
621 
623  template<typename object_t>
624  static ustring concat(const std::initializer_list<object_t>& args) noexcept {
625  ustring result;
626  for (const auto& arg : args)
627  result += format("{}", arg);
628  return result;
629  }
631 
635  template<typename value_t>
636  static ustring concat(value_t value) noexcept {
637  return format("{}", value);
638  }
639 
660  static ustring demangle(const ustring& name);
661 
665  bool contains(const ustring& value) const noexcept;
666 
667  bool equals(const ustring& tzi) const noexcept;
668 
672  bool ends_with(value_type value) const noexcept;
673 
677  bool ends_with(char8 value) const noexcept;
678 
682  bool ends_with(const ustring& value) const noexcept;
683 
687  bool ends_with(const ustring& value, bool ignore_case) const noexcept;
688 
692  bool ends_with(const ustring& value, xtd::string_comparison comparison_type) const noexcept;
693 
700  template<typename ...args_t>
701  static ustring format(const ustring& fmt, args_t&& ... args) {
702  ustring result;
703  size_t index = 0;
704  std::vector<__format_information<char>> formats;
705  auto begin_format_iterator = fmt.end();
706  auto end_format_iterator = fmt.end();
707  for (auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
708  if (*iterator == '{') {
709  if (++iterator == fmt.end())
710  __throw_ustring_format_exception_open_bracket();
711  if (*iterator == '{')
712  result += *iterator;
713  else {
714  begin_format_iterator = iterator;
715  while (iterator != fmt.end() && *iterator != '}') ++iterator;
716  if (iterator == fmt.end())
717  __throw_ustring_format_exception_open_bracket();
718  end_format_iterator = iterator;
719  __format_information<char> fi;
720  fi.location = result.size();
721  std::string format_str {begin_format_iterator, end_format_iterator};
722  if (format_str.size() == 0)
723  fi.index = index++;
724  else {
725  size_t index_alignment_separator = ustring(format_str).index_of(',');
726  size_t index_format_separator = ustring(format_str).index_of(u8':');
727 
728  if (index_alignment_separator != std::string::npos && index_format_separator != std::string::npos && index_alignment_separator > index_format_separator)
729  index_alignment_separator = std::string::npos;
730 
731  if (index_alignment_separator != std::string::npos)
732  fi.alignment = format_str.substr(index_alignment_separator + 1, index_format_separator != std::string::npos ? index_format_separator - index_alignment_separator - 1 : std::string::npos);
733 
734  if (index_format_separator != std::string::npos)
735  fi.format = format_str.substr(index_format_separator + 1);
736 
737  if (index_alignment_separator == 0 || index_format_separator == 0)
738  fi.index = index++;
739  else {
740  std::string index_str;
741  if (index_alignment_separator != std::string::npos)
742  index_str = format_str.substr(0, index_alignment_separator);
743  else if (index_format_separator != std::string::npos)
744  index_str = format_str.substr(0, index_format_separator);
745  else
746  index_str = std::move(format_str);
747  try {
748  for (auto c : index_str)
749  if (!std::isdigit(c)) __throw_ustring_format_exception_start_colon();
750  fi.index = std::stoi(index_str);
751  } catch (...) {
752  __throw_ustring_format_exception_start_colon();
753  }
754  }
755  }
756  formats.push_back(fi);
757  }
758  } else if (*iterator == '}') {
759  if (++iterator == fmt.end()) {
760  __throw_ustring_format_exception_close_bracket();
761  break;
762  }
763  if (*iterator != '}') {
764  __throw_ustring_format_exception_close_bracket();
765  break;
766  }
767  result += *iterator;
768  } else
769  result += *iterator;
770  }
771 
772  __ustring_extract_format_arg(result, formats, std::forward<args_t>(args)...);
773  return result.c_str();
774  }
775 
779  template<typename object_t>
780  static ustring full_class_name() {return demangle(typeid(object_t).name());}
781 
785  template<typename object_t>
786  static ustring full_class_name(const object_t& object) {return demangle(typeid(object).name());}
787 
791  static ustring full_class_name(const std::type_info& info);
792 
795  size_t get_hash_code() const noexcept override;
796 
800  size_t index_of(value_type value) const noexcept;
801 
805  size_t index_of(const ustring& value) const noexcept;
806 
811  size_t index_of(value_type value, size_t start_index) const noexcept;
812 
817  size_t index_of(const ustring& value, size_t start_index) const noexcept;
818 
824  size_t index_of(value_type value, size_t start_index, size_t count) const noexcept;
825 
831  size_t index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
832 
836  size_t index_of_any(const std::vector<value_type>& values) const noexcept;
837 
842  size_t index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
843 
849  size_t index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
850 
852  size_t index_of_any(const std::initializer_list<value_type>& values) const noexcept;
853  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
854  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
856 
863  ustring insert(size_t start_index, const ustring& value) const noexcept;
864 
868  [[deprecated("Replaced by xtd::ustring::is_empty(const xtd::ustring&) - Will be removed in version 0.4.0")]]
869  bool is_empty() const noexcept {return is_empty(*this);}
870 
874  static bool is_empty(const xtd::ustring& string) noexcept;
875 
882  template<typename collection_t>
883  static ustring join(const ustring separator, const collection_t& values) noexcept {return join(separator, values, 0, values.size());}
884 
892  template<typename collection_t>
893  static ustring join(const ustring& separator, const collection_t& values, size_t index) noexcept {return join(separator, values, index, values.size() - index);}
894 
903  template<typename collection_t>
904  static ustring join(const ustring& separator, const collection_t& values, size_t index, size_t count) noexcept {
905  size_t i = 0;
906  ustring result;
907  for (const auto& item : values) {
908  if (i >= index) {
909  if (i != index) result += separator;
910  result += format("{}", item);
911  }
912  if (++i >= index + count) break;
913  }
914  return result;
915  }
916 
918  template<typename value_t>
919  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values) noexcept {return join(separator, std::vector<value_t>(values));}
920  template<typename value_t>
921  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);}
922  template<typename value_t>
923  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);}
925 
929  size_t last_index_of(value_type value) const noexcept;
930 
934  size_t last_index_of(const ustring& value) const noexcept;
935 
940  size_t last_index_of(value_type value, size_t start_index) const noexcept;
941 
946  size_t last_index_of(const ustring& value, size_t start_index) const noexcept;
947 
954  size_t last_index_of(value_type value, size_t start_index, size_t count) const noexcept;
955 
961  size_t last_index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
962 
966  size_t last_index_of_any(const std::vector<value_type>& values) const noexcept;
967 
972  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
973 
979  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
980 
982  size_t last_index_of_any(const std::initializer_list<value_type>& values) const noexcept;
983  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
984  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
986 
992  ustring pad_left(size_t total_width) const noexcept;
993 
1000  ustring pad_left(size_t total_width, value_type padding_char) const noexcept;
1001 
1007  ustring pad_right(size_t total_width) const noexcept;
1008 
1015  ustring pad_right(size_t total_width, value_type padding_char) const noexcept;
1016 
1020  template<typename value_t>
1021  static value_t parse(const ustring& str) {
1022  return xtd::parse<value_t>(str);
1023  }
1024 
1028  ustring remove(size_t start_index) const noexcept;
1029 
1034  ustring remove(size_t start_index, size_t count) const noexcept;
1035 
1040  ustring replace(value_type old_char, value_type new_char) const noexcept;
1041 
1047  ustring replace(const ustring& old_string, const ustring& new_string) const noexcept;
1048 
1060  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count, string_split_options options) const noexcept;
1061 
1066  std::vector<ustring> split() const noexcept;
1067 
1073  std::vector<ustring> split(const std::vector<value_type>& separators) const noexcept;
1074 
1091  std::vector<ustring> split(const std::vector<value_type>& separators, string_split_options options) const noexcept;
1092 
1101  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count) const noexcept;
1102 
1162  template<typename ... args_t>
1163  static ustring sprintf(const ustring& fmt, args_t&& ... args) noexcept {return __sprintf(fmt.c_str(), convert_param(std::forward<args_t>(args)) ...);}
1164 
1169  bool starts_with(value_type value) const noexcept;
1170 
1176  bool starts_with(value_type value, bool ignore_case) const noexcept;
1177 
1182  bool starts_with(const ustring& value) const noexcept;
1183 
1189  bool starts_with(const ustring& value, bool ignore_case) const noexcept;
1190 
1195  ustring substring(size_t start_index) const noexcept;
1196 
1201  ustring substring(size_t start_index, size_t length) const noexcept;
1202 
1205  std::vector<value_type> to_array() const noexcept;
1206 
1210  std::vector<value_type> to_array(size_t start_index) const noexcept;
1211 
1216  std::vector<value_type> to_array(size_t start_index, size_t length) const noexcept;
1217 
1220  ustring to_lower() const noexcept;
1221 
1222  //ustring to_string() const noexcept override;
1223  ustring to_string() const noexcept override;
1224 
1227  ustring to_upper() const noexcept;
1228 
1233  ustring trim() const noexcept;
1234 
1239  ustring trim(value_type trim_char) const noexcept;
1240 
1245  ustring trim(const std::vector<value_type>& trim_chars) const noexcept;
1246 
1251  ustring trim_end() const noexcept;
1252 
1257  ustring trim_end(value_type trim_char) const noexcept;
1258 
1263  ustring trim_end(const std::vector<value_type>& trim_chars) const noexcept;
1264 
1269  ustring trim_start() const noexcept;
1270 
1275  ustring trim_start(value_type trim_char) const noexcept;
1276 
1281  ustring trim_start(const std::vector<value_type>& trim_chars) const noexcept;
1282 
1287  template<typename value_t>
1288  static bool try_parse(const ustring& str, value_t& value) noexcept {
1289  try {
1290  value = parse<value_t>(str);
1291  return true;
1292  } catch (...) {
1293  return false;
1294  }
1295  }
1297 
1299  friend std::ostream& operator <<(std::ostream& stream, const ustring& str) {return stream << str.c_str();}
1300  friend std::istream& operator >>(std::istream& stream, ustring& str) {
1301  std::string s;
1302  stream >> s;
1303  str = s;
1304  return stream;
1305  }
1306 
1307  friend ustring operator +(const ustring& str_a, const ustring& str_b) {
1308  ustring result = str_a;
1309  result.append(str_b);
1310  return result;
1311  }
1312 
1313  friend ustring operator +(const ustring& str_a, const std::string& 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 value_type* 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 std::u8string& 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, const char8* str_b) {
1332  ustring result = str_a;
1333  result.append(ustring(str_b));
1334  return result;
1335  }
1336 
1337  friend ustring operator +(const ustring& str_a, const std::u16string& str_b) {
1338  ustring result = str_a;
1339  result.append(ustring(str_b));
1340  return result;
1341  }
1342 
1343  friend ustring operator +(const ustring& str_a, const char16* str_b) {
1344  ustring result = str_a;
1345  result.append(ustring(str_b));
1346  return result;
1347  }
1348 
1349  friend ustring operator +(const ustring& str_a, const std::u32string& str_b) {
1350  ustring result = str_a;
1351  result.append(ustring(str_b));
1352  return result;
1353  }
1354 
1355  friend ustring operator +(const ustring& str_a, const char32* str_b) {
1356  ustring result = str_a;
1357  result.append(ustring(str_b));
1358  return result;
1359  }
1360 
1361  friend ustring operator +(const ustring& str_a, const std::wstring& str_b) {
1362  ustring result = str_a;
1363  result.append(ustring(str_b));
1364  return result;
1365  }
1366 
1367  friend ustring operator +(const ustring& str_a, const wchar* str_b) {
1368  ustring result = str_a;
1369  result.append(ustring(str_b));
1370  return result;
1371  }
1372 
1373  friend ustring operator +(const ustring& str_a, value_type character) {
1374  ustring result = str_a;
1375  result.append(ustring(1, character));
1376  return result;
1377  }
1378 
1379  friend ustring operator +(const ustring& str_a, char8 character) {
1380  ustring result = str_a;
1381  result.append(ustring(1, character));
1382  return result;
1383  }
1384 
1385  friend ustring operator +(const ustring& str_a, char16 character) {
1386  ustring result = str_a;
1387  result.append(ustring(1, character));
1388  return result;
1389  }
1390 
1391  friend ustring operator +(const ustring& str_a, char32 character) {
1392  ustring result = str_a;
1393  result.append(ustring(1, character));
1394  return result;
1395  }
1396 
1397  friend ustring operator +(const ustring& str_a, wchar character) {
1398  ustring result = str_a;
1399  result.append(ustring(1, character));
1400  return result;
1401  }
1402 
1403  friend ustring operator +(const ustring& str_a, const std::initializer_list<value_type>& il) {
1404  ustring result = str_a;
1405  result.append(ustring(il));
1406  return result;
1407  }
1408 
1409  friend ustring operator +(const ustring& str_a, const std::initializer_list<char8>& il) {
1410  ustring result = str_a;
1411  result.append(ustring(il));
1412  return result;
1413  }
1414 
1415  friend ustring operator +(const ustring& str_a, const std::initializer_list<char16>& il) {
1416  ustring result = str_a;
1417  result.append(ustring(il));
1418  return result;
1419  }
1420 
1421  friend ustring operator +(const ustring& str_a, const std::initializer_list<char32>& il) {
1422  ustring result = str_a;
1423  result.append(ustring(il));
1424  return result;
1425  }
1426 
1427  friend ustring operator +(const ustring& str_a, const std::initializer_list<wchar>& il) {
1428  ustring result = str_a;
1429  result.append(ustring(il));
1430  return result;
1431  }
1432 
1433  friend ustring operator +(const std::string& 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 value_type* 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 std::u8string& 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 +(const char8* str_a, const ustring& str_b) {
1452  ustring result(str_a);
1453  result.append(str_b);
1454  return result;
1455  }
1456 
1457  friend ustring operator +(const std::u16string& str_a, const ustring& str_b) {
1458  ustring result(str_a);
1459  result.append(str_b);
1460  return result;
1461  }
1462 
1463  friend ustring operator +(const char16* str_a, const ustring& str_b) {
1464  ustring result(str_a);
1465  result.append(str_b);
1466  return result;
1467  }
1468 
1469  friend ustring operator +(const std::u32string& str_a, const ustring& str_b) {
1470  ustring result(str_a);
1471  result.append(str_b);
1472  return result;
1473  }
1474 
1475  friend ustring operator +(const char32* str_a, const ustring& str_b) {
1476  ustring result(str_a);
1477  result.append(str_b);
1478  return result;
1479  }
1480 
1481  friend ustring operator +(const std::wstring& str_a, const ustring& str_b) {
1482  ustring result(str_a);
1483  result.append(str_b);
1484  return result;
1485  }
1486 
1487  friend ustring operator +(const wchar* str_a, const ustring& str_b) {
1488  ustring result(str_a);
1489  result.append(str_b);
1490  return result;
1491  }
1492 
1493  friend ustring operator +(value_type character, const ustring& str_b) {
1494  ustring result(1, character);
1495  result.append(str_b);
1496  return result;
1497  }
1498 
1499  friend ustring operator +(char8 character, const ustring& str_b) {
1500  ustring result(1, character);
1501  result.append(str_b);
1502  return result;
1503  }
1504 
1505  friend ustring operator +(char16 character, const ustring& str_b) {
1506  ustring result(1, character);
1507  result.append(str_b);
1508  return result;
1509  }
1510 
1511  friend ustring operator +(char32 character, const ustring& str_b) {
1512  ustring result(1, character);
1513  result.append(str_b);
1514  return result;
1515  }
1516 
1517  friend ustring operator +(wchar character, const ustring& str_b) {
1518  ustring result(1, character);
1519  result.append(str_b);
1520  return result;
1521  }
1522 
1523  friend ustring operator +(const std::initializer_list<value_type>& il, const ustring& str_b) {
1524  ustring result(il);
1525  result.append(str_b);
1526  return result;
1527  }
1528 
1529  friend ustring operator +(const std::initializer_list<char8>& il, const ustring& str_b) {
1530  ustring result(il);
1531  result.append(str_b);
1532  return result;
1533  }
1534 
1535  friend ustring operator +(const std::initializer_list<char16>& il, const ustring& str_b) {
1536  ustring result(il);
1537  result.append(str_b);
1538  return result;
1539  }
1540 
1541  friend ustring operator +(const std::initializer_list<char32>& il, const ustring& str_b) {
1542  ustring result(il);
1543  result.append(str_b);
1544  return result;
1545  }
1546 
1547  friend ustring operator +(const std::initializer_list<wchar>& il, const ustring& str_b) {
1548  ustring result(il);
1549  result.append(str_b);
1550  return result;
1551  }
1553 
1554  private:
1555  template<typename arg_t>
1556  static auto convert_param(arg_t&& arg) noexcept {
1557  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();
1558  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();
1559  else return std::forward<arg_t>(arg);
1560  }
1561 
1562  static ustring get_class_name(const ustring& full_name);
1563 
1564  using std::basic_string<value_type>::assign;
1565  using std::basic_string<value_type>::reserve;
1566  using std::basic_string<value_type>::shrink_to_fit;
1567  using std::basic_string<value_type>::clear;
1568  using std::basic_string<value_type>::erase;
1569  using std::basic_string<value_type>::push_back;
1570  using std::basic_string<value_type>::pop_back;
1571  using std::basic_string<value_type>::append;
1572  using std::basic_string<value_type>::replace;
1573  using std::basic_string<value_type>::resize;
1574  };
1575 
1579  ustring to_ustring(int val);
1583  ustring to_ustring(unsigned val);
1587  ustring to_ustring(long val);
1591  ustring to_ustring(unsigned long val);
1595  ustring to_ustring(long long val);
1599  ustring to_ustring(unsigned long long val);
1603  ustring to_ustring(float val);
1607  ustring to_ustring(double val);
1611  ustring to_ustring(long double val);
1615  template <typename type_t>
1616  ustring to_ustring(type_t val) {
1617  return ustring::format("{}", val);
1618  }
1619 }
1620 
1622 template<typename arg_t>
1623 void __ustring_extract_format_arg(std::string& fmt, size_t& index, std::vector<__format_information<char>>& formats, arg_t&& arg) {
1624  size_t offset = 0;
1625  for (auto& format : formats) {
1626  format.location += offset;
1627  if (format.index == index) {
1628  xtd::ustring arg_str = format.format.empty() ? __format_stringer<char, arg_t>(arg) : xtd::to_string(arg, format.format);
1629 
1630  if (!format.alignment.empty()) {
1631  xtd::int32 alignment = 0;
1632  try {
1633  alignment = std::stoi(format.alignment);
1634  } catch (...) {
1635  __throw_ustring_format_exception();
1636  }
1637  if (alignment > 0) arg_str = arg_str.pad_left(alignment);
1638  else if (alignment < 0) arg_str = arg_str.pad_right(-alignment);
1639  }
1640  fmt.insert(format.location, arg_str);
1641  offset += arg_str.size();
1642  }
1643  }
1644  ++index;
1645 }
1646 
1647 template <typename ...args_t>
1648 void __xtd_ustrings_unused(args_t&& ... args) {}
1649 
1650 template<typename ...args_t>
1651 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& formats, args_t&& ... args) {
1652  size_t index = 0;
1653  (__ustring_extract_format_arg(fmt, index, formats, args), ...);
1654  __xtd_ustrings_unused(index); // workaround to mute gcc warning: unused-but-set-variable
1655 }
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:786
ustring trim_start() const noexcept
Removes all leading occurrences of white-space characters from the specified xtd::ustring.
Contains xtd::iequatable interface.
int32 compare_to(const ustring &tzi) const noexcept override
Compares the current instance with another object of the same type.
ustring trim_end() const noexcept
Removes all trailing occurrences of white-space characters from the specified xtd::ustring.
Contains xtd::icomparable interface.
size_t index_of(value_type value) const noexcept
Reports the index of the first occurrence of the specified character in this string.
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:17
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:615
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:15
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
constexpr ustring(const string_view_like_t &string_view, const allocator_type &allocator=allocator_type())
Initializes a new instance of xtd::ustring with specified string view of substring and allocator...
Definition: ustring.h:295
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:904
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:289
string_comparison
Specifies the culture, case, and sort rules to be used by certain overloads of the xtd::ustring::comp...
Definition: string_comparison.h:15
constexpr ustring(const string_view_like_t &string_view, size_type index, size_type count, const allocator_type &allocator=allocator_type())
Initializes a new instance of xtd::ustring with specified string view of substring and allocator...
Definition: ustring.h:303
static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept
Concatenates two specified instances of object.
Definition: ustring.h:594
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::to_string methods.
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1098
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.
ustring trim() const noexcept
Removes all leading and trailing occurrences of white-space characters from the specified xtd::ustrin...
static int32 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...
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:1163
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:462
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.
static value_t parse(const ustring &str)
Converts a string into a value_t type.
Definition: ustring.h:1021
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...
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:869
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.
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:579
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:562
The operating system is other.
bool starts_with(value_type value) const noexcept
Determines whether the beginning of this instance of xtd::ustring matches a specified xtd::ustring...
static bool try_parse(const ustring &str, value_t &value) noexcept
Try to convert a string into a value_t type.
Definition: ustring.h:1288
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:31
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:74
Contains xtd::string_split_options enum class.
static ustring class_name()
Gets the class name of the object_t.
Definition: ustring.h:456
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...
char32_t char32
Represents a 32-bit unicode character.
Definition: types.h:50
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:780
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:893
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:701
std::vector< value_type > to_array() const noexcept
Copies the characters in this instance to a Unicode character array.
static const ustring empty_string
Represents the empty string.
Definition: ustring.h:55
ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
char8_t char8
Represents a 8-bit unicode character.
Definition: types.h:34
ustring to_ustring(int val)
Converts a signed integer to xtd::ustring.
char16_t char16
Represents a 16-bit unicode character.
Definition: types.h:42
static ustring concat(value_t value) noexcept
Creates the string representation of a specified object.
Definition: ustring.h:636
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:883
static ustring demangle(const ustring &name)
Gets demangled string of name,.
wchar_t wchar
Represents a wide character.
Definition: types.h:185