* Parses the and components of a printf format sub-string * according to http://www.cplusplus.com/reference/cstdio/printf/ and returns * a corresponding FormatType. * * \param length * Length component of the printf format string * \param specifier * Specifier component of the printf format string * @return * The FormatType corresponding to the length a
| 710 | * MAX_FORMAT_TYPE is returned in case of error. |
| 711 | */ |
| 712 | static NanoLogInternal::Log::FormatType |
| 713 | getFormatType(std::string length, char specifier) |
| 714 | { |
| 715 | using namespace NanoLogInternal::Log; |
| 716 | |
| 717 | // Signed Integers |
| 718 | if (specifier == 'd' || specifier == 'i') { |
| 719 | if (length.empty()) |
| 720 | return int_t; |
| 721 | |
| 722 | if (length.size() == 2) { |
| 723 | if (length[0] == 'h') return signed_char_t; |
| 724 | if (length[0] == 'l') return long_long_int_t; |
| 725 | } |
| 726 | |
| 727 | switch(length[0]) { |
| 728 | case 'h': return short_int_t; |
| 729 | case 'l': return long_int_t; |
| 730 | case 'j': return intmax_t_t; |
| 731 | case 'z': return size_t_t; |
| 732 | case 't': return ptrdiff_t_t; |
| 733 | default : break; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | // Unsigned integers |
| 738 | if (specifier == 'u' || specifier == 'o' |
| 739 | || specifier == 'x' || specifier == 'X') |
| 740 | { |
| 741 | if (length.empty()) |
| 742 | return unsigned_int_t; |
| 743 | |
| 744 | if (length.size() == 2) { |
| 745 | if (length[0] == 'h') return unsigned_char_t; |
| 746 | if (length[0] == 'l') return unsigned_long_long_int_t; |
| 747 | } |
| 748 | |
| 749 | switch(length[0]) { |
| 750 | case 'h': return unsigned_short_int_t; |
| 751 | case 'l': return unsigned_long_int_t; |
| 752 | case 'j': return uintmax_t_t; |
| 753 | case 'z': return size_t_t; |
| 754 | case 't': return ptrdiff_t_t; |
| 755 | default : break; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | // Strings |
| 760 | if (specifier == 's') { |
| 761 | if (length.empty()) return const_char_ptr_t; |
| 762 | if (length[0] == 'l') return const_wchar_t_ptr_t; |
| 763 | } |
| 764 | |
| 765 | // Pointer |
| 766 | if (specifier == 'p') { |
| 767 | if (length.empty()) return const_void_ptr_t; |
| 768 | } |
| 769 |