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 return format(std::locale {}, fmt, std::forward<args_t>(args)...);
270template<
class char_t,
class traits_t,
class allocator_t>
271template<
class ...args_t>
273 auto result = basic_string<char> {};
275 auto formats = std::vector<__format_information<char>> {};
276 auto begin_format_iterator = fmt.end();
277 auto end_format_iterator = fmt.end();
278 for (
auto iterator = fmt.begin(); iterator != fmt.end(); ++iterator) {
279 if (*iterator ==
'{') {
280 if (++iterator == fmt.end())
282 if (*iterator ==
'{')
285 begin_format_iterator = iterator;
286 while (iterator != fmt.end() && *iterator !=
'}') ++iterator;
287 if (iterator == fmt.end())
289 end_format_iterator = iterator;
290 __format_information<char> fi;
291 fi.location = result.length();
292 auto format_str = std::basic_string<char> {begin_format_iterator, end_format_iterator};
293 if (format_str.length() == 0)
296 xtd::size index_alignment_separator = basic_string(format_str).index_of(
',');
297 xtd::size index_format_separator = basic_string(format_str).index_of(u
':');
299 if (index_alignment_separator != std::basic_string<char>::npos && index_format_separator != std::basic_string<char>::npos && index_alignment_separator > index_format_separator)
300 index_alignment_separator = std::basic_string<char>::npos;
302 if (index_alignment_separator != basic_string<char_t>::npos)
303 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);
305 if (index_format_separator != basic_string<char>::npos)
306 fi.format = format_str.substr(index_format_separator + 1);
308 if (index_alignment_separator == 0 || index_format_separator == 0)
311 auto index_str = std::basic_string<char> {};
312 if (index_alignment_separator != basic_string<char>::npos)
313 index_str = format_str.substr(0, index_alignment_separator);
314 else if (index_format_separator != basic_string<char>::npos)
315 index_str = format_str.substr(0, index_format_separator);
317 index_str = std::move(format_str);
319 for (
auto c : index_str)
321 fi.index = std::stoi(index_str);
327 formats.push_back(fi);
329 }
else if (*iterator ==
'}') {
330 if (++iterator == fmt.end())
332 if (*iterator !=
'}')
339 __basic_string_extract_format_arg(loc, result, formats, std::forward<args_t>(args)...);
340 return result.chars().c_str();
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>
356template<
class value_t>
361template<
class char_t,
class traits_t,
class allocator_t>
364template<
class char_t,
class traits_t,
class allocator_t>
367template<
class char_t,
class traits_t,
class allocator_t>
371void __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) {
374 for (
auto& format : formats) {
375 format.location += offset;
376 if (
format.index == index) {
380 if (!
format.alignment.empty()) {
383 alignment = std::stoi(
format.alignment);
387 if (alignment > 0) arg_str = arg_str.
pad_left(alignment);
388 else if (alignment < 0) arg_str = arg_str.
pad_right(-alignment);
390 fmt.insert(
format.location, arg_str);
391 offset += arg_str.length();
397template<
class ...args_t>
398void __basic_string_extract_format_arg(
const std::locale& loc,
xtd::basic_string<char>& fmt, std::vector<__format_information<char >> & formats, args_t&&... args) {
400 (__basic_string_extract_format_arg(loc,
const_cast<std::basic_string<char>&
> (fmt.chars()), index, formats, args), ...);
405template<
class target_t,
class source_t>
406inline std::basic_string<target_t> __xtd_convert_to_string(std::basic_string<source_t>&& str)
noexcept {
407 auto out = std::basic_string<target_t> {};
409 for (
const auto& character : str) {
410 if (character >= 0xd800 && character <= 0xdbff)
411 codepoint = ((
character - 0xd800) << 10) + 0x10000;
413 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
416 if (codepoint <= 0x7f)
417 out.append(1,
static_cast<target_t
>(codepoint));
418 else if (codepoint <= 0x7ff) {
419 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
420 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
421 }
else if (codepoint <= 0xffff) {
422 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
423 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
424 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
426 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
427 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
428 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
429 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
441inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(std::basic_string<char>&& str)
noexcept {
442 auto out = std::basic_string<xtd::char16> {};
444 auto expected_bytes = 0;
445 auto str_ptr = str.data();
447 while (*str_ptr != 0) {
448 auto ch =
static_cast<unsigned char>(*str_ptr++);
450 if (expected_bytes == 0) {
455 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
456 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
457 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
460 out.push_back(0xfffd);
465 if ((ch & 0xc0) != 0x80) {
467 out.push_back(0xfffd);
472 codepoint = (codepoint << 6) | (ch & 0x3f);
477 if (expected_bytes == 0) {
478 if (codepoint > 0x10ffff) codepoint = 0xfffd;
480 if (codepoint > 0xffff) {
482 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
483 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
486 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
487 else out.push_back(0xfffd);
492 if (expected_bytes != 0) out.push_back(0xfffd);
500inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
501 auto out = std::basic_string<xtd::char16> {};
503 auto expected_bytes = 0;
504 auto str_ptr = str.data();
506 while (*str_ptr != 0) {
507 auto ch =
static_cast<unsigned char>(*str_ptr++);
509 if (expected_bytes == 0) {
514 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
515 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
516 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
519 out.push_back(0xfffd);
524 if ((ch & 0xc0) != 0x80) {
526 out.push_back(0xfffd);
531 codepoint = (codepoint << 6) | (ch & 0x3f);
536 if (expected_bytes == 0) {
537 if (codepoint > 0x10ffff) codepoint = 0xfffd;
539 if (codepoint > 0xffff) {
541 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
542 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
545 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
546 else out.push_back(0xfffd);
551 if (expected_bytes != 0) out.push_back(0xfffd);
559inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(std::basic_string<char>&& str)
noexcept {
560 auto out = std::basic_string<xtd::wchar> {};
562 auto expected_bytes = 0;
563 auto str_ptr = str.data();
565 while (*str_ptr != 0) {
566 auto ch =
static_cast<unsigned char>(*str_ptr++);
568 if (expected_bytes == 0) {
573 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
574 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
575 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
577 out.push_back(0xfffd);
582 if ((ch & 0xc0) != 0x80) {
584 out.push_back(0xfffd);
589 codepoint = (codepoint << 6) | (ch & 0x3f);
594 if (expected_bytes == 0) {
595 if (codepoint > 0x10ffff) codepoint = 0xfffd;
599 out.push_back(
static_cast<xtd::wchar>(codepoint));
602 if (codepoint > 0xffff) {
603 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
604 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
607 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
608 out.push_back(
static_cast<xtd::wchar>(codepoint));
611 out.push_back(0xfffd);
618 if (expected_bytes != 0) out.push_back(0xfffd);
626inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
627 auto out = std::basic_string<xtd::wchar> {};
629 auto expected_bytes = 0;
630 auto str_ptr = str.data();
632 while (*str_ptr != 0) {
633 auto ch =
static_cast<unsigned char>(*str_ptr++);
635 if (expected_bytes == 0) {
640 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
641 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
642 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
644 out.push_back(0xfffd);
649 if ((ch & 0xc0) != 0x80) {
651 out.push_back(0xfffd);
656 codepoint = (codepoint << 6) | (ch & 0x3f);
661 if (expected_bytes == 0) {
662 if (codepoint > 0x10ffff) codepoint = 0xfffd;
666 out.push_back(
static_cast<xtd::wchar>(codepoint));
669 if (codepoint > 0xffff) {
670 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
671 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
674 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
675 out.push_back(
static_cast<xtd::wchar>(codepoint));
678 out.push_back(0xfffd);
685 if (expected_bytes != 0) out.push_back(0xfffd);
693inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(std::basic_string<char>&& str)
noexcept {
694 auto out = std::basic_string<xtd::char32> {};
696 auto expected_bytes = 0;
697 auto str_ptr = str.data();
699 while (*str_ptr != 0) {
700 auto ch =
static_cast<unsigned char>(*str_ptr++);
702 if (expected_bytes == 0) {
706 out.push_back(
static_cast<xtd::char32>(codepoint));
707 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
708 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
709 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
710 else out.push_back(0xfffd);
713 if ((ch & 0xc0) != 0x80) {
715 out.push_back(0xfffd);
720 codepoint = (codepoint << 6) | (ch & 0x3f);
723 if (expected_bytes == 0) {
725 if (codepoint > 0x10ffff) codepoint = 0xfffd;
726 out.push_back(
static_cast<xtd::char32>(codepoint));
732 if (expected_bytes != 0) out.push_back(0xfffd);
740inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
741 auto out = std::basic_string<xtd::char32> {};
743 auto expected_bytes = 0;
744 auto str_ptr = str.data();
746 while (*str_ptr != 0) {
747 auto ch =
static_cast<unsigned char>(*str_ptr++);
749 if (expected_bytes == 0) {
753 out.push_back(
static_cast<xtd::char32>(codepoint));
754 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
755 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
756 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
757 else out.push_back(0xfffd);
760 if ((ch & 0xc0) != 0x80) {
762 out.push_back(0xfffd);
767 codepoint = (codepoint << 6) | (ch & 0x3f);
770 if (expected_bytes == 0) {
772 if (codepoint > 0x10ffff) codepoint = 0xfffd;
773 out.push_back(
static_cast<xtd::char32>(codepoint));
779 if (expected_bytes != 0) out.push_back(0xfffd);
784inline std::basic_string<char> __xtd_convert_to_string<char, char>(std::basic_string<char>&& str)
noexcept {
785 return std::move(str);
789inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
790 return std::move(str);
794inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
795 return std::move(str);
799inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
800 return std::move(str);
804inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
805 return std::move(str);
809inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(std::basic_string<char>&& str)
noexcept {
810 return std::basic_string<xtd::char8> {
reinterpret_cast<const xtd::char8*
>(str.c_str())};
814inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
815 return std::basic_string<char> {
reinterpret_cast<const char*
>(str.c_str())};
819inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
820 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
824inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
825 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
829inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
830 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
834inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
835 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
839inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
840 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
844inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
845 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
848template<
class target_t,
class source_t>
849inline std::basic_string<target_t> __xtd_convert_to_string(
const std::basic_string<source_t>& str)
noexcept {
850 auto out = std::basic_string<target_t> {};
852 for (
const auto& character : str) {
853 if (character >= 0xd800 && character <= 0xdbff)
854 codepoint = ((
character - 0xd800) << 10) + 0x10000;
856 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
859 if (codepoint <= 0x7f)
860 out.append(1,
static_cast<target_t
>(codepoint));
861 else if (codepoint <= 0x7ff) {
862 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
863 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
864 }
else if (codepoint <= 0xffff) {
865 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
866 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
867 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
869 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
870 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
871 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
872 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
884inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(
const std::basic_string<char>& str)
noexcept {
885 auto out = std::basic_string<xtd::char16> {};
887 auto expected_bytes = 0;
888 auto str_ptr = str.data();
890 while (*str_ptr != 0) {
891 auto ch =
static_cast<unsigned char>(*str_ptr++);
893 if (expected_bytes == 0) {
898 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
899 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
900 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
903 out.push_back(0xfffd);
908 if ((ch & 0xc0) != 0x80) {
910 out.push_back(0xfffd);
915 codepoint = (codepoint << 6) | (ch & 0x3f);
920 if (expected_bytes == 0) {
921 if (codepoint > 0x10ffff) codepoint = 0xfffd;
923 if (codepoint > 0xffff) {
925 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
926 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
929 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
930 else out.push_back(0xfffd);
935 if (expected_bytes != 0) out.push_back(0xfffd);
943inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
944 auto out = std::basic_string<xtd::char16> {};
946 auto expected_bytes = 0;
947 auto str_ptr = str.data();
949 while (*str_ptr != 0) {
950 auto ch =
static_cast<unsigned char>(*str_ptr++);
952 if (expected_bytes == 0) {
957 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
958 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
959 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
962 out.push_back(0xfffd);
967 if ((ch & 0xc0) != 0x80) {
969 out.push_back(0xfffd);
974 codepoint = (codepoint << 6) | (ch & 0x3f);
979 if (expected_bytes == 0) {
980 if (codepoint > 0x10ffff) codepoint = 0xfffd;
982 if (codepoint > 0xffff) {
984 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
985 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
988 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
989 else out.push_back(0xfffd);
994 if (expected_bytes != 0) out.push_back(0xfffd);
1002inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(
const std::basic_string<char>& str)
noexcept {
1003 auto out = std::basic_string<xtd::wchar> {};
1004 auto codepoint = 0
u;
1005 auto expected_bytes = 0;
1006 auto str_ptr = str.data();
1008 while (*str_ptr != 0) {
1009 auto ch =
static_cast<unsigned char>(*str_ptr++);
1011 if (expected_bytes == 0) {
1016 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1017 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1018 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1020 out.push_back(0xfffd);
1025 if ((ch & 0xc0) != 0x80) {
1027 out.push_back(0xfffd);
1032 codepoint = (codepoint << 6) | (ch & 0x3f);
1037 if (expected_bytes == 0) {
1038 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1042 out.push_back(
static_cast<xtd::wchar>(codepoint));
1045 if (codepoint > 0xffff) {
1046 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1047 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1048 out.push_back(
static_cast<xtd::wchar>(high));
1050 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1051 out.push_back(
static_cast<xtd::wchar>(codepoint));
1054 out.push_back(0xfffd);
1061 if (expected_bytes != 0) out.push_back(0xfffd);
1069inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1070 auto out = std::basic_string<xtd::wchar> {};
1071 auto codepoint = 0
u;
1072 auto expected_bytes = 0;
1073 auto str_ptr = str.data();
1075 while (*str_ptr != 0) {
1076 auto ch =
static_cast<unsigned char>(*str_ptr++);
1078 if (expected_bytes == 0) {
1083 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1084 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1085 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1087 out.push_back(0xfffd);
1092 if ((ch & 0xc0) != 0x80) {
1094 out.push_back(0xfffd);
1099 codepoint = (codepoint << 6) | (ch & 0x3f);
1104 if (expected_bytes == 0) {
1105 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1109 out.push_back(
static_cast<xtd::wchar>(codepoint));
1112 if (codepoint > 0xffff) {
1113 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1114 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1115 out.push_back(
static_cast<xtd::wchar>(high));
1117 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1118 out.push_back(
static_cast<xtd::wchar>(codepoint));
1121 out.push_back(0xfffd);
1128 if (expected_bytes != 0) out.push_back(0xfffd);
1136inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(
const std::basic_string<char>& str)
noexcept {
1137 auto out = std::basic_string<xtd::char32> {};
1138 auto codepoint = 0
u;
1139 auto expected_bytes = 0;
1140 auto str_ptr = str.data();
1142 while (*str_ptr != 0) {
1143 auto ch =
static_cast<unsigned char>(*str_ptr++);
1145 if (expected_bytes == 0) {
1149 out.push_back(
static_cast<xtd::char32>(codepoint));
1150 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1151 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1152 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1153 else out.push_back(0xfffd);
1156 if ((ch & 0xc0) != 0x80) {
1158 out.push_back(0xfffd);
1163 codepoint = (codepoint << 6) | (ch & 0x3f);
1166 if (expected_bytes == 0) {
1168 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1169 out.push_back(
static_cast<xtd::char32>(codepoint));
1175 if (expected_bytes != 0) out.push_back(0xfffd);
1183inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1184 auto out = std::basic_string<xtd::char32> {};
1185 auto codepoint = 0
u;
1186 auto expected_bytes = 0;
1187 auto str_ptr = str.data();
1189 while (*str_ptr != 0) {
1190 auto ch =
static_cast<unsigned char>(*str_ptr++);
1192 if (expected_bytes == 0) {
1196 out.push_back(
static_cast<xtd::char32>(codepoint));
1197 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1198 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1199 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1200 else out.push_back(0xfffd);
1203 if ((ch & 0xc0) != 0x80) {
1205 out.push_back(0xfffd);
1210 codepoint = (codepoint << 6) | (ch & 0x3f);
1213 if (expected_bytes == 0) {
1215 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1216 out.push_back(
static_cast<xtd::char32>(codepoint));
1222 if (expected_bytes != 0) out.push_back(0xfffd);
1227inline std::basic_string<char> __xtd_convert_to_string<char, char>(
const std::basic_string<char>& str)
noexcept {
1232inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1237inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1242inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1247inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1252inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(
const std::basic_string<char>& str)
noexcept {
1253 return reinterpret_cast<const xtd::char8*
>(str.c_str());
1257inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1258 return reinterpret_cast<const char*
>(str.c_str());
1262inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1263 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1267inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1268 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1272inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1273 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1277inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1278 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1282inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1283 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
1287inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1288 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:1526
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:1540
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