8#if defined(_MSC_VER) && defined(max)
9# if __cplusplus < 202302L
10# pragma message("The macro `max` is defined. If you include the `Windows.h` file, please define the 'NOMINMAX' constant before including `Windows.h`. xtd will undef the `max` macro.")
12# warning "The macro `max` is defined. If you include the `Windows.h` file, please define the 'NOMINMAX' constant before including `Windows.h`. xtd will undef the `max` macro."
17#define __XTD_CORE_INTERNAL__
19#undef __XTD_CORE_INTERNAL__
33 template<
typename value_t>
34 inline value_t
parse(
const std::string& str) {
35 if (std::is_enum<value_t>::value)
return __parse_enum<value_t>(str);
36 __throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
46 template<
typename value_t>
47 inline value_t
parse(
const std::string& str,
const std::locale& locale) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
55 template<
typename value_t>
56 inline value_t
parse(
const std::string& str,
const std::string& fmt) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
73 template<
typename value_t>
74 inline value_t
parse(
const std::string& str,
number_styles) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
82 template<
typename value_t>
83 inline value_t
parse(
const std::string& str,
number_styles,
const std::locale& locale) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
191 inline float parse<float>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<float>(str, styles, std::locale());}
200 inline float parse<float>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<float>(str, styles, locale);}
209 inline double parse<double>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<double>(str, styles, std::locale());}
218 inline double parse<double>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<double>(str, styles, locale);}
236 inline long double parse<long double>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<long double>(str, styles, locale);}
372 std::string lower_str = str;
373 while (lower_str.size() > 0 && (lower_str[0] == 9 || lower_str[0] == 10 || lower_str[0] == 11 || lower_str[0] == 12 || lower_str[0] == 13 || lower_str[0] == 32))
374 lower_str.erase(0, 1);
375 while (lower_str.size() > 0 && (lower_str[lower_str.size() - 1] == 9 || lower_str[lower_str.size() - 1] == 10 || lower_str[lower_str.size() - 1] == 11 || lower_str[lower_str.size() - 1] == 12 || lower_str[lower_str.size() - 1] == 13 || lower_str[lower_str.size() - 1] == 32))
376 lower_str.erase(lower_str.size() - 1, 1);
377 for (
auto&
c : lower_str)
378 c =
static_cast<char>(std::tolower(
c));
379 if (lower_str !=
"true" && lower_str !=
"1" && lower_str !=
"false" && lower_str !=
"0") __throw_parse_format_exception(
"Invalid string format", __FILE__, __LINE__, __func__);
380 return lower_str ==
"true" || lower_str ==
"1";
389 template<
typename value_t>
390 inline value_t
parse(
const std::wstring& str) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
398 template<
typename value_t>
399 inline value_t
parse(
const std::u16string& str) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
407 template<
typename value_t>
408 inline value_t
parse(
const std::u32string& str) {__throw_parse_format_exception(
"Parse specialisation not found", __FILE__, __LINE__, __func__);
return {};}
416 template<
typename value_t>
417 inline bool try_parse(
const std::basic_string<char>& str, value_t& value)
noexcept {
419 value = parse<value_t>(str);
431 template<
typename value_t>
432 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value)
noexcept {
434 value = parse<value_t>(str);
446 template<
typename value_t>
447 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value)
noexcept {
449 value = parse<value_t>(str);
455#if defined(__xtd__cpp_lib_char8_t)
462 template<
typename value_t>
463 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value)
noexcept {
465 value = parse<value_t>(str);
478 template<
typename value_t>
479 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value)
noexcept {
481 value = parse<value_t>(str);
494 template<
typename value_t>
495 inline bool try_parse(
const std::basic_string<char>& str, value_t& value,
const std::locale& locale)
noexcept {
497 value = parse<value_t>(str, locale);
509 template<
typename value_t>
510 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value,
const std::locale& locale)
noexcept {
512 value = parse<value_t>(str, locale);
524 template<
typename value_t>
525 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value,
const std::locale& locale)
noexcept {
527 value = parse<value_t>(str, locale);
533#if defined(__xtd__cpp_lib_char8_t)
540 template<
typename value_t>
541 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value,
const std::locale& locale)
noexcept {
543 value = parse<value_t>(str, locale);
556 template<
typename value_t>
557 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value,
const std::locale& locale)
noexcept {
559 value = parse<value_t>(str, locale);
572 template<
typename value_t,
typename char_t>
573 inline bool try_parse(
const char_t* str, value_t& value)
noexcept {
574 return try_parse(std::basic_string<char_t>(str), value);
583 template<
typename value_t,
typename char_t>
584 inline bool try_parse(
const char_t* str, value_t& value,
const std::locale& locale)
noexcept {
585 return try_parse(std::basic_string<char_t>(str), value, locale);
594 template<
typename value_t>
597 value = parse<value_t>(str, style);
609 template<
typename value_t>
612 value = parse<value_t>(str, style);
624 template<
typename value_t>
627 value = parse<value_t>(str, style);
633#if defined(__xtd__cpp_lib_char8_t)
640 template<
typename value_t>
643 value = parse<value_t>(str, style);
656 template<
typename value_t>
659 value = parse<value_t>(str, style);
672 template<
typename value_t>
673 inline bool try_parse(
const std::basic_string<char>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
675 value = parse<value_t>(str, style, locale);
687 template<
typename value_t>
688 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
690 value = parse<value_t>(str, style, locale);
702 template<
typename value_t>
703 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
705 value = parse<value_t>(str, style, locale);
711#if defined(__xtd__cpp_lib_char8_t)
718 template<
typename value_t>
719 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
721 value = parse<value_t>(str, style, locale);
734 template<
typename value_t>
735 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
737 value = parse<value_t>(str, style, locale);
750 template<
typename value_t,
typename char_t>
752 return try_parse(std::basic_string<char_t>(str), value, style);
761 template<
typename value_t,
typename char_t>
763 return try_parse(std::basic_string<char_t>(str), value, style, locale);
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.h:23
double parse< double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:209
number_styles
Determines the styles permitted in numeric string arguments that are passed to the xtd::parse and xtd...
Definition number_styles.h:16
char parse< char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:101
bool parse< bool >(const std::string &str)
Convert a string into a type.
Definition parse.h:371
xtd::sbyte parse< xtd::sbyte >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:92
unsigned long parse< unsigned long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:164
long long parse< long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:173
long double parse< long double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:227
int parse< int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:137
long parse< long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:155
unsigned char parse< unsigned char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:110
std::string parse< std::string >(const std::string &str)
Convert a string into a type.
Definition parse.h:65
float parse< float >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:191
short parse< short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:119
unsigned int parse< unsigned int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:146
unsigned short parse< unsigned short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:128
unsigned long long parse< unsigned long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.h:182
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.h:34
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.h:417
@ integer
Indicates that the allow_leading_white, allow_trailing_white, and allow_leading_sign styles are used....
@ fixed_point
Indicates that the allow_leading_white, allow_trailing_white, allow_leading_sign, allow_decimal_point...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::number_styles enum class.
Contains xtd fundamental types.