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