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) {
378 if (!
format.alignment.empty()) {
381 alignment = std::stoi(
format.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) {
398 (__basic_string_extract_format_arg(loc,
const_cast<std::basic_string<char>&
> (fmt.chars()), index, formats, args), ...);
403template<
class target_t,
class source_t>
404inline std::basic_string<target_t> __xtd_convert_to_string(std::basic_string<source_t>&& str)
noexcept {
405 auto out = std::basic_string<target_t> {};
407 for (
const auto& character : str) {
408 if (character >= 0xd800 && character <= 0xdbff)
409 codepoint = ((
character - 0xd800) << 10) + 0x10000;
411 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
414 if (codepoint <= 0x7f)
415 out.append(1,
static_cast<target_t
>(codepoint));
416 else if (codepoint <= 0x7ff) {
417 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
418 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
419 }
else if (codepoint <= 0xffff) {
420 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
421 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
422 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
424 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
425 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
426 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
427 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
439inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(std::basic_string<char>&& str)
noexcept {
440 auto out = std::basic_string<xtd::char16> {};
442 auto expected_bytes = 0;
443 auto str_ptr = str.data();
445 while (*str_ptr != 0) {
446 auto ch =
static_cast<unsigned char>(*str_ptr++);
448 if (expected_bytes == 0) {
453 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
454 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
455 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
458 out.push_back(0xfffd);
463 if ((ch & 0xc0) != 0x80) {
465 out.push_back(0xfffd);
470 codepoint = (codepoint << 6) | (ch & 0x3f);
475 if (expected_bytes == 0) {
476 if (codepoint > 0x10ffff) codepoint = 0xfffd;
478 if (codepoint > 0xffff) {
480 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
481 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
484 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
485 else out.push_back(0xfffd);
490 if (expected_bytes != 0) out.push_back(0xfffd);
498inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
499 auto out = std::basic_string<xtd::char16> {};
501 auto expected_bytes = 0;
502 auto str_ptr = str.data();
504 while (*str_ptr != 0) {
505 auto ch =
static_cast<unsigned char>(*str_ptr++);
507 if (expected_bytes == 0) {
512 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
513 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
514 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
517 out.push_back(0xfffd);
522 if ((ch & 0xc0) != 0x80) {
524 out.push_back(0xfffd);
529 codepoint = (codepoint << 6) | (ch & 0x3f);
534 if (expected_bytes == 0) {
535 if (codepoint > 0x10ffff) codepoint = 0xfffd;
537 if (codepoint > 0xffff) {
539 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
540 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
543 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
544 else out.push_back(0xfffd);
549 if (expected_bytes != 0) out.push_back(0xfffd);
557inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(std::basic_string<char>&& str)
noexcept {
558 auto out = std::basic_string<xtd::wchar> {};
560 auto expected_bytes = 0;
561 auto str_ptr = str.data();
563 while (*str_ptr != 0) {
564 auto ch =
static_cast<unsigned char>(*str_ptr++);
566 if (expected_bytes == 0) {
571 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
572 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
573 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
575 out.push_back(0xfffd);
580 if ((ch & 0xc0) != 0x80) {
582 out.push_back(0xfffd);
587 codepoint = (codepoint << 6) | (ch & 0x3f);
592 if (expected_bytes == 0) {
593 if (codepoint > 0x10ffff) codepoint = 0xfffd;
597 out.push_back(
static_cast<xtd::wchar>(codepoint));
600 if (codepoint > 0xffff) {
601 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
602 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
605 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
606 out.push_back(
static_cast<xtd::wchar>(codepoint));
609 out.push_back(0xfffd);
616 if (expected_bytes != 0) out.push_back(0xfffd);
624inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
625 auto out = std::basic_string<xtd::wchar> {};
627 auto expected_bytes = 0;
628 auto str_ptr = str.data();
630 while (*str_ptr != 0) {
631 auto ch =
static_cast<unsigned char>(*str_ptr++);
633 if (expected_bytes == 0) {
638 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
639 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
640 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
642 out.push_back(0xfffd);
647 if ((ch & 0xc0) != 0x80) {
649 out.push_back(0xfffd);
654 codepoint = (codepoint << 6) | (ch & 0x3f);
659 if (expected_bytes == 0) {
660 if (codepoint > 0x10ffff) codepoint = 0xfffd;
664 out.push_back(
static_cast<xtd::wchar>(codepoint));
667 if (codepoint > 0xffff) {
668 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
669 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
672 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
673 out.push_back(
static_cast<xtd::wchar>(codepoint));
676 out.push_back(0xfffd);
683 if (expected_bytes != 0) out.push_back(0xfffd);
691inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(std::basic_string<char>&& str)
noexcept {
692 auto out = std::basic_string<xtd::char32> {};
694 auto expected_bytes = 0;
695 auto str_ptr = str.data();
697 while (*str_ptr != 0) {
698 auto ch =
static_cast<unsigned char>(*str_ptr++);
700 if (expected_bytes == 0) {
704 out.push_back(
static_cast<xtd::char32>(codepoint));
705 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
706 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
707 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
708 else out.push_back(0xfffd);
711 if ((ch & 0xc0) != 0x80) {
713 out.push_back(0xfffd);
718 codepoint = (codepoint << 6) | (ch & 0x3f);
721 if (expected_bytes == 0) {
723 if (codepoint > 0x10ffff) codepoint = 0xfffd;
724 out.push_back(
static_cast<xtd::char32>(codepoint));
730 if (expected_bytes != 0) out.push_back(0xfffd);
738inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
739 auto out = std::basic_string<xtd::char32> {};
741 auto expected_bytes = 0;
742 auto str_ptr = str.data();
744 while (*str_ptr != 0) {
745 auto ch =
static_cast<unsigned char>(*str_ptr++);
747 if (expected_bytes == 0) {
751 out.push_back(
static_cast<xtd::char32>(codepoint));
752 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
753 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
754 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
755 else out.push_back(0xfffd);
758 if ((ch & 0xc0) != 0x80) {
760 out.push_back(0xfffd);
765 codepoint = (codepoint << 6) | (ch & 0x3f);
768 if (expected_bytes == 0) {
770 if (codepoint > 0x10ffff) codepoint = 0xfffd;
771 out.push_back(
static_cast<xtd::char32>(codepoint));
777 if (expected_bytes != 0) out.push_back(0xfffd);
782inline std::basic_string<char> __xtd_convert_to_string<char, char>(std::basic_string<char>&& str)
noexcept {
783 return std::move(str);
787inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
788 return std::move(str);
792inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
793 return std::move(str);
797inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
798 return std::move(str);
802inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
803 return std::move(str);
807inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(std::basic_string<char>&& str)
noexcept {
808 return std::basic_string<xtd::char8> {
reinterpret_cast<const xtd::char8*
>(str.c_str())};
812inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(std::basic_string<xtd::char8>&& str)
noexcept {
813 return std::basic_string<char> {
reinterpret_cast<const char*
>(str.c_str())};
817inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
818 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
822inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
823 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(std::move(str)));
827inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
828 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
832inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(std::basic_string<xtd::wchar>&& str)
noexcept {
833 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(std::move(str)));
837inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(std::basic_string<xtd::char16>&& str)
noexcept {
838 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
842inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(std::basic_string<xtd::char32>&& str)
noexcept {
843 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(std::move(str)));
846template<
class target_t,
class source_t>
847inline std::basic_string<target_t> __xtd_convert_to_string(
const std::basic_string<source_t>& str)
noexcept {
848 auto out = std::basic_string<target_t> {};
850 for (
const auto& character : str) {
851 if (character >= 0xd800 && character <= 0xdbff)
852 codepoint = ((
character - 0xd800) << 10) + 0x10000;
854 if (character >= 0xdc00 && character <= 0xdfff) codepoint |=
character - 0xdc00;
857 if (codepoint <= 0x7f)
858 out.append(1,
static_cast<target_t
>(codepoint));
859 else if (codepoint <= 0x7ff) {
860 out.append(1,
static_cast<target_t
>(0xc0 | ((codepoint >> 6) & 0x1f)));
861 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
862 }
else if (codepoint <= 0xffff) {
863 out.append(1,
static_cast<target_t
>(0xe0 | ((codepoint >> 12) & 0x0f)));
864 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
865 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
867 out.append(1,
static_cast<target_t
>(0xf0 | ((codepoint >> 18) & 0x07)));
868 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 12) & 0x3f)));
869 out.append(1,
static_cast<target_t
>(0x80 | ((codepoint >> 6) & 0x3f)));
870 out.append(1,
static_cast<target_t
>(0x80 | (codepoint & 0x3f)));
882inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, char>(
const std::basic_string<char>& str)
noexcept {
883 auto out = std::basic_string<xtd::char16> {};
885 auto expected_bytes = 0;
886 auto str_ptr = str.data();
888 while (*str_ptr != 0) {
889 auto ch =
static_cast<unsigned char>(*str_ptr++);
891 if (expected_bytes == 0) {
896 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
897 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
898 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
901 out.push_back(0xfffd);
906 if ((ch & 0xc0) != 0x80) {
908 out.push_back(0xfffd);
913 codepoint = (codepoint << 6) | (ch & 0x3f);
918 if (expected_bytes == 0) {
919 if (codepoint > 0x10ffff) codepoint = 0xfffd;
921 if (codepoint > 0xffff) {
923 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
924 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
927 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
928 else out.push_back(0xfffd);
933 if (expected_bytes != 0) out.push_back(0xfffd);
941inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
942 auto out = std::basic_string<xtd::char16> {};
944 auto expected_bytes = 0;
945 auto str_ptr = str.data();
947 while (*str_ptr != 0) {
948 auto ch =
static_cast<unsigned char>(*str_ptr++);
950 if (expected_bytes == 0) {
955 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
956 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
957 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
960 out.push_back(0xfffd);
965 if ((ch & 0xc0) != 0x80) {
967 out.push_back(0xfffd);
972 codepoint = (codepoint << 6) | (ch & 0x3f);
977 if (expected_bytes == 0) {
978 if (codepoint > 0x10ffff) codepoint = 0xfffd;
980 if (codepoint > 0xffff) {
982 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
983 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
986 }
else if (codepoint < 0xd800 || codepoint >= 0xe000) out.push_back(
static_cast<xtd::char16>(codepoint));
987 else out.push_back(0xfffd);
992 if (expected_bytes != 0) out.push_back(0xfffd);
1000inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, char>(
const std::basic_string<char>& str)
noexcept {
1001 auto out = std::basic_string<xtd::wchar> {};
1002 auto codepoint = 0
u;
1003 auto expected_bytes = 0;
1004 auto str_ptr = str.data();
1006 while (*str_ptr != 0) {
1007 auto ch =
static_cast<unsigned char>(*str_ptr++);
1009 if (expected_bytes == 0) {
1014 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1015 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1016 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1018 out.push_back(0xfffd);
1023 if ((ch & 0xc0) != 0x80) {
1025 out.push_back(0xfffd);
1030 codepoint = (codepoint << 6) | (ch & 0x3f);
1035 if (expected_bytes == 0) {
1036 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1040 out.push_back(
static_cast<xtd::wchar>(codepoint));
1043 if (codepoint > 0xffff) {
1044 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1045 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1046 out.push_back(
static_cast<xtd::wchar>(high));
1048 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1049 out.push_back(
static_cast<xtd::wchar>(codepoint));
1052 out.push_back(0xfffd);
1059 if (expected_bytes != 0) out.push_back(0xfffd);
1067inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1068 auto out = std::basic_string<xtd::wchar> {};
1069 auto codepoint = 0
u;
1070 auto expected_bytes = 0;
1071 auto str_ptr = str.data();
1073 while (*str_ptr != 0) {
1074 auto ch =
static_cast<unsigned char>(*str_ptr++);
1076 if (expected_bytes == 0) {
1081 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1082 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1083 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1085 out.push_back(0xfffd);
1090 if ((ch & 0xc0) != 0x80) {
1092 out.push_back(0xfffd);
1097 codepoint = (codepoint << 6) | (ch & 0x3f);
1102 if (expected_bytes == 0) {
1103 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1107 out.push_back(
static_cast<xtd::wchar>(codepoint));
1110 if (codepoint > 0xffff) {
1111 unsigned int high = 0xd800 + ((codepoint - 0x10000) >> 10);
1112 unsigned int low = 0xdc00 + ((codepoint - 0x10000) & 0x3ff);
1113 out.push_back(
static_cast<xtd::wchar>(high));
1115 }
else if (codepoint < 0xd800 || codepoint >= 0xe000)
1116 out.push_back(
static_cast<xtd::wchar>(codepoint));
1119 out.push_back(0xfffd);
1126 if (expected_bytes != 0) out.push_back(0xfffd);
1134inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, char>(
const std::basic_string<char>& str)
noexcept {
1135 auto out = std::basic_string<xtd::char32> {};
1136 auto codepoint = 0
u;
1137 auto expected_bytes = 0;
1138 auto str_ptr = str.data();
1140 while (*str_ptr != 0) {
1141 auto ch =
static_cast<unsigned char>(*str_ptr++);
1143 if (expected_bytes == 0) {
1147 out.push_back(
static_cast<xtd::char32>(codepoint));
1148 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1149 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1150 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1151 else out.push_back(0xfffd);
1154 if ((ch & 0xc0) != 0x80) {
1156 out.push_back(0xfffd);
1161 codepoint = (codepoint << 6) | (ch & 0x3f);
1164 if (expected_bytes == 0) {
1166 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1167 out.push_back(
static_cast<xtd::char32>(codepoint));
1173 if (expected_bytes != 0) out.push_back(0xfffd);
1181inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1182 auto out = std::basic_string<xtd::char32> {};
1183 auto codepoint = 0
u;
1184 auto expected_bytes = 0;
1185 auto str_ptr = str.data();
1187 while (*str_ptr != 0) {
1188 auto ch =
static_cast<unsigned char>(*str_ptr++);
1190 if (expected_bytes == 0) {
1194 out.push_back(
static_cast<xtd::char32>(codepoint));
1195 }
else if (ch <= 0xdf) { codepoint = ch & 0x1f; expected_bytes = 1; }
1196 else if (ch <= 0xef) { codepoint = ch & 0x0f; expected_bytes = 2; }
1197 else if (ch <= 0xf7) { codepoint = ch & 0x07; expected_bytes = 3; }
1198 else out.push_back(0xfffd);
1201 if ((ch & 0xc0) != 0x80) {
1203 out.push_back(0xfffd);
1208 codepoint = (codepoint << 6) | (ch & 0x3f);
1211 if (expected_bytes == 0) {
1213 if (codepoint > 0x10ffff) codepoint = 0xfffd;
1214 out.push_back(
static_cast<xtd::char32>(codepoint));
1220 if (expected_bytes != 0) out.push_back(0xfffd);
1225inline std::basic_string<char> __xtd_convert_to_string<char, char>(
const std::basic_string<char>& str)
noexcept {
1230inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1235inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1240inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1245inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1250inline std::basic_string<xtd::char8> __xtd_convert_to_string<xtd::char8, char>(
const std::basic_string<char>& str)
noexcept {
1251 return reinterpret_cast<const xtd::char8*
>(str.c_str());
1255inline std::basic_string<char> __xtd_convert_to_string<char, xtd::char8>(
const std::basic_string<xtd::char8>& str)
noexcept {
1256 return reinterpret_cast<const char*
>(str.c_str());
1260inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1261 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1265inline std::basic_string<xtd::char16> __xtd_convert_to_string<xtd::char16, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1266 return __xtd_convert_to_string<xtd::char16>(__xtd_convert_to_string<char>(str));
1270inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1271 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1275inline std::basic_string<xtd::char32> __xtd_convert_to_string<xtd::char32, xtd::wchar>(
const std::basic_string<xtd::wchar>& str)
noexcept {
1276 return __xtd_convert_to_string<xtd::char32>(__xtd_convert_to_string<char>(str));
1280inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char16>(
const std::basic_string<xtd::char16>& str)
noexcept {
1281 return __xtd_convert_to_string<xtd::wchar>(__xtd_convert_to_string<char>(str));
1285inline std::basic_string<xtd::wchar> __xtd_convert_to_string<xtd::wchar, xtd::char32>(
const std::basic_string<xtd::char32>& str)
noexcept {
1286 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:67
basic_string pad_left(xtd::size total_width) const noexcept
Right-aligns the characters in this basic_string, padding with spaces on the left for a specified tot...
Definition basic_string.hpp:1023
basic_string trim() const noexcept
Removes all leading and trailing occurrences of white-space characters from the specified xtd::basic_...
Definition basic_string.hpp:1408
xtd::array< basic_string > split() const noexcept
Splits this basic_string into substrings that are based on the default white-space characters....
static basic_string join(const basic_string &separator, const collection_t &values) noexcept
Concatenates a specified separator basic_string between each element of a specified object array,...
Definition basic_string.hpp:1702
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::array< value_type > to_char_array() const noexcept
Copies the characters in this instance to a Unicode character array.
static basic_string concat(const basic_string &str_a, const basic_string &str_b, const basic_string &str_c, const basic_string &str_d) noexcept
Concatenates four specified instances of basic_string.
Definition basic_string.hpp:1536
basic_string trim_end() const noexcept
Removes all trailing occurrences of white-space characters from the specified xtd::basic_string.
Definition basic_string.hpp:1424
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 to_title_case() const noexcept
Converts the current basic_string to title case (except for words that are entirely in uppercase,...
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:1037
basic_string trim_start() const noexcept
Removes all leading occurrences of white-space characters from the specified xtd::basic_string.
Definition basic_string.hpp:1440
xtd::array< value_type > to_array() const noexcept
Copies the characters in this instance to a Unicode character array.
basic_string< xtd::char32 > to_u32string() const noexcept
Converts the value of this instance to a xtd::basic_string <xtd::char32>.
Definition basic_string.hpp:1377
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
@ format
The format is not valid.
Definition exception_case.hpp:51
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:61
@ format_opened_bracket_without_end_bracket
The format contains open backet_without_end_bracket.
Definition exception_case.hpp:55
@ format_closing_bracket_without_open_bracket
The format contains close backet_without_open_bracket.
Definition exception_case.hpp:53
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
#define unused_
It may be used to suppress the "unused variable" or "unused local typedefs" compiler warnings when th...
Definition unused.hpp:30
constexpr xtd::size npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
@ character
Specifies that the text is trimmed to the nearest character.
Definition string_trimming.hpp:21
@ word
Specifies that text is trimmed to the nearest word.
Definition string_trimming.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
string_split_options
Specifies whether applicable xtd::string::split method overloads include or omit empty substrings fro...
Definition string_split_options.hpp:14
@ none
The return value includes array elements that contain an empty string.
Definition string_split_options.hpp:16
@ remove_empty_entries
The return value does not include array elements that contain an empty string.
Definition string_split_options.hpp:18
@ high
Specifies that the process performs time-critical tasks that must be executed immediately,...
Definition process_priority_class.hpp:32
@ u
The U key.
Definition console_key.hpp:128
@ separator
The Separator key.
Definition console_key.hpp:172
@ low
Specifies low quality interpolation.
Definition interpolation_mode.hpp:26
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:194
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
xtd::array< std::remove_cv_t< type_t > > to_array() const noexcept
Copies the contents of this read_only_span into a new array.
Definition read_only_span.hpp:368
Contains xtd::to_string methods.