| 321 | FormatArg(unsigned char v) : mType(Type::UInt) { mData.u = v; } |
| 322 | |
| 323 | fl::string format(const FormatSpec& spec) const { |
| 324 | switch (mType) { |
| 325 | case Type::Int: return format_integer(mData.i, spec); |
| 326 | case Type::UInt: return format_integer(mData.u, spec); |
| 327 | case Type::Long: return format_integer(mData.l, spec); |
| 328 | case Type::ULong: return format_integer(mData.ul, spec); |
| 329 | case Type::LongLong: return format_integer(mData.ll, spec); |
| 330 | case Type::ULongLong: return format_integer(mData.ull, spec); |
| 331 | case Type::Double: return format_float(mData.d, spec); |
| 332 | case Type::Char: { |
| 333 | if (spec.type == 'd' || spec.type == 'x' || spec.type == 'X' || |
| 334 | spec.type == 'b' || spec.type == 'o') { |
| 335 | return format_integer(static_cast<int>(mData.c), spec); |
| 336 | } |
| 337 | char buf[2] = {mData.c, '\0'}; |
| 338 | return fl::string(buf); |
| 339 | } |
| 340 | case Type::CString: return format_string(mData.s, spec); |
| 341 | case Type::String: return format_string(mData.str->c_str(), spec); |
| 342 | case Type::Pointer: return format_pointer(mData.p, spec); |
| 343 | case Type::None: |
| 344 | default: return fl::string("<invalid>"); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | bool valid() const { return mType != Type::None; } |
| 349 | |