5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
16template<
class char_t,
class value_t>
17inline std::basic_string<char_t> __numeric_formatter(
const std::basic_string<char_t>& fmt, value_t value,
const std::locale& loc) {
21 std::vector<char_t> possible_formats {
'b',
'B',
'c',
'C',
'd',
'D',
'e',
'E',
'f',
'F',
'g',
'G',
'n',
'N',
'o',
'O',
'p',
'P',
'x',
'X'};
22 if (
format.
size() > 3 || std::find(possible_formats.begin(), possible_formats.end(), format[0]) == possible_formats.end() || (
format.
size() >= 2 && !std::isdigit(format[1])) || (
format.
size() == 3 && !std::isdigit(format[2])))
26 if (format[0] ==
'b' || format[0] ==
'B' || format[0] ==
'd' || format[0] ==
'D' || format[0] ==
'o' || format[0] ==
'O' || format[0] ==
'x' || format[0] ==
'X') {
28 for (
auto c :
format.substr(1))
29 if (!std::isdigit(
c) &&
c !=
' ' &&
c !=
'+' &&
c !=
'-')
xtd::helpers::throw_helper::throws(
xtd::helpers::
exception_case::
format,
"Invalid format expression");
34 if ((format[0] ==
'd' || format[0] ==
'D') && precision > 0 && value < 0) precision += 1;
35 if ((format[0] ==
'd' || format[0] ==
'D') && precision < 0 && value < 0) precision -= 1;
38 std::basic_string<char_t> fmt_str({
'%',
'0',
'*',
'l',
'l'});
41 case 'B':
return __binary_formatter<char_t>(value, precision);
44 case 'G':
return __sprintf((fmt_str + char_t(std::is_unsigned<value_t>::value ?
'u' :
'd')).c_str(), precision, static_cast<long long>(value));
46 case 'O':
return __sprintf((fmt_str + char_t(
'o')).c_str(), precision,
static_cast<long long>(value));
48 case 'X':
return __sprintf((fmt_str + format[0]).c_str(), precision,
static_cast<long long>(value));
49 default:
return __floating_point_formatter(format,
static_cast<long double>(value), loc);
Contains __format method.
size_type size() const noexcept
Returns the number of char_t elements in the string, i.e. std::distance(begin(), end()).
Definition basic_string.hpp:926
bool empty() const noexcept
Checks if the string has no characters, i.e. whether begin() == end().
Definition basic_string.hpp:896
basic_string substr() const
Returns a substring [pos, pos + count). If the requested substring extends past the end of the string...
Definition basic_string.hpp:1838
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
exception_case
Represents the exception case used by the xtd::helpers::exception helper class.
Definition exception_case.hpp:25
@ format
The format is not valid.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10