Checks if an argument is a valid printf width specifier and sets left alignment if it is negative.
| 238 | // Checks if an argument is a valid printf width specifier and sets |
| 239 | // left alignment if it is negative. |
| 240 | class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> { |
| 241 | private: |
| 242 | fmt::FormatSpec &spec_; |
| 243 | |
| 244 | public: |
| 245 | explicit WidthHandler(fmt::FormatSpec &spec) : spec_(spec) {} |
| 246 | |
| 247 | unsigned visit_unhandled_arg() { |
| 248 | FMT_THROW(fmt::FormatError("width is not integer")); |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | template <typename T> |
| 253 | unsigned visit_any_int(T value) { |
| 254 | typedef typename fmt::internal::IntTraits<T>::MainType UnsignedType; |
| 255 | UnsignedType width = value; |
| 256 | if (fmt::internal::is_negative(value)) { |
| 257 | spec_.align_ = fmt::ALIGN_LEFT; |
| 258 | width = 0 - width; |
| 259 | } |
| 260 | if (width > INT_MAX) |
| 261 | FMT_THROW(fmt::FormatError("number is too big")); |
| 262 | return static_cast<unsigned>(width); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | class PrecisionHandler : |
| 267 | public fmt::internal::ArgVisitor<PrecisionHandler, int> { |