5 #define __XTD_CORE_INTERNAL__ 7 #include "internal/__parse.h" 8 #undef __XTD_CORE_INTERNAL__ 22 template<
typename value_t>
23 inline value_t
parse(
const std::string& str) {
24 if (std::is_enum<value_t>::value)
return __parse_enum<value_t>(str);
25 __throw_parse_format_exception(
"Parse specialisation not found");
35 template<
typename value_t>
36 inline value_t
parse(
const std::string& str,
const std::locale& locale) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
44 template<
typename value_t>
45 inline value_t
parse(
const std::string& str,
const std::string& fmt) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
54 inline std::string parse<std::string>(
const std::string& str) {
return str;}
62 template<
typename value_t>
63 inline value_t
parse(
const std::string& str,
number_styles) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
71 template<
typename value_t>
72 inline value_t
parse(
const std::string& str,
number_styles,
const std::locale& locale) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
81 inline xtd::sbyte parse<xtd::sbyte>(
const std::string& str,
number_styles styles) {
return __parse_number<xtd::sbyte>(str, styles);}
180 inline float parse<float>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<float>(str, styles, std::locale());}
189 inline float parse<float>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<float>(str, styles, locale);}
198 inline double parse<double>(
const std::string& str,
number_styles styles) {
return __parse_floating_point_number<double>(str, styles, std::locale());}
207 inline double parse<double>(
const std::string& str,
number_styles styles,
const std::locale& locale) {
return __parse_floating_point_number<double>(str, styles, locale);}
225 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);}
361 std::string lower_str = str;
362 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))
363 lower_str.erase(0, 1);
364 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))
365 lower_str.erase(lower_str.size() - 1, 1);
366 for (
auto&
c : lower_str)
367 c =
static_cast<char>(std::tolower(
c));
368 if (lower_str !=
"true" && lower_str !=
"1" && lower_str !=
"false" && lower_str !=
"0") __throw_parse_format_exception(
"Invalid string format");
369 return lower_str ==
"true" || lower_str ==
"1";
378 template<
typename value_t>
379 inline value_t
parse(
const std::wstring& str) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
387 template<
typename value_t>
388 inline value_t
parse(
const std::u16string& str) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
396 template<
typename value_t>
397 inline value_t
parse(
const std::u32string& str) {__throw_parse_format_exception(
"Parse specialisation not found");
return {};}
405 template<
typename value_t,
typename char_t>
406 inline bool try_parse(
const std::basic_string<char_t>& str, value_t& value) noexcept {
408 value = parse<value_t>(str);
421 template<
typename value_t,
typename char_t>
422 inline bool try_parse(
const std::basic_string<char_t>& str, value_t& value,
const std::locale& locale) noexcept {
424 value = parse<value_t>(str, locale);
437 template<
typename value_t,
typename char_t>
438 inline bool try_parse(
const char_t* str, value_t& value) noexcept {
439 return try_parse(std::basic_string<char_t>(str), value);
448 template<
typename value_t,
typename char_t>
449 inline bool try_parse(
const char_t* str, value_t& value,
const std::locale& locale) noexcept {
450 return try_parse(std::basic_string<char_t>(str), value, locale);
459 template<
typename value_t,
typename char_t>
462 value = parse<value_t>(str, style);
475 template<
typename value_t,
typename char_t>
476 inline bool try_parse(
const std::basic_string<char_t>& str, value_t& value,
number_styles style,
const std::locale& locale) noexcept {
478 value = parse<value_t>(str, style, locale);
491 template<
typename value_t,
typename char_t>
493 return try_parse(std::basic_string<char_t>(str), value, style);
502 template<
typename value_t,
typename char_t>
504 return try_parse(std::basic_string<char_t>(str), value, style, locale);
unsigned char parse< unsigned char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:99
int parse< int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:126
Contains xtd fundamental types.
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition: types.h:173
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:23
char parse< char >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:90
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
long long parse< long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:162
Indicates that the allow_leading_white, allow_trailing_white, and allow_leading_sign styles are used...
long double parse< long double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:216
double parse< double >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:198
long parse< long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:144
unsigned long long parse< unsigned long long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:171
Indicates that the allow_leading_white, allow_trailing_white, allow_leading_sign, allow_decimal_point...
bool parse< bool >(const std::string &str)
Convert a string into a type.
Definition: parse.h:360
unsigned long parse< unsigned long >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:153
float parse< float >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:180
unsigned int parse< unsigned int >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:135
bool try_parse(const std::basic_string< char_t > &str, value_t &value) noexcept
Convert a string into a type.
Definition: parse.h:406
unsigned short parse< unsigned short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:117
Contains xtd::number_styles enum class.
number_styles
Determines the styles permitted in numeric string arguments that are passed to the xtd::parse and xtd...
Definition: number_styles.h:16
short parse< short >(const std::string &str, number_styles styles)
Convert a string into a type.
Definition: parse.h:108