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>
17 return index_of_any(values, 0,
length());
20template<
class char_t,
class traits_t,
class allocator_t>
22 return index_of_any(values, start_index,
length() - start_index);
25template<
class char_t,
class traits_t,
class allocator_t>
29 for (
const auto& item :
self_) {
30 if (index++ < start_index)
continue;
31 if (index - 1 > start_index + count)
break;
32 if (std::find(values.
items().begin(), values.
items().end(), item) != values.
items().end())
return index - 1;
37template<
class char_t,
class traits_t,
class allocator_t>
42template<
class char_t,
class traits_t,
class allocator_t>
47template<
class char_t,
class traits_t,
class allocator_t>
52template<
class char_t,
class traits_t,
class allocator_t>
54 return last_index_of_any(values, 0,
length());
57template<
class char_t,
class traits_t,
class allocator_t>
59 return last_index_of_any(values, start_index,
length() - start_index);
62template<
class char_t,
class traits_t,
class allocator_t>
66 for (
auto iterator = chars().
crbegin(); iterator != chars().crend(); ++iterator) {
67 if (index-- > start_index + count)
continue;
68 if (index + 1 < start_index)
break;
69 if (std::find(values.
items().begin(), values.
items().end(), *iterator) != values.
items().end())
return index + 1;
74template<
class char_t,
class traits_t,
class allocator_t>
79template<
class char_t,
class traits_t,
class allocator_t>
84template<
class char_t,
class traits_t,
class allocator_t>
89template<
class char_t,
class traits_t,
class allocator_t>
94template<
class char_t,
class traits_t,
class allocator_t>
99template<
class char_t,
class traits_t,
class allocator_t>
104template<
class char_t,
class traits_t,
class allocator_t>
109template<
class char_t,
class traits_t,
class allocator_t>
114template<
class char_t,
class traits_t,
class allocator_t>
119template<
class char_t,
class traits_t,
class allocator_t>
121 return split(separators, std::numeric_limits<xtd::size>::max(), options);
124template<
class char_t,
class traits_t,
class allocator_t>
129template<
class char_t,
class traits_t,
class allocator_t>
131 if (count == 0)
return {};
132 if (count == 1)
return {
self_};
134 auto result = std::vector<basic_string> {};
135 auto sub_string = basic_string {};
136 auto split_char_separators = separators.length() == 0 ? default_split_separators : separators;
137 for (
auto it = chars().
begin(); it != chars().end(); ++it) {
138 auto is_separator = std::find(split_char_separators.items().begin(), split_char_separators.items().end(), *it) != split_char_separators.items().end();
139 if (!is_separator) sub_string.chars_.append(basic_string(*it, 1));
140 auto is_last = (it + 1 == chars().end());
141 auto should_add = is_last || is_separator;
144 if (should_add && keep_empty) {
145 if (result.size() == count - 1) {
146 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)));
149 result.push_back(sub_string);
150 sub_string.chars_.clear();
159template<
class char_t,
class traits_t,
class allocator_t>
164template<
class char_t,
class traits_t,
class allocator_t>
169template<
class char_t,
class traits_t,
class allocator_t>
171 if (start_index >=
self_.length())
return {};
172 if (start_index + length >=
self_.length())
return {chars().begin() + start_index, chars().end()};
173 return {chars().begin() + start_index, chars().begin() + start_index +
length};
176template<
class char_t,
class traits_t,
class allocator_t>
181template<
class char_t,
class traits_t,
class allocator_t>
183 return to_array(start_index, length);
186template<
class char_t,
class traits_t,
class allocator_t>
188 auto words = split({
' '});
189 for (
auto& word : words)
190 if (
word.length() && word !=
word.to_upper())
word =
static_cast<value_type
>(toupper(word[0])) +
word.substring(1).to_lower();
191 return basic_string::join(
" ", words);
194template<
class char_t,
class traits_t,
class allocator_t>
199template<
class char_t,
class traits_t,
class allocator_t>
201 return trim_start(trim_chars).trim_end(trim_chars);
204template<
class char_t,
class traits_t,
class allocator_t>
209template<
class char_t,
class traits_t,
class allocator_t>
212 auto result = chars_;
213 while (std::find(trim_chars.items().begin(), trim_chars.items().end(), result[result.size() - 1]) != trim_chars.items().end())
214 result.erase(result.size() - 1, 1);
218template<
class char_t,
class traits_t,
class allocator_t>
221template<
class char_t,
class traits_t,
class allocator_t>
224 auto result = chars_;
225 while (std::find(trim_chars.items().begin(), trim_chars.items().end(), result[0]) != trim_chars.items().end())
230template<
class char_t,
class traits_t,
class allocator_t>
232 auto result = basic_string::empty_string;
233 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
237template<
class char_t,
class traits_t,
class allocator_t>
239 auto result = basic_string::empty_string;
240 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
244template<
class char_t,
class traits_t,
class allocator_t>
245template<
class other_
char_t>
247 auto result = basic_string::empty_string;
248 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
253template<
class char_t,
class traits_t,
class allocator_t>
254template<
class object_t>
257 for (
const auto& arg : args)
258 result +=
format(
"{}", arg);
262template<
class char_t,
class traits_t,
class allocator_t>
263template<
class ...args_t>
265 return format(std::locale {}, fmt, std::forward<args_t>(args)...);
268template<
class char_t,
class traits_t,
class allocator_t>
269template<
class ...args_t>
271 auto result = basic_string<char> {};
273 auto formats = std::vector<__format_information<char>> {};
274 auto begin_format_iterator = fmt.end();
275 auto end_format_iterator = fmt.end();
276 for (
auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
277 if (*iterator ==
'{') {
278 if (++iterator == fmt.end())
280 if (*iterator ==
'{')
283 begin_format_iterator = iterator;
284 while (iterator != fmt.end() && *iterator !=
'}') ++iterator;
285 if (iterator == fmt.end())
287 end_format_iterator = iterator;
288 __format_information<char> fi;
289 fi.location = result.length();
290 auto format_str = std::basic_string<char> {begin_format_iterator, end_format_iterator};
291 if (format_str.length() == 0)
294 xtd::size index_alignment_separator = basic_string(format_str).index_of(
',');
295 xtd::size index_format_separator = basic_string(format_str).index_of(u
':');
297 if (index_alignment_separator != std::basic_string<char>::npos && index_format_separator != std::basic_string<char>::npos && index_alignment_separator > index_format_separator)
298 index_alignment_separator = std::basic_string<char>::npos;
300 if (index_alignment_separator != basic_string<char_t>::npos)
301 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);
303 if (index_format_separator != basic_string<char>::npos)
304 fi.format = format_str.substr(index_format_separator + 1);
306 if (index_alignment_separator == 0 || index_format_separator == 0)
309 auto index_str = std::basic_string<char> {};
310 if (index_alignment_separator != basic_string<char>::npos)
311 index_str = format_str.substr(0, index_alignment_separator);
312 else if (index_format_separator != basic_string<char>::npos)
313 index_str = format_str.substr(0, index_format_separator);
315 index_str = std::move(format_str);
317 for (
auto c : index_str)
319 fi.index = std::stoi(index_str);
325 formats.push_back(fi);
327 }
else if (*iterator ==
'}') {
328 if (++iterator == fmt.end())
330 if (*iterator !=
'}')
337 __basic_string_extract_format_arg(loc, result, formats, std::forward<args_t>(args)...);
338 return result.chars().c_str();
341template<
class char_t,
class traits_t,
class allocator_t>
342template<
class value_t>
347template<
class char_t,
class traits_t,
class allocator_t>
348template<
class value_t>
353template<
class char_t,
class traits_t,
class allocator_t>
354template<
class value_t>
359template<
class char_t,
class traits_t,
class allocator_t>
362template<
class char_t,
class traits_t,
class allocator_t>
365template<
class char_t,
class traits_t,
class allocator_t>
369void __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) {
372 for (
auto& format : formats) {
373 format.location += offset;
374 if (
format.index == index) {
381 alignment = std::stoi(
format.alignment);
385 if (alignment > 0) arg_str = arg_str.to_u32string().pad_left(alignment);
386 else if (alignment < 0) arg_str = arg_str.to_u32string().pad_right(-alignment);
388 fmt.insert(
format.location, arg_str);
389 offset += arg_str.
length();
395template<
class ...args_t>
396void __basic_string_extract_format_arg(
const std::locale& loc,
xtd::basic_string<char>& fmt, std::vector<__format_information<char >>& formats, args_t&&... args) {
397 [[maybe_unused]]
auto index =
xtd::size {0};
398 (__basic_string_extract_format_arg(loc,
const_cast<std::basic_string<char>&
> (fmt.
chars()), index, formats, args), ...);
402template<
class target_t,
class source_t>
403inline std::basic_string<target_t> __xtd_convert_to_string(std::basic_string<source_t>&& str)
noexcept {
404 auto out = std::basic_string<target_t> {};
406 for (
const auto& character : str) {
407 if (character >= 0xd800 && character <= 0xdbff)
408 codepoint = ((
character - 0xd800) << 10) + 0x10000;
410 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
413 if (codepoint <= 0x7f)
414 out.append(1,
static_cast<target_t
>(codepoint));
415 else if (codepoint <= 0x7ff) {
416 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
417 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
418 }
else if (codepoint <= 0xffff) {
419 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
420 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
421 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
423 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
424 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
425 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
426 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
438inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(std::basic_string<char>&& str)
noexcept {
439 auto out = std::basic_string<xtd::char16> {};
441 auto expected_bytes = 0;
442 auto str_ptr = str.data();
444 while (*str_ptr != 0) {
445 auto ch =
static_cast<unsigned char>(*str_ptr++);
447 if (expected_bytes == 0) {
452 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
453 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
454 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
457 out.push_back(0xfffd);
462 if ((ch & 0xc0) != 0x80) {
464 out.push_back(0xfffd);
469 codepoint = (codepoint << 6) | (ch & 0x3f);
474 if (expected_bytes == 0) {
475 if (codepoint > 0x10ffff) codepoint = 0xfffd;
477 if (codepoint > 0xffff) {
479 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
480 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
483 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
484 else out.push_back(0xfffd);
489 if (expected_bytes != 0) out.push_back(0xfffd);
497inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
498 auto out = std::basic_string<xtd::char16> {};
500 auto expected_bytes = 0;
501 auto str_ptr = str.data();
503 while (*str_ptr != 0) {
504 auto ch =
static_cast<unsigned char>(*str_ptr++);
506 if (expected_bytes == 0) {
511 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
512 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
513 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
516 out.push_back(0xfffd);
521 if ((ch & 0xc0) != 0x80) {
523 out.push_back(0xfffd);
528 codepoint = (codepoint << 6) | (ch & 0x3f);
533 if (expected_bytes == 0) {
534 if (codepoint > 0x10ffff) codepoint = 0xfffd;
536 if (codepoint > 0xffff) {
538 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
539 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
542 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
543 else out.push_back(0xfffd);
548 if (expected_bytes != 0) out.push_back(0xfffd);
556inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(std::basic_string<char>&& str)
noexcept {
557 auto out = std::basic_string<xtd::wchar> {};
559 auto expected_bytes = 0;
560 auto str_ptr = str.data();
562 while (*str_ptr != 0) {
563 auto ch =
static_cast<unsigned char>(*str_ptr++);
565 if (expected_bytes == 0) {
570 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
571 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
572 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
574 out.push_back(0xfffd);
579 if ((ch & 0xc0) != 0x80) {
581 out.push_back(0xfffd);
586 codepoint = (codepoint << 6) | (ch & 0x3f);
591 if (expected_bytes == 0) {
592 if (codepoint > 0x10ffff) codepoint = 0xfffd;
596 out.push_back(
static_cast<xtd::wchar>(codepoint));
599 if (codepoint > 0xffff) {
600 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
601 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
604 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
605 out.push_back(
static_cast<xtd::wchar>(codepoint));
608 out.push_back(0xfffd);
615 if (expected_bytes != 0) out.push_back(0xfffd);
623inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
624 auto out = std::basic_string<xtd::wchar> {};
626 auto expected_bytes = 0;
627 auto str_ptr = str.data();
629 while (*str_ptr != 0) {
630 auto ch =
static_cast<unsigned char>(*str_ptr++);
632 if (expected_bytes == 0) {
637 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
638 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
639 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
641 out.push_back(0xfffd);
646 if ((ch & 0xc0) != 0x80) {
648 out.push_back(0xfffd);
653 codepoint = (codepoint << 6) | (ch & 0x3f);
658 if (expected_bytes == 0) {
659 if (codepoint > 0x10ffff) codepoint = 0xfffd;
663 out.push_back(
static_cast<xtd::wchar>(codepoint));
666 if (codepoint > 0xffff) {
667 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
668 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
671 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
672 out.push_back(
static_cast<xtd::wchar>(codepoint));
675 out.push_back(0xfffd);
682 if (expected_bytes != 0) out.push_back(0xfffd);
690inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(std::basic_string<char>&& str)
noexcept {
691 auto out = std::basic_string<xtd::char32> {};
693 auto expected_bytes = 0;
694 auto str_ptr = str.data();
696 while (*str_ptr != 0) {
697 auto ch =
static_cast<unsigned char>(*str_ptr++);
699 if (expected_bytes == 0) {
703 out.push_back(
static_cast<xtd::char32>(codepoint));
704 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
705 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
706 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
707 else out.push_back(0xfffd);
710 if ((ch & 0xc0) != 0x80) {
712 out.push_back(0xfffd);
717 codepoint = (codepoint << 6) | (ch & 0x3f);
720 if (expected_bytes == 0) {
722 if (codepoint > 0x10ffff) codepoint = 0xfffd;
723 out.push_back(
static_cast<xtd::char32>(codepoint));
729 if (expected_bytes != 0) out.push_back(0xfffd);
737inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
738 auto out = std::basic_string<xtd::char32> {};
740 auto expected_bytes = 0;
741 auto str_ptr = str.data();
743 while (*str_ptr != 0) {
744 auto ch =
static_cast<unsigned char>(*str_ptr++);
746 if (expected_bytes == 0) {
750 out.push_back(
static_cast<xtd::char32>(codepoint));
751 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
752 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
753 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
754 else out.push_back(0xfffd);
757 if ((ch & 0xc0) != 0x80) {
759 out.push_back(0xfffd);
764 codepoint = (codepoint << 6) | (ch & 0x3f);
767 if (expected_bytes == 0) {
769 if (codepoint > 0x10ffff) codepoint = 0xfffd;
770 out.push_back(
static_cast<xtd::char32>(codepoint));
776 if (expected_bytes != 0) out.push_back(0xfffd);
781inline std::basic_string<char> __xtd_convert_to_string<char, char>(std::basic_string<char>&& str)
noexcept {
782 return std::move(str);
786inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
787 return std::move(str);
791inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
792 return std::move(str);
796inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
797 return std::move(str);
801inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
802 return std::move(str);
806inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(std::basic_string<char>&& str)
noexcept {
807 return std::basic_string<xtd::char8> {
reinterpret_cast<const xtd::char8*
>(str.c_str())};
811inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
812 return std::basic_string<char> {
reinterpret_cast<const char*
>(str.c_str())};
816inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
817 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
821inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
822 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
826inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
827 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
831inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
832 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
836inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
837 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
841inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
842 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
845template<
class target_t,
class source_t>
846inline std::basic_string<target_t> __xtd_convert_to_string(
const std::basic_string<source_t>& str)
noexcept {
847 auto out = std::basic_string<target_t> {};
849 for (
const auto& character : str) {
850 if (character >= 0xd800 && character <= 0xdbff)
851 codepoint = ((
character - 0xd800) << 10) + 0x10000;
853 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
856 if (codepoint <= 0x7f)
857 out.append(1,
static_cast<target_t
>(codepoint));
858 else if (codepoint <= 0x7ff) {
859 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
860 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
861 }
else if (codepoint <= 0xffff) {
862 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
863 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
864 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
866 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
867 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
868 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
869 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
881inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(
const std::basic_string<char>& str)
noexcept {
882 auto out = std::basic_string<xtd::char16> {};
884 auto expected_bytes = 0;
885 auto str_ptr = str.data();
887 while (*str_ptr != 0) {
888 auto ch =
static_cast<unsigned char>(*str_ptr++);
890 if (expected_bytes == 0) {
895 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
896 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
897 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
900 out.push_back(0xfffd);
905 if ((ch & 0xc0) != 0x80) {
907 out.push_back(0xfffd);
912 codepoint = (codepoint << 6) | (ch & 0x3f);
917 if (expected_bytes == 0) {
918 if (codepoint > 0x10ffff) codepoint = 0xfffd;
920 if (codepoint > 0xffff) {
922 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
923 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
926 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
927 else out.push_back(0xfffd);
932 if (expected_bytes != 0) out.push_back(0xfffd);
940inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
941 auto out = std::basic_string<xtd::char16> {};
943 auto expected_bytes = 0;
944 auto str_ptr = str.data();
946 while (*str_ptr != 0) {
947 auto ch =
static_cast<unsigned char>(*str_ptr++);
949 if (expected_bytes == 0) {
954 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
955 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
956 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
959 out.push_back(0xfffd);
964 if ((ch & 0xc0) != 0x80) {
966 out.push_back(0xfffd);
971 codepoint = (codepoint << 6) | (ch & 0x3f);
976 if (expected_bytes == 0) {
977 if (codepoint > 0x10ffff) codepoint = 0xfffd;
979 if (codepoint > 0xffff) {
981 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
982 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
985 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
986 else out.push_back(0xfffd);
991 if (expected_bytes != 0) out.push_back(0xfffd);
999inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(
const std::basic_string<char>& str)
noexcept {
1000 auto out = std::basic_string<xtd::wchar> {};
1001 auto codepoint = 0
u;
1002 auto expected_bytes = 0;
1003 auto str_ptr = str.data();
1005 while (*str_ptr != 0) {
1006 auto ch =
static_cast<unsigned char>(*str_ptr++);
1008 if (expected_bytes == 0) {
1013 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1014 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1015 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1017 out.push_back(0xfffd);
1022 if ((ch & 0xc0) != 0x80) {
1024 out.push_back(0xfffd);
1029 codepoint = (codepoint << 6) | (ch & 0x3f);
1034 if (expected_bytes == 0) {
1035 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1039 out.push_back(
static_cast<xtd::wchar>(codepoint));
1042 if (codepoint > 0xffff) {
1043 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1044 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1045 out.push_back(
static_cast<xtd::wchar>(high));
1047 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1048 out.push_back(
static_cast<xtd::wchar>(codepoint));
1051 out.push_back(0xfffd);
1058 if (expected_bytes != 0) out.push_back(0xfffd);
1066inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1067 auto out = std::basic_string<xtd::wchar> {};
1068 auto codepoint = 0
u;
1069 auto expected_bytes = 0;
1070 auto str_ptr = str.data();
1072 while (*str_ptr != 0) {
1073 auto ch =
static_cast<unsigned char>(*str_ptr++);
1075 if (expected_bytes == 0) {
1080 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1081 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1082 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1084 out.push_back(0xfffd);
1089 if ((ch & 0xc0) != 0x80) {
1091 out.push_back(0xfffd);
1096 codepoint = (codepoint << 6) | (ch & 0x3f);
1101 if (expected_bytes == 0) {
1102 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1106 out.push_back(
static_cast<xtd::wchar>(codepoint));
1109 if (codepoint > 0xffff) {
1110 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1111 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1112 out.push_back(
static_cast<xtd::wchar>(high));
1114 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1115 out.push_back(
static_cast<xtd::wchar>(codepoint));
1118 out.push_back(0xfffd);
1125 if (expected_bytes != 0) out.push_back(0xfffd);
1133inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(
const std::basic_string<char>& str)
noexcept {
1134 auto out = std::basic_string<xtd::char32> {};
1135 auto codepoint = 0
u;
1136 auto expected_bytes = 0;
1137 auto str_ptr = str.data();
1139 while (*str_ptr != 0) {
1140 auto ch =
static_cast<unsigned char>(*str_ptr++);
1142 if (expected_bytes == 0) {
1146 out.push_back(
static_cast<xtd::char32>(codepoint));
1147 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1148 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1149 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1150 else out.push_back(0xfffd);
1153 if ((ch & 0xc0) != 0x80) {
1155 out.push_back(0xfffd);
1160 codepoint = (codepoint << 6) | (ch & 0x3f);
1163 if (expected_bytes == 0) {
1165 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1166 out.push_back(
static_cast<xtd::char32>(codepoint));
1172 if (expected_bytes != 0) out.push_back(0xfffd);
1180inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1181 auto out = std::basic_string<xtd::char32> {};
1182 auto codepoint = 0
u;
1183 auto expected_bytes = 0;
1184 auto str_ptr = str.data();
1186 while (*str_ptr != 0) {
1187 auto ch =
static_cast<unsigned char>(*str_ptr++);
1189 if (expected_bytes == 0) {
1193 out.push_back(
static_cast<xtd::char32>(codepoint));
1194 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1195 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1196 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1197 else out.push_back(0xfffd);
1200 if ((ch & 0xc0) != 0x80) {
1202 out.push_back(0xfffd);
1207 codepoint = (codepoint << 6) | (ch & 0x3f);
1210 if (expected_bytes == 0) {
1212 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1213 out.push_back(
static_cast<xtd::char32>(codepoint));
1219 if (expected_bytes != 0) out.push_back(0xfffd);
1224inline std::basic_string<char> __xtd_convert_to_string<char, char>(
const std::basic_string<char>& str)
noexcept {
1229inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1234inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1239inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1244inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1249inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(
const std::basic_string<char>& str)
noexcept {
1250 return reinterpret_cast<const xtd::char8*
>(str.c_str());
1254inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1255 return reinterpret_cast<const char*
>(str.c_str());
1259inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1260 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1264inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1265 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1269inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1270 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1274inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1275 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1279inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1280 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
1284inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1285 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:64
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition basic_array.hpp:113
Represents text as a sequence of character units.
Definition basic_string.hpp:66
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.hpp:111
const base_type & chars() const noexcept
Returns a reference to the underlying base type.
Definition basic_string.hpp:354
virtual size_type length() const noexcept
Gets the number of characters in the current xtd::basic_string object.
Definition basic_string.hpp:380
virtual bool empty() const noexcept
Checks whether the container is empty.
Definition basic_string.hpp:375
auto to_array() const noexcept -> xtd::array< char_t >
auto concat(const ienumerable< char_t > &second) const noexcept
Definition enumerable.hpp:185
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
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
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.