5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
22template<
typename char_t,
typename value_t>
23inline std::basic_string<char_t> __floating_point_formatter(
const std::basic_string<char_t>& format, value_t value,
const std::locale& loc) {
25 if (fmt.empty()) fmt = {
'G'};
27 std::vector<char_t> possible_formats {
'b',
'B',
'c',
'C',
'e',
'E',
'f',
'F',
'g',
'G',
'n',
'N',
'p',
'P',
'x',
'X'};
28 if (fmt.size() > 3 || std::find(possible_formats.begin(), possible_formats.end(), fmt[0]) == possible_formats.end() || (fmt.size() >= 2 && !std::isdigit(fmt[1])) || (fmt.size() == 3 && !std::isdigit(fmt[2])))
29 __format_exception(
"Custom format not yet implemented");
33 if (fmt.size() > 1) precision = std::stoi(fmt.substr(1));
35 __format_exception(
"Invalid format expression");
37 if ((fmt[0] ==
'f' || fmt[0] ==
'F' || fmt[0] ==
'n' || fmt[0] ==
'N' || fmt[0] ==
'p' || fmt[0] ==
'P' || fmt[0] ==
'r' || fmt[0] ==
'R') && fmt.size() == 1) precision = 2;
38 if ((fmt[0] ==
'e' || fmt[0] ==
'E') && fmt.size() == 1) precision = 6;
39 if ((fmt[0] ==
'g' || fmt[0] ==
'G') && fmt.size() == 1) precision =
sizeof(value) <= 4 ? 7 : 15;
41 std::basic_string<char_t> fmt_str({
'%',
'.',
'*',
'L'});
44 case 'B': {
double value_double =
static_cast<double>(value); int64_t value_int64 = 0; memcpy(&value_int64, &value_double,
sizeof(value_double));
return __binary_formatter<char_t>(value_int64, precision);}
46 case 'C':
return __currency_formatter<char_t>(
static_cast<long double>(value), loc);
52 case 'G':
return __sprintf((fmt_str + fmt[0]).c_str(), precision,
static_cast<long double>(value));
54 case 'N':
return __natural_formatter<char_t>(
static_cast<long double>(value), precision, loc);
55 case 'p':
return __sprintf((fmt_str + char_t(
'f')).c_str(), precision,
static_cast<long double>(value * 100)) + std::basic_string<char_t>({char_t(
' '), char_t(
'%')});
56 case 'P':
return __sprintf((fmt_str + char_t(
'F')).c_str(), precision,
static_cast<long double>(value * 100)) + std::basic_string<char_t>({char_t(
' '), char_t(
'%')});
58 case 'X':
return __hexfloat_formatter<char_t>(
static_cast<long double>(value), precision, loc);
59 default: __format_exception(
"Invalid format expression");
return {};
Contains __format method.