MCPcopy Create free account
hub / github.com/fmtlib/fmt / printf_width_handler

Class printf_width_handler

include/fmt/printf.h:196–220  ·  view source on GitHub ↗

Checks if an argument is a valid printf width specifier and sets left alignment if it is negative.

Source from the content-addressed store, hash-verified

194// Checks if an argument is a valid printf width specifier and sets
195// left alignment if it is negative.
196class 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.

Callers 1

parse_headerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected