xtd 0.2.0
__enum_formatter.hpp
Go to the documentation of this file.
1
3#pragma once
5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
7#endif
9
11#include "../helpers/throw_helper.hpp"
12
14template<class enum_t>
15std::string __enum_to_string__(enum_t value) noexcept;
16
17template<class char_t, class value_t>
18inline std::basic_string<char_t> __enum_formatter(const std::basic_string<char_t>& format, value_t value, const std::locale& loc) {
19 auto fmt = format;
20 if (fmt.empty()) fmt = {'G'};
21
22 switch (fmt[0]) {
23 case 'b':
24 case 'B':
25 case 'd':
26 case 'D':
27 case 'o':
28 case 'O':
29 case 'x':
30 case 'X': return __numeric_formatter(fmt, static_cast<long long int>(value), loc);
31 case 'g':
32 case 'G': return __enum_to_string__(value);
34 }
35}
36
37template<class value_t>
38static std::string __to_string_enum(const value_t& value, const std::string& fmt, const std::locale& loc, std::true_type) {return __enum_formatter(fmt, value, loc);}
39
40template<class value_t>
41static std::string __to_string_enum(const value_t& value, const std::string& fmt, const std::locale& loc, std::false_type) {
43}
44
45template<class value_t>
46static std::wstring __to_string_enum(const value_t& value, const std::wstring& fmt, const std::locale& loc, std::true_type) {return __enum_formatter(fmt, value, loc);}
47
48template<class value_t>
49static std::wstring __to_string_enum(const value_t& value, const std::wstring& fmt, const std::locale& loc, std::false_type) {
51}
Contains __numeric_formatter method.
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:20
@ format_not_iformatable
The object is not iformatable.
@ format
The format is not valid.