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."
14template<
class char_t,
class traits_t,
class allocator_t>
17template<
class char_t,
class traits_t,
class allocator_t>
19 return index_of_any(values, 0,
length());
22template<
class char_t,
class traits_t,
class allocator_t>
24 return index_of_any(values, start_index,
length() - start_index);
27template<
class char_t,
class traits_t,
class allocator_t>
31 for (
const auto& item :
self_) {
32 if (index++ < start_index)
continue;
33 if (index - 1 > start_index + count)
break;
34 if (std::find(values.
begin(), values.
end(), item) != values.
end())
return index - 1;
39template<
class char_t,
class traits_t,
class allocator_t>
44template<
class char_t,
class traits_t,
class allocator_t>
49template<
class char_t,
class traits_t,
class allocator_t>
54template<
class char_t,
class traits_t,
class allocator_t>
56 return last_index_of_any(values, 0,
length());
59template<
class char_t,
class traits_t,
class allocator_t>
61 return last_index_of_any(values, start_index,
length() - start_index);
64template<
class char_t,
class traits_t,
class allocator_t>
68 for (
auto iterator = chars().
crbegin(); iterator != chars().crend(); ++iterator) {
69 if (index-- > start_index + count)
continue;
70 if (index + 1 < start_index)
break;
71 if (std::find(values.
begin(), values.
end(), *iterator) != values.
end())
return index + 1;
76template<
class char_t,
class traits_t,
class allocator_t>
81template<
class char_t,
class traits_t,
class allocator_t>
86template<
class char_t,
class traits_t,
class allocator_t>
91template<
class char_t,
class traits_t,
class allocator_t>
96template<
class char_t,
class traits_t,
class allocator_t>
101template<
class char_t,
class traits_t,
class allocator_t>
106template<
class char_t,
class traits_t,
class allocator_t>
111template<
class char_t,
class traits_t,
class allocator_t>
116template<
class char_t,
class traits_t,
class allocator_t>
121template<
class char_t,
class traits_t,
class allocator_t>
123 return split(separators, std::numeric_limits<xtd::size>::max(), options);
126template<
class char_t,
class traits_t,
class allocator_t>
131template<
class char_t,
class traits_t,
class allocator_t>
133 if (count == 0)
return {};
134 if (count == 1)
return {
self_};
136 auto result = std::vector<basic_string> {};
137 auto sub_string = basic_string {};
138 auto split_char_separators = separators.length() == 0 ? default_split_separators : separators;
139 for (
auto it = chars().
begin(); it != chars().end(); ++it) {
140 auto is_separator = std::find(split_char_separators.begin(), split_char_separators.end(), *it) != split_char_separators.end();
141 if (!is_separator) sub_string.chars_.append(basic_string(1, *it));
142 auto is_last = (it + 1 == chars().end());
143 auto should_add = is_last || is_separator;
146 if (should_add && keep_empty) {
147 if (result.size() == count - 1) {
148 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)));
151 result.push_back(sub_string);
152 sub_string.chars_.clear();
161template<
class char_t,
class traits_t,
class allocator_t>
166template<
class char_t,
class traits_t,
class allocator_t>
171template<
class char_t,
class traits_t,
class allocator_t>
173 if (start_index >=
self_.length())
return {};
174 if (start_index + length >=
self_.length())
return {chars().begin() + start_index, chars().end()};
175 return {chars().begin() + start_index, chars().begin() + start_index +
length};
178template<
class char_t,
class traits_t,
class allocator_t>
183template<
class char_t,
class traits_t,
class allocator_t>
185 return to_array(start_index, length);
188template<
class char_t,
class traits_t,
class allocator_t>
190 auto words = split({
' '});
191 for (
auto& word : words)
192 if (
word.length() && word !=
word.to_upper())
word =
static_cast<value_type
>(toupper(word[0])) +
word.substring(1).to_lower();
193 return basic_string::join(
" ", words);
196template<
class char_t,
class traits_t,
class allocator_t>
201template<
class char_t,
class traits_t,
class allocator_t>
203 return trim_start(trim_chars).trim_end(trim_chars);
206template<
class char_t,
class traits_t,
class allocator_t>
211template<
class char_t,
class traits_t,
class allocator_t>
214 auto result = chars_;
215 while (std::find(trim_chars.begin(), trim_chars.end(), result[result.size() - 1]) != trim_chars.end())
216 result.erase(result.size() - 1, 1);
220template<
class char_t,
class traits_t,
class allocator_t>
223template<
class char_t,
class traits_t,
class allocator_t>
226 auto result = chars_;
227 while (std::find(trim_chars.begin(), trim_chars.end(), result[0]) != trim_chars.end())
232template<
class char_t,
class traits_t,
class allocator_t>
234 auto result = basic_string::empty_string;
235 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
239template<
class char_t,
class traits_t,
class allocator_t>
241 auto result = basic_string::empty_string;
242 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
246template<
class char_t,
class traits_t,
class allocator_t>
247template<
class other_
char_t>
249 auto result = basic_string::empty_string;
250 std::for_each(values.begin(), values.end(), [&](
const auto & item) {result += item;});
255template<
class char_t,
class traits_t,
class allocator_t>
256template<
class object_t>
259 for (
const auto& arg : args)
260 result +=
format(
"{}", arg);
264template<
class char_t,
class traits_t,
class allocator_t>
265template<
class ...args_t>
267 auto result = basic_string<char> {};
269 auto formats = std::vector<__format_information<char>> {};
270 auto begin_format_iterator = fmt.end();
271 auto end_format_iterator = fmt.end();
272 for (
auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
273 if (*iterator ==
'{') {
274 if (++iterator == fmt.end())
276 if (*iterator ==
'{')
279 begin_format_iterator = iterator;
280 while (iterator != fmt.end() && *iterator !=
'}') ++iterator;
281 if (iterator == fmt.end())
283 end_format_iterator = iterator;
284 __format_information<char> fi;
285 fi.location = result.length();
286 auto format_str = std::basic_string<char> {begin_format_iterator, end_format_iterator};
287 if (format_str.length() == 0)
290 xtd::size index_alignment_separator = basic_string(format_str).index_of(
',');
291 xtd::size index_format_separator = basic_string(format_str).index_of(u
':');
293 if (index_alignment_separator != std::basic_string<char>::npos && index_format_separator != std::basic_string<char>::npos && index_alignment_separator > index_format_separator)
294 index_alignment_separator = std::basic_string<char>::npos;
296 if (index_alignment_separator != basic_string<char_t>::npos)
297 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);
299 if (index_format_separator != basic_string<char>::npos)
300 fi.format = format_str.substr(index_format_separator + 1);
302 if (index_alignment_separator == 0 || index_format_separator == 0)
305 auto index_str = std::basic_string<char> {};
306 if (index_alignment_separator != basic_string<char>::npos)
307 index_str = format_str.substr(0, index_alignment_separator);
308 else if (index_format_separator != basic_string<char>::npos)
309 index_str = format_str.substr(0, index_format_separator);
311 index_str = std::move(format_str);
313 for (
auto c : index_str)
315 fi.index = std::stoi(index_str);
321 formats.push_back(fi);
323 }
else if (*iterator ==
'}') {
324 if (++iterator == fmt.end())
326 if (*iterator !=
'}')
333 __basic_string_extract_format_arg(result, formats, std::forward<args_t>(args)...);
334 return result.chars().c_str();
337template<
class char_t,
class traits_t,
class allocator_t>
338template<
class value_t>
343template<
class char_t,
class traits_t,
class allocator_t>
344template<
class value_t>
349template<
class char_t,
class traits_t,
class allocator_t>
350template<
class value_t>
355template<
class char_t,
class traits_t,
class allocator_t>
358template<
class char_t,
class traits_t,
class allocator_t>
361template<
class char_t,
class traits_t,
class allocator_t>
365void __basic_string_extract_format_arg(std::basic_string<char>& fmt,
xtd::size& index, std::vector<__format_information<char >> & formats, arg_t&& arg) {
368 for (
auto& format : formats) {
369 format.location += offset;
370 if (
format.index == index) {
374 if (!
format.alignment.empty()) {
377 alignment = std::stoi(
format.alignment);
381 if (alignment > 0) arg_str = arg_str.
pad_left(alignment);
382 else if (alignment < 0) arg_str = arg_str.
pad_right(-alignment);
384 fmt.insert(
format.location, arg_str);
385 offset += arg_str.length();
391template<
class ...args_t>
392void __basic_string_extract_format_arg(
xtd::basic_string<char>& fmt, std::vector<__format_information<char >> & formats, args_t&&... args) {
394 (__basic_string_extract_format_arg(
const_cast<std::basic_string<char>&
> (fmt.chars()), index, formats, args), ...);
399template<
class target_t,
class source_t>
400inline std::basic_string<target_t> __xtd_convert_to_string(std::basic_string<source_t>&& str)
noexcept {
401 auto out = std::basic_string<target_t> {};
403 for (
const auto& character : str) {
404 if (character >= 0xd800 && character <= 0xdbff)
405 codepoint = ((
character - 0xd800) << 10) + 0x10000;
407 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
410 if (codepoint <= 0x7f)
411 out.append(1,
static_cast<target_t
>(codepoint));
412 else if (codepoint <= 0x7ff) {
413 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
414 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
415 }
else if (codepoint <= 0xffff) {
416 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
417 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
418 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
420 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
421 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
422 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
423 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
435inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(std::basic_string<char>&& str)
noexcept {
436 auto out = std::basic_string<xtd::char16> {};
438 auto expected_bytes = 0;
439 auto str_ptr = str.data();
441 while (*str_ptr != 0) {
442 auto ch =
static_cast<unsigned char>(*str_ptr++);
444 if (expected_bytes == 0) {
449 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
450 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
451 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
454 out.push_back(0xfffd);
459 if ((ch & 0xc0) != 0x80) {
461 out.push_back(0xfffd);
466 codepoint = (codepoint << 6) | (ch & 0x3f);
471 if (expected_bytes == 0) {
472 if (codepoint > 0x10ffff) codepoint = 0xfffd;
474 if (codepoint > 0xffff) {
476 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
477 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
480 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
481 else out.push_back(0xfffd);
486 if (expected_bytes != 0) out.push_back(0xfffd);
494inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
495 auto out = std::basic_string<xtd::char16> {};
497 auto expected_bytes = 0;
498 auto str_ptr = str.data();
500 while (*str_ptr != 0) {
501 auto ch =
static_cast<unsigned char>(*str_ptr++);
503 if (expected_bytes == 0) {
508 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
509 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
510 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
513 out.push_back(0xfffd);
518 if ((ch & 0xc0) != 0x80) {
520 out.push_back(0xfffd);
525 codepoint = (codepoint << 6) | (ch & 0x3f);
530 if (expected_bytes == 0) {
531 if (codepoint > 0x10ffff) codepoint = 0xfffd;
533 if (codepoint > 0xffff) {
535 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
536 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
539 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
540 else out.push_back(0xfffd);
545 if (expected_bytes != 0) out.push_back(0xfffd);
553inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(std::basic_string<char>&& str)
noexcept {
554 auto out = std::basic_string<xtd::wchar> {};
556 auto expected_bytes = 0;
557 auto str_ptr = str.data();
559 while (*str_ptr != 0) {
560 auto ch =
static_cast<unsigned char>(*str_ptr++);
562 if (expected_bytes == 0) {
567 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
568 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
569 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
571 out.push_back(0xfffd);
576 if ((ch & 0xc0) != 0x80) {
578 out.push_back(0xfffd);
583 codepoint = (codepoint << 6) | (ch & 0x3f);
588 if (expected_bytes == 0) {
589 if (codepoint > 0x10ffff) codepoint = 0xfffd;
593 out.push_back(
static_cast<xtd::wchar>(codepoint));
596 if (codepoint > 0xffff) {
597 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
598 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
601 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
602 out.push_back(
static_cast<xtd::wchar>(codepoint));
605 out.push_back(0xfffd);
612 if (expected_bytes != 0) out.push_back(0xfffd);
620inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
621 auto out = std::basic_string<xtd::wchar> {};
623 auto expected_bytes = 0;
624 auto str_ptr = str.data();
626 while (*str_ptr != 0) {
627 auto ch =
static_cast<unsigned char>(*str_ptr++);
629 if (expected_bytes == 0) {
634 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
635 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
636 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
638 out.push_back(0xfffd);
643 if ((ch & 0xc0) != 0x80) {
645 out.push_back(0xfffd);
650 codepoint = (codepoint << 6) | (ch & 0x3f);
655 if (expected_bytes == 0) {
656 if (codepoint > 0x10ffff) codepoint = 0xfffd;
660 out.push_back(
static_cast<xtd::wchar>(codepoint));
663 if (codepoint > 0xffff) {
664 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
665 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
668 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
669 out.push_back(
static_cast<xtd::wchar>(codepoint));
672 out.push_back(0xfffd);
679 if (expected_bytes != 0) out.push_back(0xfffd);
687inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(std::basic_string<char>&& str)
noexcept {
688 auto out = std::basic_string<xtd::char32> {};
690 auto expected_bytes = 0;
691 auto str_ptr = str.data();
693 while (*str_ptr != 0) {
694 auto ch =
static_cast<unsigned char>(*str_ptr++);
696 if (expected_bytes == 0) {
700 out.push_back(
static_cast<xtd::char32>(codepoint));
701 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
702 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
703 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
704 else out.push_back(0xfffd);
707 if ((ch & 0xc0) != 0x80) {
709 out.push_back(0xfffd);
714 codepoint = (codepoint << 6) | (ch & 0x3f);
717 if (expected_bytes == 0) {
719 if (codepoint > 0x10ffff) codepoint = 0xfffd;
720 out.push_back(
static_cast<xtd::char32>(codepoint));
726 if (expected_bytes != 0) out.push_back(0xfffd);
734inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
735 auto out = std::basic_string<xtd::char32> {};
737 auto expected_bytes = 0;
738 auto str_ptr = str.data();
740 while (*str_ptr != 0) {
741 auto ch =
static_cast<unsigned char>(*str_ptr++);
743 if (expected_bytes == 0) {
747 out.push_back(
static_cast<xtd::char32>(codepoint));
748 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
749 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
750 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
751 else out.push_back(0xfffd);
754 if ((ch & 0xc0) != 0x80) {
756 out.push_back(0xfffd);
761 codepoint = (codepoint << 6) | (ch & 0x3f);
764 if (expected_bytes == 0) {
766 if (codepoint > 0x10ffff) codepoint = 0xfffd;
767 out.push_back(
static_cast<xtd::char32>(codepoint));
773 if (expected_bytes != 0) out.push_back(0xfffd);
778inline std::basic_string<char> __xtd_convert_to_string<char, char>(std::basic_string<char>&& str)
noexcept {
779 return std::move(str);
783inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
784 return std::move(str);
788inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
789 return std::move(str);
793inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
794 return std::move(str);
798inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
799 return std::move(str);
803inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(std::basic_string<char>&& str)
noexcept {
804 return std::basic_string<xtd::char8> {
reinterpret_cast<const xtd::char8*
>(str.c_str())};
808inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
809 return std::basic_string<char> {
reinterpret_cast<const char*
>(str.c_str())};
813inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
814 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
818inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
819 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
823inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
824 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
828inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
829 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
833inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
834 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
838inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
839 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
842template<
class target_t,
class source_t>
843inline std::basic_string<target_t> __xtd_convert_to_string(
const std::basic_string<source_t>& str)
noexcept {
844 auto out = std::basic_string<target_t> {};
846 for (
const auto& character : str) {
847 if (character >= 0xd800 && character <= 0xdbff)
848 codepoint = ((
character - 0xd800) << 10) + 0x10000;
850 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
853 if (codepoint <= 0x7f)
854 out.append(1,
static_cast<target_t
>(codepoint));
855 else if (codepoint <= 0x7ff) {
856 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
857 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
858 }
else if (codepoint <= 0xffff) {
859 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
860 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
861 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
863 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
864 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
865 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
866 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
878inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(
const std::basic_string<char>& str)
noexcept {
879 auto out = std::basic_string<xtd::char16> {};
881 auto expected_bytes = 0;
882 auto str_ptr = str.data();
884 while (*str_ptr != 0) {
885 auto ch =
static_cast<unsigned char>(*str_ptr++);
887 if (expected_bytes == 0) {
892 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
893 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
894 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
897 out.push_back(0xfffd);
902 if ((ch & 0xc0) != 0x80) {
904 out.push_back(0xfffd);
909 codepoint = (codepoint << 6) | (ch & 0x3f);
914 if (expected_bytes == 0) {
915 if (codepoint > 0x10ffff) codepoint = 0xfffd;
917 if (codepoint > 0xffff) {
919 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
920 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
923 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
924 else out.push_back(0xfffd);
929 if (expected_bytes != 0) out.push_back(0xfffd);
937inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
938 auto out = std::basic_string<xtd::char16> {};
940 auto expected_bytes = 0;
941 auto str_ptr = str.data();
943 while (*str_ptr != 0) {
944 auto ch =
static_cast<unsigned char>(*str_ptr++);
946 if (expected_bytes == 0) {
951 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
952 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
953 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
956 out.push_back(0xfffd);
961 if ((ch & 0xc0) != 0x80) {
963 out.push_back(0xfffd);
968 codepoint = (codepoint << 6) | (ch & 0x3f);
973 if (expected_bytes == 0) {
974 if (codepoint > 0x10ffff) codepoint = 0xfffd;
976 if (codepoint > 0xffff) {
978 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
979 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
982 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
983 else out.push_back(0xfffd);
988 if (expected_bytes != 0) out.push_back(0xfffd);
996inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(
const std::basic_string<char>& str)
noexcept {
997 auto out = std::basic_string<xtd::wchar> {};
999 auto expected_bytes = 0;
1000 auto str_ptr = str.data();
1002 while (*str_ptr != 0) {
1003 auto ch =
static_cast<unsigned char>(*str_ptr++);
1005 if (expected_bytes == 0) {
1010 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1011 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1012 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1014 out.push_back(0xfffd);
1019 if ((ch & 0xc0) != 0x80) {
1021 out.push_back(0xfffd);
1026 codepoint = (codepoint << 6) | (ch & 0x3f);
1031 if (expected_bytes == 0) {
1032 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1036 out.push_back(
static_cast<xtd::wchar>(codepoint));
1039 if (codepoint > 0xffff) {
1040 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1041 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1042 out.push_back(
static_cast<xtd::wchar>(high));
1044 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1045 out.push_back(
static_cast<xtd::wchar>(codepoint));
1048 out.push_back(0xfffd);
1055 if (expected_bytes != 0) out.push_back(0xfffd);
1063inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1064 auto out = std::basic_string<xtd::wchar> {};
1065 auto codepoint = 0
u;
1066 auto expected_bytes = 0;
1067 auto str_ptr = str.data();
1069 while (*str_ptr != 0) {
1070 auto ch =
static_cast<unsigned char>(*str_ptr++);
1072 if (expected_bytes == 0) {
1077 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1078 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1079 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1081 out.push_back(0xfffd);
1086 if ((ch & 0xc0) != 0x80) {
1088 out.push_back(0xfffd);
1093 codepoint = (codepoint << 6) | (ch & 0x3f);
1098 if (expected_bytes == 0) {
1099 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1103 out.push_back(
static_cast<xtd::wchar>(codepoint));
1106 if (codepoint > 0xffff) {
1107 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1108 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1109 out.push_back(
static_cast<xtd::wchar>(high));
1111 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1112 out.push_back(
static_cast<xtd::wchar>(codepoint));
1115 out.push_back(0xfffd);
1122 if (expected_bytes != 0) out.push_back(0xfffd);
1130inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(
const std::basic_string<char>& str)
noexcept {
1131 auto out = std::basic_string<xtd::char32> {};
1132 auto codepoint = 0
u;
1133 auto expected_bytes = 0;
1134 auto str_ptr = str.data();
1136 while (*str_ptr != 0) {
1137 auto ch =
static_cast<unsigned char>(*str_ptr++);
1139 if (expected_bytes == 0) {
1143 out.push_back(
static_cast<xtd::char32>(codepoint));
1144 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1145 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1146 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1147 else out.push_back(0xfffd);
1150 if ((ch & 0xc0) != 0x80) {
1152 out.push_back(0xfffd);
1157 codepoint = (codepoint << 6) | (ch & 0x3f);
1160 if (expected_bytes == 0) {
1162 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1163 out.push_back(
static_cast<xtd::char32>(codepoint));
1169 if (expected_bytes != 0) out.push_back(0xfffd);
1177inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1178 auto out = std::basic_string<xtd::char32> {};
1179 auto codepoint = 0
u;
1180 auto expected_bytes = 0;
1181 auto str_ptr = str.data();
1183 while (*str_ptr != 0) {
1184 auto ch =
static_cast<unsigned char>(*str_ptr++);
1186 if (expected_bytes == 0) {
1190 out.push_back(
static_cast<xtd::char32>(codepoint));
1191 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1192 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1193 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1194 else out.push_back(0xfffd);
1197 if ((ch & 0xc0) != 0x80) {
1199 out.push_back(0xfffd);
1204 codepoint = (codepoint << 6) | (ch & 0x3f);
1207 if (expected_bytes == 0) {
1209 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1210 out.push_back(
static_cast<xtd::char32>(codepoint));
1216 if (expected_bytes != 0) out.push_back(0xfffd);
1221inline std::basic_string<char> __xtd_convert_to_string<char, char>(
const std::basic_string<char>& str)
noexcept {
1226inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1231inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1236inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1241inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1246inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(
const std::basic_string<char>& str)
noexcept {
1247 return reinterpret_cast<const xtd::char8*
>(str.c_str());
1251inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1252 return reinterpret_cast<const char*
>(str.c_str());
1256inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1257 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1261inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1262 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1266inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1267 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1271inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1272 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1276inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1277 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
1281inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1282 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:71
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:1527
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:1541
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:49
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:59
@ format_opened_bracket_without_end_bracket
The format contains open backet_without_end_bracket.
Definition exception_case.hpp:53
@ format_closing_bracket_without_open_bracket
The format contains close backet_without_open_bracket.
Definition exception_case.hpp:51
#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