xtd 0.2.0
ustring.h
Go to the documentation of this file.
1 #pragma once
4 #define __XTD_CORE_INTERNAL__
6 #include "internal/__generic_stream_output.h"
7 #include "internal/__format_information.h"
8 #include "internal/__format_stringer.h"
9 #include "internal/__sprintf.h"
10 #undef __XTD_CORE_INTERNAL__
11 #include "icomparable.h"
13 #include "iequatable.h"
14 #include "string_comparison.h"
15 #include "string_split_options.h"
16 #include "types.h"
17 #include "object.h"
18 #include "parse.h"
19 #include "to_string.h"
20 #include "types.h"
21 #include <ostream>
22 #include <string>
23 
25 namespace xtd {
26  class ustring;
27 }
28 template<typename ...args_t>
29 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& format, args_t&& ... args);
30 void __throw_ustring_format_exception();
31 void __throw_ustring_format_exception_close_bracket();
32 void __throw_ustring_format_exception_open_bracket();
33 void __throw_ustring_format_exception_start_colon();
35 
36 namespace xtd {
46  class ustring : public object, public xtd::icomparable<ustring>, public std::basic_string<char> {
47  public:
49 
53  static const ustring empty_string;
55 
57 
60  ustring() noexcept;
63  explicit ustring(const allocator_type& allocator) noexcept;
64 
69  ustring(size_t count, value_type character);
75  ustring(size_t count, value_type character, const allocator_type& allocator);
76 #if defined(__cpp_lib_char8_t)
77  ustring(size_t count, char8 character);
87  ustring(size_t count, char8 character, const allocator_type& allocator);
88 #endif
89  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 
183 #if defined(__cpp_lib_char8_t)
184  ustring(const std::u8string& str) noexcept; // Can't be explicit by design.
190  ustring(const std::u8string& str, const allocator_type& allocator) noexcept;
191 
193  ustring(const char8* str); // Can't be explicit by design.
197  ustring(const char8* str, const allocator_type& allocator);
198 
200  ustring(char8* str); // Can't be explicit by design.
204  ustring(char8* str, const allocator_type& allocator);
205 #endif
206 
209  ustring(const std::u16string& str) noexcept; // Can't be explicit by design.
213  ustring(const std::u16string& str, const allocator_type& allocator) noexcept;
214 
216  ustring(const char16* str); // Can't be explicit by design.
220  ustring(const char16* str, const allocator_type& allocator);
221 
223  ustring(char16* str); // Can't be explicit by design.
227  ustring(char16* str, const allocator_type& allocator);
228 
231  ustring(const std::u32string& str) noexcept; // Can't be explicit by design.
235  ustring(const std::u32string& str, const allocator_type& allocator) noexcept;
236 
238  ustring(const char32* str); // Can't be explicit by design.
242  ustring(const char32* str, const allocator_type& allocator);
243 
245  ustring(char32* str); // Can't be explicit by design.
249  ustring(char32* str, const allocator_type& allocator);
250 
253  ustring(const std::wstring& str) noexcept; // Can't be explicit by design.
257  ustring(const std::wstring& str, const allocator_type& allocator) noexcept;
258 
260  ustring(const wchar* str); // Can't be explicit by design.
264  ustring(const wchar* str, const allocator_type& allocator);
265 
267  ustring(wchar* str); // Can't be explicit by design.
271  ustring(wchar* 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 
296  template<typename string_view_like_t>
297  explicit constexpr ustring(const string_view_like_t& string_view, const allocator_type& allocator = allocator_type()) : std::basic_string<value_type>(string_view, allocator) {}
298 
304  template<typename string_view_like_t>
305  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) {}
306 
309  ustring(std::initializer_list<value_type> il);
313  ustring(std::initializer_list<value_type> il, const allocator_type& allocator);
314 
315 #if defined(__cpp_lib_char8_t)
316  ustring(std::initializer_list<char8> il);
322  ustring(std::initializer_list<char8> il, const allocator_type& allocator);
323 #endif
324 
327  ustring(std::initializer_list<char16> il);
331  ustring(std::initializer_list<char16> il, const allocator_type& allocator);
332 
335  ustring(std::initializer_list<char32> il);
339  ustring(std::initializer_list<char32> il, const allocator_type& allocator);
340 
343  ustring(std::initializer_list<wchar> il);
347  ustring(std::initializer_list<wchar> il, const allocator_type& allocator);
349 
351  /*
352  template<typename type_t>
353  ustring(const type_t& object) : std::basic_string<value_type>(object) {}
354  template<typename type_t>
355  ustring(const type_t& object, const allocator_type& allocator) : std::basic_string<value_type>(object, allocator) {}
356  template<typename type_t>
357  ustring(const type_t& object, size_t index, size_t count) : std::basic_string<value_type>(object, index, count) {}
358  template<typename type_t>
359  ustring(const type_t& object, size_t index, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, index, count, allocator) {}
360  template<typename type_t>
361  ustring(const type_t& object, size_t count) : std::basic_string<value_type>(object, 0, count) {}
362  template<typename type_t>
363  ustring(const type_t& object, size_t count, const allocator_type& allocator) : std::basic_string<value_type>(object, 0, count, allocator) {}
364  */
365 
366  ustring& operator =(const ustring& str) noexcept;
367  ustring& operator =(const std::string& str) noexcept;
368  ustring& operator =(const value_type* str);
369 #if defined(__cpp_lib_char8_t)
370  ustring& operator =(const std::u8string& str) noexcept;
371  ustring& operator =(const char8* str);
372 #endif
373  ustring& operator =(const std::u16string& str) noexcept;
374  ustring& operator =(const char16* str);
375  ustring& operator =(const std::u32string& str) noexcept;
376  ustring& operator =(const char32* str);
377  ustring& operator =(const std::wstring& str) noexcept;
378  ustring& operator =(const wchar* str);
379  ustring& operator =(ustring&& str) noexcept;
380 
381  ustring& operator =(value_type character);
382 #if defined(__cpp_lib_char8_t)
383  ustring& operator =(char8 character);
384 #endif
385  ustring& operator =(char16 character);
386  ustring& operator =(char32 character);
387  ustring& operator =(wchar character);
388  ustring& operator =(const std::initializer_list<value_type>& il);
389 #if defined(__cpp_lib_char8_t)
390  ustring& operator =(const std::initializer_list<char8>& il);
391 #endif
392  ustring& operator =(const std::initializer_list<char16>& il);
393  ustring& operator =(const std::initializer_list<char32>& il);
394  ustring& operator =(const std::initializer_list<wchar>& il);
395  //template<typename type_t>
396  //ustring& operator =(const type_t& object) {return std::basic_string<value_type>::assign(object);}
397 
398  template<typename type_t>
399  ustring operator +(const type_t& object) const {
400  ustring result(*this);
401  result.append(object);
402  return result;
403  }
404 
405  template<typename type_t>
406  ustring operator +(const type_t* object) const {
407  ustring result(*this);
408  result.append(ustring(object));
409  return result;
410  }
411 
412  template<typename type_t>
413  ustring operator +(type_t* object) const {
414  ustring result(*this);
415  result.append(ustring(object));
416  return result;
417  }
418 
419  ustring& operator +=(const ustring& str);
420  ustring& operator +=(const std::string& str);
421  ustring& operator +=(const value_type* str);
422 #if defined(__cpp_lib_char8_t)
423  ustring& operator +=(const std::u8string& str);
424  ustring& operator +=(const char8* str);
425 #endif
426  ustring& operator +=(const std::u16string& str);
427  ustring& operator +=(const char16* str);
428  ustring& operator +=(const std::u32string& str);
429  ustring& operator +=(const char32* str);
430  ustring& operator +=(const std::wstring& str);
431  ustring& operator +=(const wchar* str);
432  ustring& operator +=(value_type character);
433 #if defined(__cpp_lib_char8_t)
434  ustring& operator +=(char8 character);
435 #endif
436  ustring& operator +=(char16 character);
437  ustring& operator +=(char32 character);
438  ustring& operator +=(wchar character);
439  ustring& operator +=(const std::initializer_list<value_type>& il);
440 #if defined(__cpp_lib_char8_t)
441  ustring& operator +=(const std::initializer_list<char8>& il);
442 #endif
443  ustring& operator +=(const std::initializer_list<char16>& il);
444  ustring& operator +=(const std::initializer_list<char32>& il);
445  ustring& operator +=(const std::initializer_list<wchar>& il);
446  template<typename type_t>
447  ustring& operator +=(const type_t& object) {
448  *this = *this + ustring(object);
449  return *this;
450  }
451 
452  bool operator ==(const ustring& other) const;
453  bool operator !=(const ustring& other) const;
454  bool operator ==(const std::string& other) const;
455  bool operator !=(const std::string& other) const;
456  bool operator ==(const value_type* other) const;
457  bool operator !=(const value_type* other) const;
458 #if defined(__cpp_lib_char8_t)
459  bool operator ==(const std::u8string& other) const;
460  bool operator !=(const std::u8string& other) const;
461  bool operator ==(const char8* other) const;
462  bool operator !=(const char8* other) const;
463 #endif
464  bool operator ==(const std::u16string& other) const;
465  bool operator !=(const std::u16string& other) const;
466  bool operator ==(const char16* other) const;
467  bool operator !=(const char16* other) const;
468  bool operator ==(const std::u32string& other) const;
469  bool operator !=(const std::u32string& other) const;
470  bool operator ==(const char32* other) const;
471  bool operator !=(const char32* other) const;
472  bool operator ==(const std::wstring& other) const;
473  bool operator !=(const std::wstring& other) const;
474  bool operator ==(const wchar* other) const;
475  bool operator !=(const wchar* other) const;
476  const value_type& operator [](size_t index);
477  const value_type& operator [](size_t index) const;
478  ustring substr(size_type index = 0, size_type count = npos) const;
480 
482 
488  template<typename object_t>
489  [[deprecated("Replaced by typeof_<object_t>().name() - Will be removed in version 0.4.0")]]
490  static ustring class_name() {return get_class_name(full_class_name<object_t>());}
491 
496  template<typename object_t>
497  [[deprecated("Replaced by typeof_(object).name() - Will be removed in version 0.4.0")]]
498  static ustring class_name(const object_t& object) {return get_class_name(full_class_name(object));}
499 
504  [[deprecated("Replaced by typeof_(info).name() - Will be removed in version 0.4.0")]]
505  static ustring class_name(const std::type_info& info);
506 
507  using std::basic_string<value_type>::compare;
517  static int32 compare(const ustring& str_a, const ustring& str_b) noexcept;
528  static int32 compare(const ustring& str_a, const ustring& str_b, bool ignore_case) noexcept;
529 
540  static int32 compare(const ustring& str_a, const ustring& str_b, xtd::string_comparison comparison_type) noexcept;
553  static int32 compare(const ustring& str_a, size_t index_a, const ustring& str_b, size_t index_b, size_t length) noexcept;
567  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;
581  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;
582 
583  int32 compare_to(const ustring& tzi) const noexcept override;
584 
591  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c, const ustring& str_d) noexcept;
592 
599  template<typename object_a_t, typename object_b_t, typename object_c_t, typename object_d_t>
600  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c, object_d_t obj_d) noexcept {
601  return format("{}{}{}{}", obj_a, obj_b, obj_c, obj_d);
602  }
603 
609  static ustring concat(const ustring& str_a, const ustring& str_b, const ustring& str_c) noexcept;
610 
616  template<typename object_a_t, typename object_b_t, typename object_c_t>
617  static ustring concat(object_a_t obj_a, object_b_t obj_b, object_c_t obj_c) noexcept {
618  return format("{}{}{}", obj_a, obj_b, obj_c);
619  }
620 
625  static ustring concat(const ustring& str_a, const ustring& str_b) noexcept;
626 
631  template<typename object_a_t, typename object_b_t>
632  static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept {
633  return format("{}{}", obj_a, obj_b);
634  }
635 
639  static ustring concat(const std::vector<ustring>& values) noexcept;
640 
642  static ustring concat(const std::vector<const value_type*>& values) noexcept;
643 #if defined(__cpp_lib_char8_t)
644  static ustring concat(const std::vector<const char8*>& values) noexcept;
645 #endif
646  static ustring concat(const std::initializer_list<ustring>& values) noexcept;
647  static ustring concat(const std::initializer_list<const value_type*>& values) noexcept;
648 #if defined(__cpp_lib_char8_t)
649  static ustring concat(const std::initializer_list<const char8*>& values) noexcept;
650 #endif
651 
656  template<typename object_t>
657  static ustring concat(const std::vector<object_t>& args) noexcept {
658  ustring result;
659  for (const auto& arg : args)
660  result += format("{}", arg);
661  return result;
662  }
663 
665  template<typename object_t>
666  static ustring concat(const std::initializer_list<object_t>& args) noexcept {
667  ustring result;
668  for (const auto& arg : args)
669  result += format("{}", arg);
670  return result;
671  }
673 
677  template<typename value_t>
678  static ustring concat(value_t value) noexcept {
679  return format("{}", value);
680  }
681 
701  static ustring demangle(const ustring& name);
702 
706  bool contains(const ustring& value) const noexcept;
707 
708  bool equals(const ustring& tzi) const noexcept;
709 
713  bool ends_with(value_type value) const noexcept;
714 
715 #if defined(__cpp_lib_char8_t)
716  bool ends_with(char8 value) const noexcept;
720 #endif
721 
725  bool ends_with(const ustring& value) const noexcept;
726 
730  bool ends_with(const ustring& value, bool ignore_case) const noexcept;
731 
735  bool ends_with(const ustring& value, xtd::string_comparison comparison_type) const noexcept;
736 
743  template<typename ...args_t>
744  static ustring format(const ustring& fmt, args_t&& ... args) {
745  ustring result;
746  size_t index = 0;
747  std::vector<__format_information<char>> formats;
748  auto begin_format_iterator = fmt.end();
749  auto end_format_iterator = fmt.end();
750  for (auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
751  if (*iterator == '{') {
752  if (++iterator == fmt.end())
753  __throw_ustring_format_exception_open_bracket();
754  if (*iterator == '{')
755  result += *iterator;
756  else {
757  begin_format_iterator = iterator;
758  while (iterator != fmt.end() && *iterator != '}') ++iterator;
759  if (iterator == fmt.end())
760  __throw_ustring_format_exception_open_bracket();
761  end_format_iterator = iterator;
762  __format_information<char> fi;
763  fi.location = result.size();
764  std::string format_str {begin_format_iterator, end_format_iterator};
765  if (format_str.size() == 0)
766  fi.index = index++;
767  else {
768  size_t index_alignment_separator = ustring(format_str).index_of(',');
769  size_t index_format_separator = ustring(format_str).index_of(u':');
770 
771  if (index_alignment_separator != std::string::npos && index_format_separator != std::string::npos && index_alignment_separator > index_format_separator)
772  index_alignment_separator = std::string::npos;
773 
774  if (index_alignment_separator != std::string::npos)
775  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);
776 
777  if (index_format_separator != std::string::npos)
778  fi.format = format_str.substr(index_format_separator + 1);
779 
780  if (index_alignment_separator == 0 || index_format_separator == 0)
781  fi.index = index++;
782  else {
783  std::string index_str;
784  if (index_alignment_separator != std::string::npos)
785  index_str = format_str.substr(0, index_alignment_separator);
786  else if (index_format_separator != std::string::npos)
787  index_str = format_str.substr(0, index_format_separator);
788  else
789  index_str = std::move(format_str);
790  try {
791  for (auto c : index_str)
792  if (!std::isdigit(c)) __throw_ustring_format_exception_start_colon();
793  fi.index = std::stoi(index_str);
794  } catch (...) {
795  __throw_ustring_format_exception_start_colon();
796  }
797  }
798  }
799  formats.push_back(fi);
800  }
801  } else if (*iterator == '}') {
802  if (++iterator == fmt.end()) {
803  __throw_ustring_format_exception_close_bracket();
804  break;
805  }
806  if (*iterator != '}') {
807  __throw_ustring_format_exception_close_bracket();
808  break;
809  }
810  result += *iterator;
811  } else
812  result += *iterator;
813  }
814 
815  __ustring_extract_format_arg(result, formats, std::forward<args_t>(args)...);
816  return result.c_str();
817  }
818 
823  template<typename object_t>
824  [[deprecated("Replaced by typeof_<object_t>().full_name() - Will be removed in version 0.4.0")]]
825  static ustring full_class_name() {return demangle(typeid(object_t).name());}
826 
831  template<typename object_t>
832  [[deprecated("Replaced by typeof_(object).full_name() - Will be removed in version 0.4.0")]]
833  static ustring full_class_name(const object_t& object) {return demangle(typeid(object).name());}
834 
839  [[deprecated("Replaced by typeof_(info).full_name() - Will be removed in version 0.4.0")]]
840  static ustring full_class_name(const std::type_info& info);
841 
844  size_t get_hash_code() const noexcept override;
845 
849  size_t index_of(value_type value) const noexcept;
850 
854  size_t index_of(const ustring& value) const noexcept;
855 
860  size_t index_of(value_type value, size_t start_index) const noexcept;
861 
866  size_t index_of(const ustring& value, size_t start_index) const noexcept;
867 
873  size_t index_of(value_type value, size_t start_index, size_t count) const noexcept;
874 
880  size_t index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
881 
885  size_t index_of_any(const std::vector<value_type>& values) const noexcept;
886 
891  size_t index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
892 
898  size_t index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
899 
901  size_t index_of_any(const std::initializer_list<value_type>& values) const noexcept;
902  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
903  size_t index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
905 
912  ustring insert(size_t start_index, const ustring& value) const noexcept;
913 
917  [[deprecated("Replaced by xtd::ustring::is_empty(const xtd::ustring&) - Will be removed in version 0.4.0")]]
918  bool is_empty() const noexcept {return is_empty(*this);}
919 
923  static bool is_empty(const xtd::ustring& string) noexcept;
924 
931  template<typename collection_t>
932  static ustring join(const ustring separator, const collection_t& values) noexcept {return join(separator, values, 0, values.size());}
933 
941  template<typename collection_t>
942  static ustring join(const ustring& separator, const collection_t& values, size_t index) noexcept {return join(separator, values, index, values.size() - index);}
943 
952  template<typename collection_t>
953  static ustring join(const ustring& separator, const collection_t& values, size_t index, size_t count) noexcept {
954  size_t i = 0;
955  ustring result;
956  for (const auto& item : values) {
957  if (i >= index) {
958  if (i != index) result += separator;
959  result += format("{}", item);
960  }
961  if (++i >= index + count) break;
962  }
963  return result;
964  }
965 
967  template<typename value_t>
968  static ustring join(const ustring& separator, const std::initializer_list<value_t>& values) noexcept {return join(separator, std::vector<value_t>(values));}
969  template<typename value_t>
970  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);}
971  template<typename value_t>
972  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);}
974 
978  size_t last_index_of(value_type value) const noexcept;
979 
983  size_t last_index_of(const ustring& value) const noexcept;
984 
989  size_t last_index_of(value_type value, size_t start_index) const noexcept;
990 
995  size_t last_index_of(const ustring& value, size_t start_index) const noexcept;
996 
1003  size_t last_index_of(value_type value, size_t start_index, size_t count) const noexcept;
1004 
1010  size_t last_index_of(const ustring& value, size_t start_index, size_t count) const noexcept;
1011 
1015  size_t last_index_of_any(const std::vector<value_type>& values) const noexcept;
1016 
1021  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index) const noexcept;
1022 
1028  size_t last_index_of_any(const std::vector<value_type>& values, size_t start_index, size_t count) const noexcept;
1029 
1031  size_t last_index_of_any(const std::initializer_list<value_type>& values) const noexcept;
1032  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index) const noexcept;
1033  size_t last_index_of_any(const std::initializer_list<value_type>& values, size_t start_index, size_t count) const noexcept;
1035 
1041  ustring pad_left(size_t total_width) const noexcept;
1042 
1049  ustring pad_left(size_t total_width, value_type padding_char) const noexcept;
1050 
1056  ustring pad_right(size_t total_width) const noexcept;
1057 
1064  ustring pad_right(size_t total_width, value_type padding_char) const noexcept;
1065 
1070  ustring quoted() const;
1076  ustring quoted(value_type delimiter, value_type escape) const;
1077 
1081  template<typename value_t>
1082  static value_t parse(const ustring& str) {
1083  return xtd::parse<value_t>(str);
1084  }
1085 
1089  ustring remove(size_t start_index) const noexcept;
1090 
1095  ustring remove(size_t start_index, size_t count) const noexcept;
1096 
1101  ustring replace(value_type old_char, value_type new_char) const noexcept;
1102 
1108  ustring replace(const ustring& old_string, const ustring& new_string) const noexcept;
1109 
1121  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count, string_split_options options) const noexcept;
1122 
1127  std::vector<ustring> split() const noexcept;
1128 
1134  std::vector<ustring> split(const std::vector<value_type>& separators) const noexcept;
1135 
1152  std::vector<ustring> split(const std::vector<value_type>& separators, string_split_options options) const noexcept;
1153 
1162  std::vector<ustring> split(const std::vector<value_type>& separators, size_t count) const noexcept;
1163 
1223  template<typename ... args_t>
1224  static ustring sprintf(const ustring& fmt, args_t&& ... args) noexcept {return __sprintf(fmt.c_str(), convert_param(std::forward<args_t>(args)) ...);}
1225 
1230  bool starts_with(value_type value) const noexcept;
1231 
1237  bool starts_with(value_type value, bool ignore_case) const noexcept;
1238 
1243  bool starts_with(const ustring& value) const noexcept;
1244 
1250  bool starts_with(const ustring& value, bool ignore_case) const noexcept;
1251 
1256  ustring substring(size_t start_index) const noexcept;
1257 
1262  ustring substring(size_t start_index, size_t length) const noexcept;
1263 
1266  std::vector<value_type> to_array() const noexcept;
1267 
1271  std::vector<value_type> to_array(size_t start_index) const noexcept;
1272 
1277  std::vector<value_type> to_array(size_t start_index, size_t length) const noexcept;
1278 
1281  ustring to_lower() const noexcept;
1282 
1283  //ustring to_string() const noexcept override;
1284  ustring to_string() const noexcept override;
1285 
1288  ustring to_title_case() const noexcept;
1289 
1292  ustring to_upper() const noexcept;
1293 
1298  ustring trim() const noexcept;
1299 
1304  ustring trim(value_type trim_char) const noexcept;
1305 
1310  ustring trim(const std::vector<value_type>& trim_chars) const noexcept;
1311 
1316  ustring trim_end() const noexcept;
1317 
1322  ustring trim_end(value_type trim_char) const noexcept;
1323 
1328  ustring trim_end(const std::vector<value_type>& trim_chars) const noexcept;
1329 
1334  ustring trim_start() const noexcept;
1335 
1340  ustring trim_start(value_type trim_char) const noexcept;
1341 
1346  ustring trim_start(const std::vector<value_type>& trim_chars) const noexcept;
1347 
1352  template<typename value_t>
1353  static bool try_parse(const ustring& str, value_t& value) noexcept {
1354  try {
1355  value = parse<value_t>(str);
1356  return true;
1357  } catch (...) {
1358  return false;
1359  }
1360  }
1362 
1364  friend std::ostream& operator <<(std::ostream& stream, const ustring& str) {return stream << str.c_str();}
1365  friend std::istream& operator >>(std::istream& stream, ustring& str) {
1366  std::string s;
1367  stream >> s;
1368  str = s;
1369  return stream;
1370  }
1371 
1372  friend ustring operator +(const ustring& str_a, const ustring& str_b) {
1373  ustring result = str_a;
1374  result.append(str_b);
1375  return result;
1376  }
1377 
1378  friend ustring operator +(const ustring& str_a, const std::string& str_b) {
1379  ustring result = str_a;
1380  result.append(ustring(str_b));
1381  return result;
1382  }
1383 
1384  friend ustring operator +(const ustring& str_a, const value_type* str_b) {
1385  ustring result = str_a;
1386  result.append(ustring(str_b));
1387  return result;
1388  }
1389 
1390 #if defined(__cpp_lib_char8_t)
1391  friend ustring operator +(const ustring& str_a, const std::u8string& str_b) {
1392  ustring result = str_a;
1393  result.append(ustring(str_b));
1394  return result;
1395  }
1396 
1397  friend ustring operator +(const ustring& str_a, const char8* str_b) {
1398  ustring result = str_a;
1399  result.append(ustring(str_b));
1400  return result;
1401  }
1402 #endif
1403 
1404  friend ustring operator +(const ustring& str_a, const std::u16string& str_b) {
1405  ustring result = str_a;
1406  result.append(ustring(str_b));
1407  return result;
1408  }
1409 
1410  friend ustring operator +(const ustring& str_a, const char16* str_b) {
1411  ustring result = str_a;
1412  result.append(ustring(str_b));
1413  return result;
1414  }
1415 
1416  friend ustring operator +(const ustring& str_a, const std::u32string& str_b) {
1417  ustring result = str_a;
1418  result.append(ustring(str_b));
1419  return result;
1420  }
1421 
1422  friend ustring operator +(const ustring& str_a, const char32* str_b) {
1423  ustring result = str_a;
1424  result.append(ustring(str_b));
1425  return result;
1426  }
1427 
1428  friend ustring operator +(const ustring& str_a, const std::wstring& str_b) {
1429  ustring result = str_a;
1430  result.append(ustring(str_b));
1431  return result;
1432  }
1433 
1434  friend ustring operator +(const ustring& str_a, const wchar* str_b) {
1435  ustring result = str_a;
1436  result.append(ustring(str_b));
1437  return result;
1438  }
1439 
1440  friend ustring operator +(const ustring& str_a, value_type character) {
1441  ustring result = str_a;
1442  result.append(ustring(1, character));
1443  return result;
1444  }
1445 
1446 #if defined(__cpp_lib_char8_t)
1447  friend ustring operator +(const ustring& str_a, char8 character) {
1448  ustring result = str_a;
1449  result.append(ustring(1, character));
1450  return result;
1451  }
1452 #endif
1453 
1454  friend ustring operator +(const ustring& str_a, char16 character) {
1455  ustring result = str_a;
1456  result.append(ustring(1, character));
1457  return result;
1458  }
1459 
1460  friend ustring operator +(const ustring& str_a, char32 character) {
1461  ustring result = str_a;
1462  result.append(ustring(1, character));
1463  return result;
1464  }
1465 
1466  friend ustring operator +(const ustring& str_a, wchar character) {
1467  ustring result = str_a;
1468  result.append(ustring(1, character));
1469  return result;
1470  }
1471 
1472  friend ustring operator +(const ustring& str_a, const std::initializer_list<value_type>& il) {
1473  ustring result = str_a;
1474  result.append(ustring(il));
1475  return result;
1476  }
1477 
1478 #if defined(__cpp_lib_char8_t)
1479  friend ustring operator +(const ustring& str_a, const std::initializer_list<char8>& il) {
1480  ustring result = str_a;
1481  result.append(ustring(il));
1482  return result;
1483  }
1484 #endif
1485 
1486  friend ustring operator +(const ustring& str_a, const std::initializer_list<char16>& il) {
1487  ustring result = str_a;
1488  result.append(ustring(il));
1489  return result;
1490  }
1491 
1492  friend ustring operator +(const ustring& str_a, const std::initializer_list<char32>& il) {
1493  ustring result = str_a;
1494  result.append(ustring(il));
1495  return result;
1496  }
1497 
1498  friend ustring operator +(const ustring& str_a, const std::initializer_list<wchar>& il) {
1499  ustring result = str_a;
1500  result.append(ustring(il));
1501  return result;
1502  }
1503 
1504  friend ustring operator +(const std::string& str_a, const ustring& str_b) {
1505  ustring result(str_a);
1506  result.append(str_b);
1507  return result;
1508  }
1509 
1510  friend ustring operator +(const value_type* str_a, const ustring& str_b) {
1511  ustring result(str_a);
1512  result.append(str_b);
1513  return result;
1514  }
1515 
1516 #if defined(__cpp_lib_char8_t)
1517  friend ustring operator +(const std::u8string& str_a, const ustring& str_b) {
1518  ustring result(str_a);
1519  result.append(str_b);
1520  return result;
1521  }
1522 
1523  friend ustring operator +(const char8* str_a, const ustring& str_b) {
1524  ustring result(str_a);
1525  result.append(str_b);
1526  return result;
1527  }
1528 #endif
1529 
1530  friend ustring operator +(const std::u16string& str_a, const ustring& str_b) {
1531  ustring result(str_a);
1532  result.append(str_b);
1533  return result;
1534  }
1535 
1536  friend ustring operator +(const char16* str_a, const ustring& str_b) {
1537  ustring result(str_a);
1538  result.append(str_b);
1539  return result;
1540  }
1541 
1542  friend ustring operator +(const std::u32string& str_a, const ustring& str_b) {
1543  ustring result(str_a);
1544  result.append(str_b);
1545  return result;
1546  }
1547 
1548  friend ustring operator +(const char32* str_a, const ustring& str_b) {
1549  ustring result(str_a);
1550  result.append(str_b);
1551  return result;
1552  }
1553 
1554  friend ustring operator +(const std::wstring& str_a, const ustring& str_b) {
1555  ustring result(str_a);
1556  result.append(str_b);
1557  return result;
1558  }
1559 
1560  friend ustring operator +(const wchar* str_a, const ustring& str_b) {
1561  ustring result(str_a);
1562  result.append(str_b);
1563  return result;
1564  }
1565 
1566  friend ustring operator +(value_type character, const ustring& str_b) {
1567  ustring result(1, character);
1568  result.append(str_b);
1569  return result;
1570  }
1571 
1572 #if defined(__cpp_lib_char8_t)
1573  friend ustring operator +(char8 character, const ustring& str_b) {
1574  ustring result(1, character);
1575  result.append(str_b);
1576  return result;
1577  }
1578 #endif
1579 
1580  friend ustring operator +(char16 character, const ustring& str_b) {
1581  ustring result(1, character);
1582  result.append(str_b);
1583  return result;
1584  }
1585 
1586  friend ustring operator +(char32 character, const ustring& str_b) {
1587  ustring result(1, character);
1588  result.append(str_b);
1589  return result;
1590  }
1591 
1592  friend ustring operator +(wchar character, const ustring& str_b) {
1593  ustring result(1, character);
1594  result.append(str_b);
1595  return result;
1596  }
1597 
1598  friend ustring operator +(const std::initializer_list<value_type>& il, const ustring& str_b) {
1599  ustring result(il);
1600  result.append(str_b);
1601  return result;
1602  }
1603 
1604 #if defined(__cpp_lib_char8_t)
1605  friend ustring operator +(const std::initializer_list<char8>& il, const ustring& str_b) {
1606  ustring result(il);
1607  result.append(str_b);
1608  return result;
1609  }
1610 #endif
1611 
1612  friend ustring operator +(const std::initializer_list<char16>& il, const ustring& str_b) {
1613  ustring result(il);
1614  result.append(str_b);
1615  return result;
1616  }
1617 
1618  friend ustring operator +(const std::initializer_list<char32>& il, const ustring& str_b) {
1619  ustring result(il);
1620  result.append(str_b);
1621  return result;
1622  }
1623 
1624  friend ustring operator +(const std::initializer_list<wchar>& il, const ustring& str_b) {
1625  ustring result(il);
1626  result.append(str_b);
1627  return result;
1628  }
1630 
1631  private:
1632  template<typename arg_t>
1633  static auto convert_param(arg_t&& arg) noexcept {
1634  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();
1635  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();
1636  else if constexpr(std::is_same<std::remove_cv_t<std::remove_reference_t<arg_t>>, xtd::ustring>::value) return std::forward<arg_t>(arg).c_str();
1637  else return std::forward<arg_t>(arg);
1638  }
1639 
1640  static ustring get_class_name(const ustring& full_name);
1641 
1642  using std::basic_string<value_type>::assign;
1643  using std::basic_string<value_type>::reserve;
1644  using std::basic_string<value_type>::shrink_to_fit;
1645  using std::basic_string<value_type>::clear;
1646  using std::basic_string<value_type>::erase;
1647  using std::basic_string<value_type>::push_back;
1648  using std::basic_string<value_type>::pop_back;
1649  using std::basic_string<value_type>::append;
1650  using std::basic_string<value_type>::replace;
1651  using std::basic_string<value_type>::resize;
1652  };
1653 
1657  ustring to_ustring(int val);
1661  ustring to_ustring(unsigned val);
1665  ustring to_ustring(long val);
1669  ustring to_ustring(unsigned long val);
1673  ustring to_ustring(long long val);
1677  ustring to_ustring(unsigned long long val);
1681  ustring to_ustring(float val);
1685  ustring to_ustring(double val);
1689  ustring to_ustring(long double val);
1693  template <typename type_t>
1694  ustring to_ustring(type_t val) {
1695  return ustring::format("{}", val);
1696  }
1697 }
1698 
1700 template<typename arg_t>
1701 void __ustring_extract_format_arg(std::string& fmt, size_t& index, std::vector<__format_information<char>>& formats, arg_t&& arg) {
1702  size_t offset = 0;
1703  for (auto& format : formats) {
1704  format.location += offset;
1705  if (format.index == index) {
1706  xtd::ustring arg_str = format.format.empty() ? __format_stringer<char, arg_t>(arg) : xtd::to_string(arg, format.format);
1707 
1708  if (!format.alignment.empty()) {
1709  xtd::int32 alignment = 0;
1710  try {
1711  alignment = std::stoi(format.alignment);
1712  } catch (...) {
1713  __throw_ustring_format_exception();
1714  }
1715  if (alignment > 0) arg_str = arg_str.pad_left(alignment);
1716  else if (alignment < 0) arg_str = arg_str.pad_right(-alignment);
1717  }
1718  fmt.insert(format.location, arg_str);
1719  offset += arg_str.size();
1720  }
1721  }
1722  ++index;
1723 }
1724 
1725 template <typename ...args_t>
1726 void __xtd_ustrings_unused(args_t&& ... args) {}
1727 
1728 template<typename ...args_t>
1729 void __ustring_extract_format_arg(xtd::ustring& fmt, std::vector<__format_information<char>>& formats, args_t&& ... args) {
1730  size_t index = 0;
1731  (__ustring_extract_format_arg(fmt, index, formats, args), ...);
1732  __xtd_ustrings_unused(index); // workaround to mute gcc warning: unused-but-set-variable
1733 }
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:833
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:657
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:14
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:20
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:297
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:953
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:14
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:305
static ustring concat(object_a_t obj_a, object_b_t obj_b) noexcept
Concatenates two specified instances of object.
Definition: ustring.h:632
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
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:1063
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:1224
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:498
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:1082
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:918
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:617
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:600
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:1353
The ESC (ESCAPE) key.
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::string_split_options enum class.
static ustring class_name()
Gets the class name of the object_t.
Definition: ustring.h:490
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:85
ustring quoted() const
Allows insertion and extraction of quoted strings, such as the ones found in CSV or XML...
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:825
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:942
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:744
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:53
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:62
ustring to_ustring(int val)
Converts a signed integer to xtd::ustring.
char16_t char16
Represents a 16-bit unicode character.
Definition: types.h:74
static ustring concat(value_t value) noexcept
Creates the string representation of a specified object.
Definition: ustring.h:678
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:932
ustring to_title_case() const noexcept
Converts the current string to title case (except for words that are entirely in uppercase, which are considered to be acronyms).
static ustring demangle(const ustring &name)
Gets demangled string of name,.
wchar_t wchar
Represents a wide character.
Definition: types.h:284