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 <string>
15 #include "icomparable.h"
16 #include "iequatable.h"
17 #include "string_comparison.h"
18 #include "string_split_options.h"
19 #include "types.h"
20 #include "object.h"
21 #include "parse.h"
22 #include "to_string.h"
23 
24 #if !defined(_WIN32)
25 #include <cxxabi.h>
26 #endif
27 
29 namespace xtd {
30  class ustring;
31 }
32 template<typename ...args_t>
33 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& format, args_t&& ... args);
34 void __throw_ustring_format_exception();
35 void __throw_ustring_format_exception_close_bracket();
36 void __throw_ustring_format_exception_open_bracket();
37 void __throw_ustring_format_exception_start_colon();
39 
40 namespace xtd {
50  class ustring : public xtd::icomparable<ustring>, public object, public std::basic_string<char> {
51  public:
53 
57  static ustring empty_string() noexcept;
59 
61 
64  ustring() noexcept;
67  explicit ustring(const allocator_type& allocator) noexcept;
68 
73  ustring(size_t count, value_type character);
79  ustring(size_t count, value_type character, const allocator_type& allocator);
84  ustring(size_t count, char8_t character);
90  ustring(size_t count, char8_t character, const allocator_type& allocator);
95  ustring(size_t count, char16_t character);
101  ustring(size_t count, char16_t character, const allocator_type& allocator);
106  ustring(size_t count, char32_t character);
112  ustring(size_t count, char32_t character, const allocator_type& allocator);
117  ustring(size_t count, wchar_t character);
123  ustring(size_t count, wchar_t character, const allocator_type& allocator);
124 
129  ustring(const ustring& str, size_t index, size_t count);
135  ustring(const ustring& str, size_t index, size_t count, const allocator_type& allocator);
139  ustring(const ustring& str, size_t index);
144  ustring(const ustring& str, size_t index, const allocator_type& allocator);
145 
148  ustring(const value_type* str, size_t count);
153  ustring(const value_type* str, size_t count, const allocator_type& allocator);
154 
156  ustring(const value_type* str);
160  ustring(const value_type* str, const allocator_type& allocator);
161 
163  ustring(value_type* str);
167  ustring(value_type* str, const allocator_type& allocator);
168 
171  ustring(const ustring& str) noexcept;
175  ustring(const ustring& str, const allocator_type& allocator) noexcept;
176 
179  ustring(const std::string& str) noexcept;
183  ustring(const std::string& str, const allocator_type& allocator) noexcept;
184 
187  ustring(const std::u8string& str) noexcept;
191  ustring(const std::u8string& str, const allocator_type& allocator) noexcept;
192 
194  ustring(const char8_t* str);
198  ustring(const char8_t* str, const allocator_type& allocator);
199 
201  ustring(char8_t* str);
205  ustring(char8_t* str, const allocator_type& allocator);
206 
209  ustring(const std::u16string& str) noexcept;
213  ustring(const std::u16string& str, const allocator_type& allocator) noexcept;
214 
216  ustring(const char16_t* str);
220  ustring(const char16_t* str, const allocator_type& allocator);
221 
223  ustring(char16_t* str);
227  ustring(char16_t* str, const allocator_type& allocator);
228 
231  ustring(const std::u32string& str) noexcept;
235  ustring(const std::u32string& str, const allocator_type& allocator) noexcept;
236 
238  ustring(const char32_t* str);
242  ustring(const char32_t* str, const allocator_type& allocator);
243 
245  ustring(char32_t* str);
249  ustring(char32_t* str, const allocator_type& allocator);
250 
253  ustring(const std::wstring& str) noexcept;
257  ustring(const std::wstring& str, const allocator_type& allocator) noexcept;
258 
260  ustring(const wchar_t* str);
264  ustring(const wchar_t* str, const allocator_type& allocator);
265 
267  ustring(wchar_t* str);
271  ustring(wchar_t* str, const allocator_type& allocator);
272 
275  ustring(ustring&& str) noexcept;
279  ustring(ustring&& str, const allocator_type& allocator) noexcept;
280 
284  template<typename input_iterator_t>
285  ustring(input_iterator_t first, input_iterator_t last) : std::basic_string<value_type>(first, last) {}
290  template<typename input_iterator_t>
291  ustring(input_iterator_t first, input_iterator_t last, const allocator_type& allocator) : std::basic_string<value_type>(first, last, allocator) {}
292 
295  ustring(std::initializer_list<value_type> il);
299  ustring(std::initializer_list<value_type> il, const allocator_type& allocator);
300 
303  ustring(std::initializer_list<char8_t> il);
307  ustring(std::initializer_list<char8_t> il, const allocator_type& allocator);
308 
311  ustring(std::initializer_list<char16_t> il);
315  ustring(std::initializer_list<char16_t> il, const allocator_type& allocator);
316 
319  ustring(std::initializer_list<char32_t> il);
323  ustring(std::initializer_list<char32_t> il, const allocator_type& allocator);
324 
327  ustring(std::initializer_list<wchar_t> il);
331  ustring(std::initializer_list<wchar_t> il, const allocator_type& allocator);
333 
335  /*
336  template<typename type_t>
337  ustring(const type_t& object) : std::basic_string<value_type>(object) {}
338  template<typename type_t>
339  ustring(const type_t& object, const allocator_type& allocator) : std::basic_string<value_type>(object, allocator) {}
340  template<typename type_t>
341  ustring(const type_t& object, size_t index, size_t count) : std::basic_string<value_type>(object, index, count) {}
342  template<typename type_t>
343  ustring(const type_t& object, size_t index, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, index, count, allocator) {}
344  template<typename type_t>
345  ustring(const type_t& object, size_t count) : std::basic_string<value_type>(object, 0, count) {}
346  template<typename type_t>
347  ustring(const type_t& object, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, 0, count, allocator) {}
348  */
349 
350  ustring& operator=(const ustring& str);
351  ustring& operator=(const std::string& str);
352  ustring& operator=(const value_type* str);
353  ustring& operator=(const std::u8string& str);
354  ustring& operator=(const char8_t* str);
355  ustring& operator=(const std::u16string& str);
356  ustring& operator=(const char16_t* str);
357  ustring& operator=(const std::u32string& str);
358  ustring& operator=(const char32_t* str);
359  ustring& operator=(const std::wstring& str);
360  ustring& operator=(const wchar_t* str);
361  ustring& operator=(ustring&& str) noexcept;
362 
363  ustring& operator=(value_type character);
364  ustring& operator=(char8_t character);
365  ustring& operator=(char16_t character);
366  ustring& operator=(char32_t character);
367  ustring& operator=(wchar_t character);
368  ustring& operator=(const std::initializer_list<value_type>& il);
369  ustring& operator=(const std::initializer_list<char8_t>& il);
370  ustring& operator=(const std::initializer_list<char16_t>& il);
371  ustring& operator=(const std::initializer_list<char32_t>& il);
372  ustring& operator=(const std::initializer_list<wchar_t>& il);
373  //template<typename type_t>
374  //ustring& operator=(const type_t& object) {return std::basic_string<value_type>::assign(object);}
375 
376  template<typename type_t>
377  ustring operator+(const type_t& object) const {
378  ustring result(*this);
379  result.append(object);
380  return result;
381  }
382 
383  ustring& operator+=(const ustring& str);
384  ustring& operator+=(const std::string& str);
385  ustring& operator+=(const value_type* str);
386  ustring& operator+=(const std::u8string& str);
387  ustring& operator+=(const char8_t* str);
388  ustring& operator+=(const std::u16string& str);
389  ustring& operator+=(const char16_t* str);
390  ustring& operator+=(const std::u32string& str);
391  ustring& operator+=(const char32_t* str);
392  ustring& operator+=(const std::wstring& str);
393  ustring& operator+=(const wchar_t* str);
394  ustring& operator+=(value_type character);
395  ustring& operator+=(char8_t character);
396  ustring& operator+=(char16_t character);
397  ustring& operator+=(char32_t character);
398  ustring& operator+=(wchar_t character);
399  ustring& operator+=(const std::initializer_list<value_type>& il);
400  ustring& operator+=(const std::initializer_list<char8_t>& il);
401  ustring& operator+=(const std::initializer_list<char16_t>& il);
402  ustring& operator+=(const std::initializer_list<char32_t>& il);
403  ustring& operator+=(const std::initializer_list<wchar_t>& il);
404  template<typename type_t>
405  ustring& operator+=(const type_t& object) {
406  *this = *this + ustring(object);
407  return *this;
408  }
409 
410  bool operator==(const ustring& other) const;
411  bool operator!=(const ustring& other) const;
412  bool operator==(const std::string& other) const;
413  bool operator!=(const std::string& other) const;
414  bool operator==(const value_type* other) const;
415  bool operator!=(const value_type* other) const;
416  bool operator==(const std::u8string& other) const;
417  bool operator!=(const std::u8string& other) const;
418  bool operator==(const char8_t* other) const;
419  bool operator!=(const char8_t* other) const;
420  bool operator==(const std::u16string& other) const;
421  bool operator!=(const std::u16string& other) const;
422  bool operator==(const char16_t* other) const;
423  bool operator!=(const char16_t* other) const;
424  bool operator==(const std::u32string& other) const;
425  bool operator!=(const std::u32string& other) const;
426  bool operator==(const char32_t* other) const;
427  bool operator!=(const char32_t* other) const;
428  bool operator==(const std::wstring& other) const;
429  bool operator!=(const std::wstring& other) const;
430  bool operator==(const wchar_t* other) const;
431  bool operator!=(const wchar_t* other) const;
432  const value_type& operator[](size_t index);
433  const value_type& operator[](size_t index) const;
434  ustring substr(size_type index = 0, size_type count = npos) const;
436 
438 
443  template<typename object_t>
444  static ustring full_class_name() {return demangle(typeid(object_t).name());}
445 
449  template<typename object_t>
450  static ustring full_class_name(const object_t& object) {return demangle(typeid(object).name());}
451 
455  static ustring full_class_name(const std::type_info& info) {return demangle(info.name());}
456 
460  template<typename object_t>
461  static ustring class_name() {return get_class_name(full_class_name<object_t>());}
462 
466  template<typename object_t>
467  static ustring class_name(const object_t& object) {return get_class_name(full_class_name(object));}
468 
472  static ustring class_name(const std::type_info& info) {return get_class_name(full_class_name(info));}
473 
474  using std::basic_string<value_type>::compare;
484  static int compare(const ustring& str_a, const ustring& str_b) noexcept;
495  static int compare(const ustring& str_a, const ustring& str_b, bool ignore_case) noexcept;
496 
507  static int compare(const ustring& str_a, const ustring& str_b, xtd::string_comparison comparison_type) noexcept;
520  static int compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length) noexcept;
534  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;
548  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;
549 
550  int32_t compare_to(const ustring& tzi) const noexcept override;
551  int32_t compare_to(const object& obj) const noexcept override;
552 
559  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c, const ustring& str_d) noexcept;
560 
567  template<typename object_a_t, typename object_b_t, typename object_c_t, typename object_d_t>
568  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c, object_d_t obj_d) noexcept {
569  return format("{}{}{}{}", obj_a, obj_b, obj_c, obj_d);
570  }
571 
577  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c) noexcept;
578 
584  template<typename object_a_t, typename object_b_t, typename object_c_t>
585  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c) noexcept {
586  return format("{}{}{}", obj_a, obj_b, obj_c);
587  }
588 
593  static ustring concat(const ustring& str_a, const ustring& str_b) noexcept;
594 
599  template<typename object_a_t, typename object_b_t>
600  static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept {
601  return format("{}{}", obj_a, obj_b);
602  }
603 
607  static ustring concat(const std::vector<ustring>& values) noexcept;
608 
610  static ustring concat(const std::vector<const value_type*>& values) noexcept;
611  static ustring concat(const std::vector<const char8_t*>& values) noexcept;
612  static ustring concat(const std::initializer_list<ustring>& values) noexcept;
613  static ustring concat(const std::initializer_list<const value_type*>& values) noexcept;
614  static ustring concat(const std::initializer_list<const char8_t*>& values) noexcept;
616 
620  template<typename object_t>
621  static ustring concat(const std::vector<object_t>& args) noexcept {
622  ustring result;
623  for (const auto& arg : args)
624  result += format("{}", arg);
625  return result;
626  }
627 
629  template<typename object_t>
630  static ustring concat(const std::initializer_list<object_t>& args) noexcept {
631  ustring result;
632  for (const auto& arg : args)
633  result += format("{}", arg);
634  return result;
635  }
637 
641  template<typename value_t>
642  static ustring concat(value_t value) noexcept {
643  return format("{}", value);
644  }
645 
648  static ustring demangle(const ustring& name) {
649  #if defined(_WIN32)
650  ustring result = name;
651  for (auto& item : {"enum ", "class ", "union ", "struct "})
652  result = result.replace(item, "");
653  return result;
654  #else
655  class auto_delete_char_pointer {
656  public:
657  auto_delete_char_pointer(char* value) : value_(value) {}
658  ~auto_delete_char_pointer() {free(value_);}
659  char* operator()() const {return value_;}
660  private:
661  char* value_;
662  };
663  int32_t status = 0;
664  return auto_delete_char_pointer(abi::__cxa_demangle(name.c_str(), 0, 0, &status))();
665  #endif
666  }
667 
671  bool contains(const ustring& value) const noexcept;
672 
673  bool equals(const ustring& tzi) const noexcept;
674  bool equals(const object& obj) const noexcept override;
675 
679  bool ends_with(value_type value) const noexcept;
680 
684  bool ends_with(char8_t value) const noexcept;
685 
689  bool ends_with(const ustring& value) const noexcept;
690 
694  bool ends_with(const ustring& value, bool ignore_case) const noexcept;
695 
699  bool ends_with(const ustring& value, xtd::string_comparison comparison_type) const noexcept;
700 
707  template<typename ...args_t>
708  static ustring format(const ustring& fmt, args_t&& ... args) {
709  ustring result;
710  size_t index = 0;
711  std::vector<__format_information<char>> formats;
712  auto begin_format_iterator = fmt.end();
713  auto end_format_iterator = fmt.end();
714  for (auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
715  if (*iterator == '{') {
716  if (++iterator == fmt.end())
717  __throw_ustring_format_exception_open_bracket();
718  if (*iterator == '{')
719  result += *iterator;
720  else {
721  begin_format_iterator = iterator;
722  while (iterator != fmt.end() && *iterator != '}') ++iterator;
723  if (iterator == fmt.end())
724  __throw_ustring_format_exception_open_bracket();
725  end_format_iterator = iterator;
726  __format_information<char> fi;
727  fi.location = result.size();
728  std::string format_str {begin_format_iterator, end_format_iterator};
729  if (format_str.size() == 0)
730  fi.index = index++;
731  else {
732  size_t index_alignment_separator = ustring(format_str).index_of(',');
733  size_t index_format_separator = ustring(format_str).index_of(u8':');
734 
735  if (index_alignment_separator != std::string::npos && index_format_separator != std::string::npos && index_alignment_separator > index_format_separator)
736  index_alignment_separator = std::string::npos;
737 
738  if (index_alignment_separator != std::string::npos)
739  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);
740 
741  if (index_format_separator != std::string::npos)
742  fi.format = format_str.substr(index_format_separator + 1);
743 
744  if (index_alignment_separator == 0 || index_format_separator == 0)
745  fi.index = index++;
746  else {
747  std::string index_str;
748  if (index_alignment_separator != std::string::npos)
749  index_str = format_str.substr(0, index_alignment_separator);
750  else if (index_format_separator != std::string::npos)
751  index_str = format_str.substr(0, index_format_separator);
752  else
753  index_str = format_str;
754  try {
755  for (auto c : index_str)
756  if (!std::isdigit(c)) __throw_ustring_format_exception_start_colon();
757  fi.index = std::stoi(index_str);
758  } catch (...) {
759  __throw_ustring_format_exception_start_colon();
760  }
761  }
762  }
763  formats.push_back(fi);
764  }
765  } else if (*iterator == '}') {
766  if (++iterator == fmt.end())
767  __throw_ustring_format_exception_close_bracket();
768  if (*iterator != '}')
769  __throw_ustring_format_exception_close_bracket();
770  result += *iterator;
771  } else
772  result += *iterator;
773  }
774 
775  __ustring_extract_format_arg(result, formats, std::forward<args_t>(args)...);
776  return result.c_str();
777  }
778 
781  size_t get_hash_code() const noexcept override;
782 
786  size_t index_of(value_type value) const noexcept;
787 
791  size_t index_of(const ustring& value) const noexcept;
792 
797  size_t index_of(value_type value, size_t start_index) const noexcept;
798 
803  size_t index_of(const ustring& value, size_t start_index) const noexcept;
804 
810  size_t index_of(value_type value, size_t start_index, size_t count) const noexcept;
811 
817  size_t index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
818 
822  size_t index_of_any(const std::vector<value_type>& values) const noexcept;
823 
828  size_t index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
829 
835  size_t index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
836 
838  size_t index_of_any(const std::initializer_list<value_type>& values) const noexcept;
839  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
840  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
842 
849  ustring insert(size_t start_index, const ustring& value) const noexcept;
850 
854  [[deprecated("Replaced by xtd::ustring::is_empty(const xtd::ustring&) - Will be removed in version 0.4.0")]]
855  bool is_empty() const noexcept {return is_empty(*this);}
856 
860  static bool is_empty(const xtd::ustring& string) noexcept;
861 
868  template<typename collection_t>
869  static ustring join(const ustring separator, const collection_t& values) noexcept {return join(separator, values, 0, values.size());}
870 
878  template<typename collection_t>
879  static ustring join(const ustring& separator, const collection_t& values, size_t index) noexcept {return join(separator, values, index, values.size() - index);}
880 
889  template<typename collection_t>
890  static ustring join(const ustring& separator, const collection_t& values, size_t index, size_t count) noexcept {
891  size_t i = 0;
892  ustring result;
893  for (const auto& item : values) {
894  if (i >= index) {
895  if (i != index) result += separator;
896  result += format("{}", item);
897  }
898  if (++i >= index + count) break;
899  }
900  return result;
901  }
902 
904  template<typename value_t>
905  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values) noexcept {return join(separator, std::vector<value_t>(values));}
906  template<typename value_t>
907  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);}
908  template<typename value_t>
909  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);}
911 
915  size_t last_index_of(value_type value) const noexcept;
916 
920  size_t last_index_of(const ustring& value) const noexcept;
921 
926  size_t last_index_of(value_type value, size_t start_index) const noexcept;
927 
932  size_t last_index_of(const ustring& value, size_t start_index) const noexcept;
933 
940  size_t last_index_of(value_type value, size_t start_index, size_t count) const noexcept;
941 
947  size_t last_index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
948 
952  size_t last_index_of_any(const std::vector<value_type>& values) const noexcept;
953 
958  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
959 
965  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
966 
968  size_t last_index_of_any(const std::initializer_list<value_type>& values) const noexcept;
969  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
970  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
972 
978  ustring pad_left(size_t total_width) const noexcept;
979 
986  ustring pad_left(size_t total_width, value_type padding_char) const noexcept;
987 
993  ustring pad_right(size_t total_width) const noexcept;
994 
1001  ustring pad_right(size_t total_width, value_type padding_char) const noexcept;
1002 
1006  ustring remove(size_t start_index) const noexcept;
1007 
1012  ustring remove(size_t start_index, size_t count) const noexcept;
1013 
1018  ustring replace(value_type old_char, value_type new_char) const noexcept;
1019 
1025  ustring replace(const ustring& old_string, const ustring& new_string) const noexcept;
1026 
1038  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count, string_split_options options) const noexcept;
1039 
1044  std::vector<ustring> split() const noexcept;
1045 
1051  std::vector<ustring> split(const std::vector<value_type>& separators) const noexcept;
1052 
1069  std::vector<ustring> split(const std::vector<value_type>& separators, string_split_options options) const noexcept;
1070 
1079  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count) const noexcept;
1080 
1140  template<typename ... args_t>
1141  static ustring sprintf(const ustring& fmt, args_t&& ... args) noexcept {return __sprintf(fmt.c_str(), convert_param(std::forward<args_t>(args)) ...);}
1142 
1147  bool starts_with(value_type value) const noexcept;
1148 
1154  bool starts_with(value_type value, bool ignore_case) const noexcept;
1155 
1160  bool starts_with(const ustring& value) const noexcept;
1161 
1167  bool starts_with(const ustring& value, bool ignore_case) const noexcept;
1168 
1173  ustring substring(size_t start_index) const noexcept;
1174 
1179  ustring substring(size_t start_index, size_t length) const noexcept;
1180 
1183  std::vector<value_type> to_array() const noexcept;
1184 
1188  std::vector<value_type> to_array(size_t start_index) const noexcept;
1189 
1194  std::vector<value_type> to_array(size_t start_index, size_t length) const noexcept;
1195 
1198  ustring to_lower() const noexcept;
1199 
1200  //ustring to_string() const noexcept override;
1201  ustring to_string() const noexcept override;
1202 
1205  ustring to_upper() const noexcept;
1206 
1211  ustring trim() const noexcept;
1212 
1217  ustring trim(value_type trim_char) const noexcept;
1218 
1223  ustring trim(const std::vector<value_type>& trim_chars) const noexcept;
1224 
1229  ustring trim_end() const noexcept;
1230 
1235  ustring trim_end(value_type trim_char) const noexcept;
1236 
1241  ustring trim_end(const std::vector<value_type>& trim_chars) const noexcept;
1242 
1247  ustring trim_start() const noexcept;
1248 
1253  ustring trim_start(value_type trim_char) const noexcept;
1254 
1259  ustring trim_start(const std::vector<value_type>& trim_chars) const noexcept;
1260 
1261  template<typename value_t>
1262  static value_t parse(const ustring& str) {
1263  return xtd::parse<value_t>(str);
1264  }
1265 
1266  template<typename value_t>
1267  static bool try_parse(const ustring& str, value_t& value) {
1268  try {
1269  value = parse<value_t>(str);
1270  return true;
1271  } catch (...) {
1272  return false;
1273  }
1274  }
1276 
1278  friend std::ostream& operator<<(std::ostream& stream, const ustring& str) {return stream << str.c_str();}
1279  friend std::istream& operator>>(std::istream& stream, ustring& str) {
1280  std::string s;
1281  stream >> s;
1282  str = s;
1283  return stream;
1284  }
1285 
1286  friend ustring operator+(const ustring& str_a, const ustring& str_b) {
1287  ustring result = str_a;
1288  result.append(str_b);
1289  return result;
1290  }
1291 
1292  friend ustring operator+(const ustring& str_a, const std::string& str_b) {
1293  ustring result = str_a;
1294  result.append(ustring(str_b));
1295  return result;
1296  }
1297 
1298  friend ustring operator+(const ustring& str_a, const value_type* str_b) {
1299  ustring result = str_a;
1300  result.append(ustring(str_b));
1301  return result;
1302  }
1303 
1304  friend ustring operator+(const ustring& str_a, const std::u8string& str_b) {
1305  ustring result = str_a;
1306  result.append(ustring(str_b));
1307  return result;
1308  }
1309 
1310  friend ustring operator+(const ustring& str_a, const char8_t* str_b) {
1311  ustring result = str_a;
1312  result.append(ustring(str_b));
1313  return result;
1314  }
1315 
1316  friend ustring operator+(const ustring& str_a, const std::u16string& str_b) {
1317  ustring result = str_a;
1318  result.append(ustring(str_b));
1319  return result;
1320  }
1321 
1322  friend ustring operator+(const ustring& str_a, const char16_t* str_b) {
1323  ustring result = str_a;
1324  result.append(ustring(str_b));
1325  return result;
1326  }
1327 
1328  friend ustring operator+(const ustring& str_a, const std::u32string& str_b) {
1329  ustring result = str_a;
1330  result.append(ustring(str_b));
1331  return result;
1332  }
1333 
1334  friend ustring operator+(const ustring& str_a, const char32_t* str_b) {
1335  ustring result = str_a;
1336  result.append(ustring(str_b));
1337  return result;
1338  }
1339 
1340  friend ustring operator+(const ustring& str_a, const std::wstring& str_b) {
1341  ustring result = str_a;
1342  result.append(ustring(str_b));
1343  return result;
1344  }
1345 
1346  friend ustring operator+(const ustring& str_a, const wchar_t* str_b) {
1347  ustring result = str_a;
1348  result.append(ustring(str_b));
1349  return result;
1350  }
1351 
1352  friend ustring operator+(const ustring& str_a, value_type character) {
1353  ustring result = str_a;
1354  result.append(ustring(1, character));
1355  return result;
1356  }
1357 
1358  friend ustring operator+(const ustring& str_a, char8_t character) {
1359  ustring result = str_a;
1360  result.append(ustring(1, character));
1361  return result;
1362  }
1363 
1364  friend ustring operator+(const ustring& str_a, char16_t character) {
1365  ustring result = str_a;
1366  result.append(ustring(1, character));
1367  return result;
1368  }
1369 
1370  friend ustring operator+(const ustring& str_a, char32_t character) {
1371  ustring result = str_a;
1372  result.append(ustring(1, character));
1373  return result;
1374  }
1375 
1376  friend ustring operator+(const ustring& str_a, wchar_t character) {
1377  ustring result = str_a;
1378  result.append(ustring(1, character));
1379  return result;
1380  }
1381 
1382  friend ustring operator+(const ustring& str_a, const std::initializer_list<value_type>& il) {
1383  ustring result = str_a;
1384  result.append(ustring(il));
1385  return result;
1386  }
1387 
1388  friend ustring operator+(const ustring& str_a, const std::initializer_list<char8_t>& il) {
1389  ustring result = str_a;
1390  result.append(ustring(il));
1391  return result;
1392  }
1393 
1394  friend ustring operator+(const ustring& str_a, const std::initializer_list<char16_t>& il) {
1395  ustring result = str_a;
1396  result.append(ustring(il));
1397  return result;
1398  }
1399 
1400  friend ustring operator+(const ustring& str_a, const std::initializer_list<char32_t>& il) {
1401  ustring result = str_a;
1402  result.append(ustring(il));
1403  return result;
1404  }
1405 
1406  friend ustring operator+(const ustring& str_a, const std::initializer_list<wchar_t>& il) {
1407  ustring result = str_a;
1408  result.append(ustring(il));
1409  return result;
1410  }
1411 
1412  friend ustring operator+(const std::string& str_a, const ustring& str_b) {
1413  ustring result(str_a);
1414  result.append(str_b);
1415  return result;
1416  }
1417 
1418  friend ustring operator+(const value_type* str_a, const ustring& str_b) {
1419  ustring result(str_a);
1420  result.append(str_b);
1421  return result;
1422  }
1423 
1424  friend ustring operator+(const std::u8string& str_a, const ustring& str_b) {
1425  ustring result(str_a);
1426  result.append(str_b);
1427  return result;
1428  }
1429 
1430  friend ustring operator+(const char8_t* str_a, const ustring& str_b) {
1431  ustring result(str_a);
1432  result.append(str_b);
1433  return result;
1434  }
1435 
1436  friend ustring operator+(const std::u16string& str_a, const ustring& str_b) {
1437  ustring result(str_a);
1438  result.append(str_b);
1439  return result;
1440  }
1441 
1442  friend ustring operator+(const char16_t* str_a, const ustring& str_b) {
1443  ustring result(str_a);
1444  result.append(str_b);
1445  return result;
1446  }
1447 
1448  friend ustring operator+(const std::u32string& str_a, const ustring& str_b) {
1449  ustring result(str_a);
1450  result.append(str_b);
1451  return result;
1452  }
1453 
1454  friend ustring operator+(const char32_t* str_a, const ustring& str_b) {
1455  ustring result(str_a);
1456  result.append(str_b);
1457  return result;
1458  }
1459 
1460  friend ustring operator+(const std::wstring& str_a, const ustring& str_b) {
1461  ustring result(str_a);
1462  result.append(str_b);
1463  return result;
1464  }
1465 
1466  friend ustring operator+(const wchar_t* str_a, const ustring& str_b) {
1467  ustring result(str_a);
1468  result.append(str_b);
1469  return result;
1470  }
1471 
1472  friend ustring operator+(value_type character, const ustring& str_b) {
1473  ustring result(1, character);
1474  result.append(str_b);
1475  return result;
1476  }
1477 
1478  friend ustring operator+(char8_t character, const ustring& str_b) {
1479  ustring result(1, character);
1480  result.append(str_b);
1481  return result;
1482  }
1483 
1484  friend ustring operator+(char16_t character, const ustring& str_b) {
1485  ustring result(1, character);
1486  result.append(str_b);
1487  return result;
1488  }
1489 
1490  friend ustring operator+(char32_t character, const ustring& str_b) {
1491  ustring result(1, character);
1492  result.append(str_b);
1493  return result;
1494  }
1495 
1496  friend ustring operator+(wchar_t character, const ustring& str_b) {
1497  ustring result(1, character);
1498  result.append(str_b);
1499  return result;
1500  }
1501 
1502  friend ustring operator+(const std::initializer_list<value_type>& il, const ustring& str_b) {
1503  ustring result(il);
1504  result.append(str_b);
1505  return result;
1506  }
1507 
1508  friend ustring operator+(const std::initializer_list<char8_t>& il, const ustring& str_b) {
1509  ustring result(il);
1510  result.append(str_b);
1511  return result;
1512  }
1513 
1514  friend ustring operator+(const std::initializer_list<char16_t>& il, const ustring& str_b) {
1515  ustring result(il);
1516  result.append(str_b);
1517  return result;
1518  }
1519 
1520  friend ustring operator+(const std::initializer_list<char32_t>& il, const ustring& str_b) {
1521  ustring result(il);
1522  result.append(str_b);
1523  return result;
1524  }
1525 
1526  friend ustring operator+(const std::initializer_list<wchar_t>& il, const ustring& str_b) {
1527  ustring result(il);
1528  result.append(str_b);
1529  return result;
1530  }
1532 
1533  private:
1534  template<typename arg_t>
1535  static auto convert_param(arg_t&& arg) noexcept {
1536  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();
1537  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();
1538  else return std::forward<arg_t>(arg);
1539  }
1540 
1541  static ustring get_class_name(const ustring& full_name);
1542 
1543  using std::basic_string<value_type>::assign;
1544  using std::basic_string<value_type>::reserve;
1545  using std::basic_string<value_type>::shrink_to_fit;
1546  using std::basic_string<value_type>::clear;
1547  using std::basic_string<value_type>::erase;
1548  using std::basic_string<value_type>::push_back;
1549  using std::basic_string<value_type>::pop_back;
1550  using std::basic_string<value_type>::append;
1551  using std::basic_string<value_type>::replace;
1552  using std::basic_string<value_type>::resize;
1553  };
1554 
1558  ustring to_ustring(int val);
1562  ustring to_ustring(unsigned val);
1566  ustring to_ustring(long val);
1570  ustring to_ustring(unsigned long val);
1574  ustring to_ustring(long long val);
1578  ustring to_ustring(unsigned long long val);
1582  ustring to_ustring(float val);
1586  ustring to_ustring(double val);
1590  ustring to_ustring(long double val);
1594  template <typename type_t>
1595  ustring to_ustring(type_t val) {
1596  return ustring::format("{}", val);
1597  }
1598 }
1599 
1601 template<typename arg_t>
1602 void __ustring_extract_format_arg(std::string& fmt, size_t& index, std::vector<__format_information<char>>& formats, arg_t&& arg) {
1603  size_t offset = 0;
1604  for (auto& format : formats) {
1605  format.location += offset;
1606  if (format.index == index) {
1607  xtd::ustring arg_str = format.format.empty() ? __format_stringer<char, arg_t>(arg) : xtd::to_string(arg, format.format);
1608 
1609  if (!format.alignment.empty()) {
1610  int alignment = 0;
1611  try {
1612  alignment = std::stoi(format.alignment);
1613  } catch (...) {
1614  __throw_ustring_format_exception();
1615  }
1616  if (alignment > 0) arg_str = arg_str.pad_left(alignment);
1617  else if (alignment < 0) arg_str = arg_str.pad_right(-alignment);
1618  }
1619  fmt.insert(format.location, arg_str);
1620  offset += arg_str.size();
1621  }
1622  }
1623  ++index;
1624 }
1625 
1626 template <typename ...args_t>
1627 void __xtd_ustrings_unused(args_t&& ... args) {}
1628 
1629 template<typename ...args_t>
1630 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& formats, args_t&& ... args) {
1631  size_t index = 0;
1632  (__ustring_extract_format_arg(fmt, index, formats, args), ...);
1633  __xtd_ustrings_unused(index); // workaround to mute gcc warning: unused-but-set-variable
1634 }
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:450
ustring trim_start() const noexcept
Removes all leading occurrences of white-space characters from the specified String.
Contains xtd::iequatable interface.
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:22
ustring trim_end() const noexcept
Removes all trailing occurrences of white-space characters from the specified String.
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:18
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:621
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 string into a type.
Definition: parse.h:399
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:890
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:291
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:600
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
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:1110
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:472
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:1141
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:467
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:455
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:855
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:285
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:585
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:568
The operating system is other.
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:30
Contains xtd::string_split_options enum class.
static ustring class_name()
Gets the class name of the object_t.
Definition: ustring.h:461
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:444
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:879
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:708
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 sxd::ustring 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:642
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:869
static ustring demangle(const ustring &name)
Gets demangled string of name,.
Definition: ustring.h:648
int32_t compare_to(const ustring &tzi) const noexcept override
Compares the current instance with another object of the same type.
static ustring empty_string() noexcept
Represents the empty string.