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<
class 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);
45 template<
class value_t>
54 template<
class value_t>
72 template<
class value_t>
81 template<
class value_t>
190 inline float parse<float>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<float>(str, styles, std::locale());}
199 inline float parse<float>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<float>(str, styles, locale);}
208 inline double parse<double>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<double>(str, styles, std::locale());}
217 inline double parse<double>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<double>(str, styles, locale);}
235 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);}
371 std::string lower_str = str;
372 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))
373 lower_str.erase(0, 1);
374 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))
375 lower_str.erase(lower_str.size() - 1, 1);
376 for (
auto&
c : lower_str)
377 c =
static_cast<char>(std::tolower(
c));
379 return lower_str ==
"true" || lower_str ==
"1";
388 template<
class value_t>
397 template<
class value_t>
406 template<
class value_t>
415 template<
class value_t>
416 inline bool try_parse(
const std::basic_string<char>& str, value_t& value)
noexcept {
418 value = parse<value_t>(str);
430 template<
class value_t>
431 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value)
noexcept {
433 value = parse<value_t>(str);
445 template<
class value_t>
446 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value)
noexcept {
448 value = parse<value_t>(str);
454#if defined(__xtd__cpp_lib_char8_t)
461 template<
class value_t>
462 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value)
noexcept {
464 value = parse<value_t>(str);
477 template<
class value_t>
478 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value)
noexcept {
480 value = parse<value_t>(str);
493 template<
class value_t>
494 inline bool try_parse(
const std::basic_string<char>& str, value_t& value,
const std::locale& locale)
noexcept {
496 value = parse<value_t>(str, locale);
508 template<
class value_t>
509 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value,
const std::locale& locale)
noexcept {
511 value = parse<value_t>(str, locale);
523 template<
class value_t>
524 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value,
const std::locale& locale)
noexcept {
526 value = parse<value_t>(str, locale);
532#if defined(__xtd__cpp_lib_char8_t)
539 template<
class value_t>
540 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value,
const std::locale& locale)
noexcept {
542 value = parse<value_t>(str, locale);
555 template<
class value_t>
556 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value,
const std::locale& locale)
noexcept {
558 value = parse<value_t>(str, locale);
571 template<
class value_t,
class char_t>
572 inline bool try_parse(
const char_t* str, value_t& value)
noexcept {
573 return try_parse(std::basic_string<char_t>(str), value);
582 template<
class value_t,
class char_t>
583 inline bool try_parse(
const char_t* str, value_t& value,
const std::locale& locale)
noexcept {
584 return try_parse(std::basic_string<char_t>(str), value, locale);
593 template<
class value_t>
596 value = parse<value_t>(str, style);
608 template<
class value_t>
611 value = parse<value_t>(str, style);
623 template<
class value_t>
626 value = parse<value_t>(str, style);
632#if defined(__xtd__cpp_lib_char8_t)
639 template<
class value_t>
642 value = parse<value_t>(str, style);
655 template<
class value_t>
658 value = parse<value_t>(str, style);
671 template<
class value_t>
672 inline bool try_parse(
const std::basic_string<char>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
674 value = parse<value_t>(str, style, locale);
686 template<
class value_t>
687 inline bool try_parse(
const std::basic_string<xtd::char16>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
689 value = parse<value_t>(str, style, locale);
701 template<
class value_t>
702 inline bool try_parse(
const std::basic_string<xtd::char32>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
704 value = parse<value_t>(str, style, locale);
710#if defined(__xtd__cpp_lib_char8_t)
717 template<
class value_t>
718 inline bool try_parse(
const std::basic_string<xtd::char8>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
720 value = parse<value_t>(str, style, locale);
733 template<
class value_t>
734 inline bool try_parse(
const std::basic_string<xtd::wchar>& str, value_t& value,
number_styles style,
const std::locale& locale)
noexcept {
736 value = parse<value_t>(str, style, locale);
749 template<
class value_t,
class char_t>
751 return try_parse(std::basic_string<char_t>(str), value, style);
760 template<
class value_t,
class char_t>
762 return try_parse(std::basic_string<char_t>(str), value, style, locale);
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.
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
double parse< double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:208
number_styles
Determines the styles permitted in numeric string arguments that are passed to the xtd::parse and xtd...
Definition number_styles.hpp:16
char parse< char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:100
bool parse< bool >(const std::string &str)
Convert a string into a type.
Definition parse.hpp:370
xtd::sbyte parse< xtd::sbyte >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:91
unsigned long parse< unsigned long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:163
long long parse< long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:172
long double parse< long double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:226
int parse< int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:136
long parse< long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:154
unsigned char parse< unsigned char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:109
std::string parse< std::string >(const std::string &str)
Convert a string into a type.
Definition parse.hpp:64
float parse< float >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:190
short parse< short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:118
unsigned int parse< unsigned int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:145
unsigned short parse< unsigned short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:127
unsigned long long parse< unsigned long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition parse.hpp:181
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.hpp:416
@ 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.hpp:10
Contains xtd::number_styles enum class.
Contains xtd fundamental types.