Checks if an argument is a valid printf width specifier and sets left alignment if it is negative.
| 194 | // Checks if an argument is a valid printf width specifier and sets |
| 195 | // left alignment if it is negative. |
| 196 | class printf_width_handler { |
| 197 | private: |
| 198 | format_specs& specs_; |
| 199 | |
| 200 | public: |
| 201 | inline explicit printf_width_handler(format_specs& specs) : specs_(specs) {} |
| 202 | |
| 203 | template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> |
| 204 | auto operator()(T value) -> unsigned { |
| 205 | auto width = static_cast<uint32_or_64_or_128_t<T>>(value); |
| 206 | if (detail::is_negative(value)) { |
| 207 | specs_.set_align(align::left); |
| 208 | width = 0 - width; |
| 209 | } |
| 210 | unsigned int_max = to_unsigned(max_value<int>()); |
| 211 | if (width > int_max) report_error("number is too big"); |
| 212 | return static_cast<unsigned>(width); |
| 213 | } |
| 214 | |
| 215 | template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> |
| 216 | auto operator()(T) -> unsigned { |
| 217 | report_error("width is not integer"); |
| 218 | return 0; |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | // Workaround for a bug with the XL compiler when initializing |
| 223 | // printf_arg_formatter's base class. |