6#if !defined(__XTD_BASIC_STRING_INTERNAL__)
7#error "Do not include this file: Internal use only. Include <xtd/basic_string> or <xtd/basic_string.hpp> instead."
15template<
class char_t,
class traits_t,
class allocator_t>
18template<
class char_t,
class traits_t,
class allocator_t>
20 return index_of_any(values, 0,
length());
23template<
class char_t,
class traits_t,
class allocator_t>
25 return index_of_any(values, start_index,
length() - start_index);
28template<
class char_t,
class traits_t,
class allocator_t>
32 for (
const auto& item :
self_) {
33 if (index++ < start_index)
continue;
34 if (index - 1 > start_index + count)
break;
35 if (std::find(values.
begin(), values.
end(), item) != values.
end())
return index - 1;
40template<
class char_t,
class traits_t,
class allocator_t>
45template<
class char_t,
class traits_t,
class allocator_t>
50template<
class char_t,
class traits_t,
class allocator_t>
55template<
class char_t,
class traits_t,
class allocator_t>
57 return last_index_of_any(values, 0,
length());
60template<
class char_t,
class traits_t,
class allocator_t>
62 return last_index_of_any(values, start_index,
length() - start_index);
65template<
class char_t,
class traits_t,
class allocator_t>
69 for (
auto iterator = chars().
crbegin(); iterator != chars().crend(); ++iterator) {
70 if (index-- > start_index + count)
continue;
71 if (index + 1 < start_index)
break;
72 if (std::find(values.
begin(), values.
end(), *iterator) != values.
end())
return index + 1;
77template<
class char_t,
class traits_t,
class allocator_t>
82template<
class char_t,
class traits_t,
class allocator_t>
87template<
class char_t,
class traits_t,
class allocator_t>
92template<
class char_t,
class traits_t,
class allocator_t>
97template<
class char_t,
class traits_t,
class allocator_t>
102template<
class char_t,
class traits_t,
class allocator_t>
107template<
class char_t,
class traits_t,
class allocator_t>
112template<
class char_t,
class traits_t,
class allocator_t>
117template<
class char_t,
class traits_t,
class allocator_t>
122template<
class char_t,
class traits_t,
class allocator_t>
124 return split(separators, std::numeric_limits<xtd::size>::max(), options);
127template<
class char_t,
class traits_t,
class allocator_t>
132template<
class char_t,
class traits_t,
class allocator_t>
134 if (count == 0)
return {};
135 if (count == 1)
return {
self_};
137 auto result = std::vector<basic_string> {};
138 auto sub_string = basic_string {};
139 auto split_char_separators = separators.length() == 0 ? default_split_separators : separators;
140 for (
auto it = chars().
begin(); it != chars().end(); ++it) {
141 auto is_separator = std::find(split_char_separators.begin(), split_char_separators.end(), *it) != split_char_separators.end();
142 if (!is_separator) sub_string.chars_.append(basic_string(1, *it));
143 auto is_last = (it + 1 == chars().end());
144 auto should_add = is_last || is_separator;
147 if (should_add && keep_empty) {
148 if (result.size() == count - 1) {
149 result.push_back(sub_string + basic_string(chars().c_str(), it - chars().
begin() + (is_separator ? 0 : 1),
length() - (it - chars().
begin()) + (is_separator ? 0 : 1)));
152 result.push_back(sub_string);
153 sub_string.chars_.clear();
162template<
class char_t,
class traits_t,
class allocator_t>
167template<
class char_t,
class traits_t,
class allocator_t>
172template<
class char_t,
class traits_t,
class allocator_t>
174 if (start_index >=
self_.length())
return {};
175 if (start_index + length >=
self_.length())
return {chars().begin() + start_index, chars().end()};
176 return {chars().begin() + start_index, chars().begin() + start_index +
length};
179template<
class char_t,
class traits_t,
class allocator_t>
184template<
class char_t,
class traits_t,
class allocator_t>
186 return to_array(start_index, length);
189template<
class char_t,
class traits_t,
class allocator_t>
191 auto words = split({
' '});
192 for (
auto& word : words)
193 if (
word.length() && word !=
word.to_upper())
word =
static_cast<value_type
>(toupper(word[0])) +
word.substring(1).to_lower();
194 return basic_string::join(
" ", words);
197template<
class char_t,
class traits_t,
class allocator_t>
202template<
class char_t,
class traits_t,
class allocator_t>
204 return trim_start(trim_chars).trim_end(trim_chars);
207template<
class char_t,
class traits_t,
class allocator_t>
212template<
class char_t,
class traits_t,
class allocator_t>
215 auto result = chars_;
216 while (std::find(trim_chars.begin(), trim_chars.end(), result[result.size() - 1]) != trim_chars.end())
217 result.erase(result.size() - 1, 1);
221template<
class char_t,
class traits_t,
class allocator_t>
224template<
class char_t,
class traits_t,
class allocator_t>
227 auto result = chars_;
228 while (std::find(trim_chars.begin(), trim_chars.end(), result[0]) != trim_chars.end())
233template<
class char_t,
class traits_t,
class allocator_t>
235 auto result = basic_string::empty_string;
236 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
240template<
class char_t,
class traits_t,
class allocator_t>
242 auto result = basic_string::empty_string;
243 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
247template<
class char_t,
class traits_t,
class allocator_t>
248template<
class other_
char_t>
250 auto result = basic_string::empty_string;
251 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
256template<
class char_t,
class traits_t,
class allocator_t>
257template<
class object_t>
260 for (
const auto& arg : args)
261 result +=
format(
"{}", arg);
265template<
class char_t,
class traits_t,
class allocator_t>
266template<
class ...args_t>
268 return format(std::locale {}, fmt, std::forward<args_t>(args)...);
271template<
class char_t,
class traits_t,
class allocator_t>
272template<
class ...args_t>
274 auto result = basic_string<char> {};
276 auto formats = std::vector<__format_information<char>> {};
277 auto begin_format_iterator = fmt.end();
278 auto end_format_iterator = fmt.end();
279 for (
auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
280 if (*iterator ==
'{') {
281 if (++iterator == fmt.end())
283 if (*iterator ==
'{')
286 begin_format_iterator = iterator;
287 while (iterator != fmt.end() && *iterator !=
'}') ++iterator;
288 if (iterator == fmt.end())
290 end_format_iterator = iterator;
291 __format_information<char> fi;
292 fi.location = result.length();
293 auto format_str = std::basic_string<char> {begin_format_iterator, end_format_iterator};
294 if (format_str.length() == 0)
297 xtd::size index_alignment_separator = basic_string(format_str).index_of(
',');
298 xtd::size index_format_separator = basic_string(format_str).index_of(u
':');
300 if (index_alignment_separator != std::basic_string<char>::npos && index_format_separator != std::basic_string<char>::npos && index_alignment_separator > index_format_separator)
301 index_alignment_separator = std::basic_string<char>::npos;
303 if (index_alignment_separator != basic_string<char_t>::npos)
304 fi.alignment = format_str.substr(index_alignment_separator + 1, index_format_separator != std::basic_string<char>::npos ? index_format_separator - index_alignment_separator - 1 : std::basic_string<char>::npos);
306 if (index_format_separator != basic_string<char>::npos)
307 fi.format = format_str.substr(index_format_separator + 1);
309 if (index_alignment_separator == 0 || index_format_separator == 0)
312 auto index_str = std::basic_string<char> {};
313 if (index_alignment_separator != basic_string<char>::npos)
314 index_str = format_str.substr(0, index_alignment_separator);
315 else if (index_format_separator != basic_string<char>::npos)
316 index_str = format_str.substr(0, index_format_separator);
318 index_str = std::move(format_str);
320 for (
auto c : index_str)
322 fi.index = std::stoi(index_str);
328 formats.push_back(fi);
330 }
else if (*iterator ==
'}') {
331 if (++iterator == fmt.end())
333 if (*iterator !=
'}')
340 __basic_string_extract_format_arg(loc, result, formats, std::forward<args_t>(args)...);
341 return result.chars().c_str();
344template<
class char_t,
class traits_t,
class allocator_t>
345template<
class value_t>
350template<
class char_t,
class traits_t,
class allocator_t>
351template<
class value_t>
356template<
class char_t,
class traits_t,
class allocator_t>
357template<
class value_t>
362template<
class char_t,
class traits_t,
class allocator_t>
365template<
class char_t,
class traits_t,
class allocator_t>
368template<
class char_t,
class traits_t,
class allocator_t>
372void __basic_string_extract_format_arg(
const std::locale& loc, std::basic_string<char>& fmt,
xtd::size& index, std::vector<__format_information<char >> & formats, arg_t&& arg) {
375 for (
auto& format : formats) {
376 format.location += offset;
377 if (
format.index == index) {
381 if (!
format.alignment.empty()) {
384 alignment = std::stoi(
format.alignment);
388 if (alignment > 0) arg_str = arg_str.to_u32string().
pad_left(alignment);
389 else if (alignment < 0) arg_str = arg_str.to_u32string().
pad_right(-alignment);
391 fmt.insert(
format.location, arg_str);
392 offset += arg_str.length();
398template<
class ...args_t>
399void __basic_string_extract_format_arg(
const std::locale& loc,
xtd::basic_string<char>& fmt, std::vector<__format_information<char >> & formats, args_t&&... args) {
401 (__basic_string_extract_format_arg(loc,
const_cast<std::basic_string<char>&
> (fmt.chars()), index, formats, args), ...);
406template<
class target_t,
class source_t>
407inline std::basic_string<target_t> __xtd_convert_to_string(std::basic_string<source_t>&& str)
noexcept {
408 auto out = std::basic_string<target_t> {};
410 for (
const auto& character : str) {
411 if (character >= 0xd800 && character <= 0xdbff)
412 codepoint = ((
character - 0xd800) << 10) + 0x10000;
414 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
417 if (codepoint <= 0x7f)
418 out.append(1,
static_cast<target_t
>(codepoint));
419 else if (codepoint <= 0x7ff) {
420 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
421 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
422 }
else if (codepoint <= 0xffff) {
423 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
424 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
425 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
427 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
428 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
429 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
430 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
442inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(std::basic_string<char>&& str)
noexcept {
443 auto out = std::basic_string<xtd::char16> {};
445 auto expected_bytes = 0;
446 auto str_ptr = str.data();
448 while (*str_ptr != 0) {
449 auto ch =
static_cast<unsigned char>(*str_ptr++);
451 if (expected_bytes == 0) {
456 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
457 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
458 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
461 out.push_back(0xfffd);
466 if ((ch & 0xc0) != 0x80) {
468 out.push_back(0xfffd);
473 codepoint = (codepoint << 6) | (ch & 0x3f);
478 if (expected_bytes == 0) {
479 if (codepoint > 0x10ffff) codepoint = 0xfffd;
481 if (codepoint > 0xffff) {
483 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
484 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
487 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
488 else out.push_back(0xfffd);
493 if (expected_bytes != 0) out.push_back(0xfffd);
501inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
502 auto out = std::basic_string<xtd::char16> {};
504 auto expected_bytes = 0;
505 auto str_ptr = str.data();
507 while (*str_ptr != 0) {
508 auto ch =
static_cast<unsigned char>(*str_ptr++);
510 if (expected_bytes == 0) {
515 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
516 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
517 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
520 out.push_back(0xfffd);
525 if ((ch & 0xc0) != 0x80) {
527 out.push_back(0xfffd);
532 codepoint = (codepoint << 6) | (ch & 0x3f);
537 if (expected_bytes == 0) {
538 if (codepoint > 0x10ffff) codepoint = 0xfffd;
540 if (codepoint > 0xffff) {
542 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
543 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
546 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
547 else out.push_back(0xfffd);
552 if (expected_bytes != 0) out.push_back(0xfffd);
560inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(std::basic_string<char>&& str)
noexcept {
561 auto out = std::basic_string<xtd::wchar> {};
563 auto expected_bytes = 0;
564 auto str_ptr = str.data();
566 while (*str_ptr != 0) {
567 auto ch =
static_cast<unsigned char>(*str_ptr++);
569 if (expected_bytes == 0) {
574 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
575 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
576 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
578 out.push_back(0xfffd);
583 if ((ch & 0xc0) != 0x80) {
585 out.push_back(0xfffd);
590 codepoint = (codepoint << 6) | (ch & 0x3f);
595 if (expected_bytes == 0) {
596 if (codepoint > 0x10ffff) codepoint = 0xfffd;
600 out.push_back(
static_cast<xtd::wchar>(codepoint));
603 if (codepoint > 0xffff) {
604 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
605 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
608 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
609 out.push_back(
static_cast<xtd::wchar>(codepoint));
612 out.push_back(0xfffd);
619 if (expected_bytes != 0) out.push_back(0xfffd);
627inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
628 auto out = std::basic_string<xtd::wchar> {};
630 auto expected_bytes = 0;
631 auto str_ptr = str.data();
633 while (*str_ptr != 0) {
634 auto ch =
static_cast<unsigned char>(*str_ptr++);
636 if (expected_bytes == 0) {
641 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
642 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
643 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
645 out.push_back(0xfffd);
650 if ((ch & 0xc0) != 0x80) {
652 out.push_back(0xfffd);
657 codepoint = (codepoint << 6) | (ch & 0x3f);
662 if (expected_bytes == 0) {
663 if (codepoint > 0x10ffff) codepoint = 0xfffd;
667 out.push_back(
static_cast<xtd::wchar>(codepoint));
670 if (codepoint > 0xffff) {
671 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
672 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
675 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
676 out.push_back(
static_cast<xtd::wchar>(codepoint));
679 out.push_back(0xfffd);
686 if (expected_bytes != 0) out.push_back(0xfffd);
694inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(std::basic_string<char>&& str)
noexcept {
695 auto out = std::basic_string<xtd::char32> {};
697 auto expected_bytes = 0;
698 auto str_ptr = str.data();
700 while (*str_ptr != 0) {
701 auto ch =
static_cast<unsigned char>(*str_ptr++);
703 if (expected_bytes == 0) {
707 out.push_back(
static_cast<xtd::char32>(codepoint));
708 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
709 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
710 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
711 else out.push_back(0xfffd);
714 if ((ch & 0xc0) != 0x80) {
716 out.push_back(0xfffd);
721 codepoint = (codepoint << 6) | (ch & 0x3f);
724 if (expected_bytes == 0) {
726 if (codepoint > 0x10ffff) codepoint = 0xfffd;
727 out.push_back(
static_cast<xtd::char32>(codepoint));
733 if (expected_bytes != 0) out.push_back(0xfffd);
741inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
742 auto out = std::basic_string<xtd::char32> {};
744 auto expected_bytes = 0;
745 auto str_ptr = str.data();
747 while (*str_ptr != 0) {
748 auto ch =
static_cast<unsigned char>(*str_ptr++);
750 if (expected_bytes == 0) {
754 out.push_back(
static_cast<xtd::char32>(codepoint));
755 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
756 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
757 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
758 else out.push_back(0xfffd);
761 if ((ch & 0xc0) != 0x80) {
763 out.push_back(0xfffd);
768 codepoint = (codepoint << 6) | (ch & 0x3f);
771 if (expected_bytes == 0) {
773 if (codepoint > 0x10ffff) codepoint = 0xfffd;
774 out.push_back(
static_cast<xtd::char32>(codepoint));
780 if (expected_bytes != 0) out.push_back(0xfffd);
785inline std::basic_string<char> __xtd_convert_to_string<char, char>(std::basic_string<char>&& str)
noexcept {
786 return std::move(str);
790inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
791 return std::move(str);
795inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
796 return std::move(str);
800inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
801 return std::move(str);
805inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
806 return std::move(str);
810inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(std::basic_string<char>&& str)
noexcept {
811 return std::basic_string<xtd::char8> {
reinterpret_cast<const xtd::char8*
>(str.c_str())};
815inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
816 return std::basic_string<char> {
reinterpret_cast<const char*
>(str.c_str())};
820inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
821 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
825inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
826 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
830inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
831 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
835inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
836 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
840inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
841 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
845inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
846 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
849template<
class target_t,
class source_t>
850inline std::basic_string<target_t> __xtd_convert_to_string(
const std::basic_string<source_t>& str)
noexcept {
851 auto out = std::basic_string<target_t> {};
853 for (
const auto& character : str) {
854 if (character >= 0xd800 && character <= 0xdbff)
855 codepoint = ((
character - 0xd800) << 10) + 0x10000;
857 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
860 if (codepoint <= 0x7f)
861 out.append(1,
static_cast<target_t
>(codepoint));
862 else if (codepoint <= 0x7ff) {
863 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
864 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
865 }
else if (codepoint <= 0xffff) {
866 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
867 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
868 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
870 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
871 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
872 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
873 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
885inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(
const std::basic_string<char>& str)
noexcept {
886 auto out = std::basic_string<xtd::char16> {};
888 auto expected_bytes = 0;
889 auto str_ptr = str.data();
891 while (*str_ptr != 0) {
892 auto ch =
static_cast<unsigned char>(*str_ptr++);
894 if (expected_bytes == 0) {
899 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
900 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
901 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
904 out.push_back(0xfffd);
909 if ((ch & 0xc0) != 0x80) {
911 out.push_back(0xfffd);
916 codepoint = (codepoint << 6) | (ch & 0x3f);
921 if (expected_bytes == 0) {
922 if (codepoint > 0x10ffff) codepoint = 0xfffd;
924 if (codepoint > 0xffff) {
926 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
927 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
930 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
931 else out.push_back(0xfffd);
936 if (expected_bytes != 0) out.push_back(0xfffd);
944inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
945 auto out = std::basic_string<xtd::char16> {};
947 auto expected_bytes = 0;
948 auto str_ptr = str.data();
950 while (*str_ptr != 0) {
951 auto ch =
static_cast<unsigned char>(*str_ptr++);
953 if (expected_bytes == 0) {
958 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
959 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
960 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
963 out.push_back(0xfffd);
968 if ((ch & 0xc0) != 0x80) {
970 out.push_back(0xfffd);
975 codepoint = (codepoint << 6) | (ch & 0x3f);
980 if (expected_bytes == 0) {
981 if (codepoint > 0x10ffff) codepoint = 0xfffd;
983 if (codepoint > 0xffff) {
985 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
986 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
989 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
990 else out.push_back(0xfffd);
995 if (expected_bytes != 0) out.push_back(0xfffd);
1003inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(
const std::basic_string<char>& str)
noexcept {
1004 auto out = std::basic_string<xtd::wchar> {};
1005 auto codepoint = 0
u;
1006 auto expected_bytes = 0;
1007 auto str_ptr = str.data();
1009 while (*str_ptr != 0) {
1010 auto ch =
static_cast<unsigned char>(*str_ptr++);
1012 if (expected_bytes == 0) {
1017 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1018 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1019 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1021 out.push_back(0xfffd);
1026 if ((ch & 0xc0) != 0x80) {
1028 out.push_back(0xfffd);
1033 codepoint = (codepoint << 6) | (ch & 0x3f);
1038 if (expected_bytes == 0) {
1039 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1043 out.push_back(
static_cast<xtd::wchar>(codepoint));
1046 if (codepoint > 0xffff) {
1047 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1048 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1049 out.push_back(
static_cast<xtd::wchar>(high));
1051 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1052 out.push_back(
static_cast<xtd::wchar>(codepoint));
1055 out.push_back(0xfffd);
1062 if (expected_bytes != 0) out.push_back(0xfffd);
1070inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1071 auto out = std::basic_string<xtd::wchar> {};
1072 auto codepoint = 0
u;
1073 auto expected_bytes = 0;
1074 auto str_ptr = str.data();
1076 while (*str_ptr != 0) {
1077 auto ch =
static_cast<unsigned char>(*str_ptr++);
1079 if (expected_bytes == 0) {
1084 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1085 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1086 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1088 out.push_back(0xfffd);
1093 if ((ch & 0xc0) != 0x80) {
1095 out.push_back(0xfffd);
1100 codepoint = (codepoint << 6) | (ch & 0x3f);
1105 if (expected_bytes == 0) {
1106 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1110 out.push_back(
static_cast<xtd::wchar>(codepoint));
1113 if (codepoint > 0xffff) {
1114 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1115 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1116 out.push_back(
static_cast<xtd::wchar>(high));
1118 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1119 out.push_back(
static_cast<xtd::wchar>(codepoint));
1122 out.push_back(0xfffd);
1129 if (expected_bytes != 0) out.push_back(0xfffd);
1137inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(
const std::basic_string<char>& str)
noexcept {
1138 auto out = std::basic_string<xtd::char32> {};
1139 auto codepoint = 0
u;
1140 auto expected_bytes = 0;
1141 auto str_ptr = str.data();
1143 while (*str_ptr != 0) {
1144 auto ch =
static_cast<unsigned char>(*str_ptr++);
1146 if (expected_bytes == 0) {
1150 out.push_back(
static_cast<xtd::char32>(codepoint));
1151 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1152 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1153 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1154 else out.push_back(0xfffd);
1157 if ((ch & 0xc0) != 0x80) {
1159 out.push_back(0xfffd);
1164 codepoint = (codepoint << 6) | (ch & 0x3f);
1167 if (expected_bytes == 0) {
1169 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1170 out.push_back(
static_cast<xtd::char32>(codepoint));
1176 if (expected_bytes != 0) out.push_back(0xfffd);
1184inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1185 auto out = std::basic_string<xtd::char32> {};
1186 auto codepoint = 0
u;
1187 auto expected_bytes = 0;
1188 auto str_ptr = str.data();
1190 while (*str_ptr != 0) {
1191 auto ch =
static_cast<unsigned char>(*str_ptr++);
1193 if (expected_bytes == 0) {
1197 out.push_back(
static_cast<xtd::char32>(codepoint));
1198 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1199 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1200 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1201 else out.push_back(0xfffd);
1204 if ((ch & 0xc0) != 0x80) {
1206 out.push_back(0xfffd);
1211 codepoint = (codepoint << 6) | (ch & 0x3f);
1214 if (expected_bytes == 0) {
1216 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1217 out.push_back(
static_cast<xtd::char32>(codepoint));
1223 if (expected_bytes != 0) out.push_back(0xfffd);
1228inline std::basic_string<char> __xtd_convert_to_string<char, char>(
const std::basic_string<char>& str)
noexcept {
1233inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1238inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1243inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1248inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1253inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(
const std::basic_string<char>& str)
noexcept {
1254 return reinterpret_cast<const xtd::char8*
>(str.c_str());
1258inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1259 return reinterpret_cast<const char*
>(str.c_str());
1263inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1264 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1268inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1269 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1273inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1274 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1278inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1279 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1283inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1284 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
1288inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1289 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:63
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition basic_array.hpp:152
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumerable.
Definition basic_array.hpp:112
Represents text as a sequence of character units.
Definition basic_string.hpp:67
basic_string pad_left(xtd::size total_width) const noexcept
Right-aligns the characters in this basic_string, padding with spaces on the left for a specified tot...
Definition basic_string.hpp:1522
xtd::size index_of_any(const xtd::array< value_type > &values) const noexcept
Reports the index of the first occurrence in this instance of any character in a specified array of c...
xtd::size last_index_of_any(const xtd::array< value_type > &values) const noexcept
Reports the index of the last occurrence in this instance of any character in a specified array of ch...
basic_string pad_right(xtd::size total_width) const noexcept
Left-aligns the characters in this basic_string, padding with spaces on the right for a specified tot...
Definition basic_string.hpp:1536
auto concat(const ienumerable< char_t > &second) const noexcept
Definition enumerable.hpp:185
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
@ format
The format is not valid.
Definition exception_case.hpp:51
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:61
@ format_opened_bracket_without_end_bracket
The format contains open backet_without_end_bracket.
Definition exception_case.hpp:55
@ format_closing_bracket_without_open_bracket
The format contains close backet_without_open_bracket.
Definition exception_case.hpp:53
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
#define unused_
It may be used to suppress the "unused variable" or "unused local typedefs" compiler warnings when th...
Definition unused.hpp:30
constexpr xtd::size npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
@ character
Specifies that the text is trimmed to the nearest character.
Definition string_trimming.hpp:21
@ word
Specifies that text is trimmed to the nearest word.
Definition string_trimming.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
string_split_options
Specifies whether applicable xtd::string::split method overloads include or omit empty substrings fro...
Definition string_split_options.hpp:14
@ none
The return value includes array elements that contain an empty string.
Definition string_split_options.hpp:16
@ remove_empty_entries
The return value does not include array elements that contain an empty string.
Definition string_split_options.hpp:18
@ high
Specifies that the process performs time-critical tasks that must be executed immediately,...
Definition process_priority_class.hpp:32
@ u
The U key.
Definition console_key.hpp:128
@ separator
The Separator key.
Definition console_key.hpp:172
@ low
Specifies low quality interpolation.
Definition interpolation_mode.hpp:26
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:194
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
xtd::array< std::remove_cv_t< type_t > > to_array() const noexcept
Copies the contents of this read_only_span into a new array.
Definition read_only_span.hpp:368
Contains xtd::to_string methods.