TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fmt::BasicFormatter< CharType > Class Template Reference

#include <format.h>

Public Types

typedef CharType Char
 

Public Member Functions

 BasicFormatter (const ArgList &args, BasicWriter< Char > &w)
 
BasicWriter< Char > & writer ()
 
void format (BasicCStringRef< Char > format_str)
 
const Charformat (const Char *&format_str, const internal::Arg &arg)
 

Private Member Functions

 FMT_DISALLOW_COPY_AND_ASSIGN (BasicFormatter)
 
internal::Arg get_arg (BasicStringRef< Char > arg_name, const char *&error)
 
internal::Arg parse_arg_index (const Char *&s)
 
internal::Arg parse_arg_name (const Char *&s)
 
- Private Member Functions inherited from fmt::internal::FormatterBase
const ArgListargs () const
 
 FormatterBase (const ArgList &args)
 
Arg next_arg (const char *&error)
 
Arg get_arg (unsigned arg_index, const char *&error)
 
bool check_no_auto_index (const char *&error)
 
template<typename Char >
void write (BasicWriter< Char > &w, const Char *start, const Char *end)
 

Private Attributes

BasicWriter< Char > & writer_
 
internal::ArgMap< Charmap_
 

Detailed Description

template<typename CharType>
class fmt::BasicFormatter< CharType >

This template formats data and writes the output to a writer.

Member Typedef Documentation

template<typename CharType>
typedef CharType fmt::BasicFormatter< CharType >::Char

The character type for the output.

Constructor & Destructor Documentation

template<typename CharType>
fmt::BasicFormatter< CharType >::BasicFormatter ( const ArgList args,
BasicWriter< Char > &  w 
)
inline

Constructs a BasicFormatter object. References to the arguments and the writer are stored in the formatter object so make sure they have appropriate lifetimes.

1921  : internal::FormatterBase(args), writer_(w) {}
BasicWriter< Char > & writer_
Definition: format.h:1895
const ArgList & args() const
Definition: format.h:1829

Member Function Documentation

template<typename CharType>
fmt::BasicFormatter< CharType >::FMT_DISALLOW_COPY_AND_ASSIGN ( BasicFormatter< CharType >  )
private
template<typename Char >
void fmt::BasicFormatter< Char >::format ( BasicCStringRef< Char format_str)

Formats stored arguments and writes the output to the writer.

3689  {
3690  const Char *s = format_str.c_str();
3691  const Char *start = s;
3692  while (*s) {
3693  Char c = *s++;
3694  if (c != '{' && c != '}') continue;
3695  if (*s == c) {
3696  write(writer_, start, s);
3697  start = ++s;
3698  continue;
3699  }
3700  if (c == '}')
3701  FMT_THROW(FormatError("unmatched '}' in format string"));
3702  write(writer_, start, s - 1);
3703  internal::Arg arg = internal::is_name_start(*s) ?
3705  start = s = format(s, arg);
3706  }
3707  write(writer_, start, s);
3708 }
void format(BasicCStringRef< Char > format_str)
Definition: format.h:3689
internal::Arg parse_arg_name(const Char *&s)
Definition: format.h:3504
char Char
Definition: bzlib_private.h:41
BasicWriter< Char > & writer_
Definition: format.h:1895
internal::Arg parse_arg_index(const Char *&s)
Definition: format.h:3492
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
void write(BasicWriter< Char > &w, const Char *start, const Char *end)
Definition: format.h:1860
#define FMT_THROW(x)
Definition: format.h:166
bool is_name_start(Char c)
Definition: format.h:3432

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Char >
const Char * fmt::BasicFormatter< Char >::format ( const Char *&  format_str,
const internal::Arg arg 
)
3520  {
3521  using internal::Arg;
3522  const Char *s = format_str;
3523  FormatSpec spec;
3524  if (*s == ':') {
3525  if (arg.type == Arg::CUSTOM) {
3526  arg.custom.format(this, arg.custom.value, &s);
3527  return s;
3528  }
3529  ++s;
3530  // Parse fill and alignment.
3531  if (Char c = *s) {
3532  const Char *p = s + 1;
3533  spec.align_ = ALIGN_DEFAULT;
3534  do {
3535  switch (*p) {
3536  case '<':
3537  spec.align_ = ALIGN_LEFT;
3538  break;
3539  case '>':
3540  spec.align_ = ALIGN_RIGHT;
3541  break;
3542  case '=':
3543  spec.align_ = ALIGN_NUMERIC;
3544  break;
3545  case '^':
3546  spec.align_ = ALIGN_CENTER;
3547  break;
3548  }
3549  if (spec.align_ != ALIGN_DEFAULT) {
3550  if (p != s) {
3551  if (c == '}') break;
3552  if (c == '{')
3553  FMT_THROW(FormatError("invalid fill character '{'"));
3554  s += 2;
3555  spec.fill_ = c;
3556  } else ++s;
3557  if (spec.align_ == ALIGN_NUMERIC)
3559  break;
3560  }
3561  } while (--p >= s);
3562  }
3563 
3564  // Parse sign.
3565  switch (*s) {
3566  case '+':
3567  check_sign(s, arg);
3568  spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
3569  break;
3570  case '-':
3571  check_sign(s, arg);
3572  spec.flags_ |= MINUS_FLAG;
3573  break;
3574  case ' ':
3575  check_sign(s, arg);
3576  spec.flags_ |= SIGN_FLAG;
3577  break;
3578  }
3579 
3580  if (*s == '#') {
3582  spec.flags_ |= HASH_FLAG;
3583  ++s;
3584  }
3585 
3586  // Parse zero flag.
3587  if (*s == '0') {
3589  spec.align_ = ALIGN_NUMERIC;
3590  spec.fill_ = '0';
3591  ++s;
3592  }
3593 
3594  // Parse width.
3595  if ('0' <= *s && *s <= '9') {
3596  spec.width_ = internal::parse_nonnegative_int(s);
3597  } else if (*s == '{') {
3598  ++s;
3599  Arg width_arg = internal::is_name_start(*s) ?
3601  if (*s++ != '}')
3602  FMT_THROW(FormatError("invalid format string"));
3603  ULongLong value = 0;
3604  switch (width_arg.type) {
3605  case Arg::INT:
3606  if (width_arg.int_value < 0)
3607  FMT_THROW(FormatError("negative width"));
3608  value = width_arg.int_value;
3609  break;
3610  case Arg::UINT:
3611  value = width_arg.uint_value;
3612  break;
3613  case Arg::LONG_LONG:
3614  if (width_arg.long_long_value < 0)
3615  FMT_THROW(FormatError("negative width"));
3616  value = width_arg.long_long_value;
3617  break;
3618  case Arg::ULONG_LONG:
3619  value = width_arg.ulong_long_value;
3620  break;
3621  default:
3622  FMT_THROW(FormatError("width is not integer"));
3623  }
3624  if (value > (std::numeric_limits<int>::max)())
3625  FMT_THROW(FormatError("number is too big"));
3626  spec.width_ = static_cast<int>(value);
3627  }
3628 
3629  // Parse precision.
3630  if (*s == '.') {
3631  ++s;
3632  spec.precision_ = 0;
3633  if ('0' <= *s && *s <= '9') {
3634  spec.precision_ = internal::parse_nonnegative_int(s);
3635  } else if (*s == '{') {
3636  ++s;
3637  Arg precision_arg = internal::is_name_start(*s) ?
3639  if (*s++ != '}')
3640  FMT_THROW(FormatError("invalid format string"));
3641  ULongLong value = 0;
3642  switch (precision_arg.type) {
3643  case Arg::INT:
3644  if (precision_arg.int_value < 0)
3645  FMT_THROW(FormatError("negative precision"));
3646  value = precision_arg.int_value;
3647  break;
3648  case Arg::UINT:
3649  value = precision_arg.uint_value;
3650  break;
3651  case Arg::LONG_LONG:
3652  if (precision_arg.long_long_value < 0)
3653  FMT_THROW(FormatError("negative precision"));
3654  value = precision_arg.long_long_value;
3655  break;
3656  case Arg::ULONG_LONG:
3657  value = precision_arg.ulong_long_value;
3658  break;
3659  default:
3660  FMT_THROW(FormatError("precision is not integer"));
3661  }
3662  if (value > (std::numeric_limits<int>::max)())
3663  FMT_THROW(FormatError("number is too big"));
3664  spec.precision_ = static_cast<int>(value);
3665  } else {
3666  FMT_THROW(FormatError("missing precision specifier"));
3667  }
3668  if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) {
3669  FMT_THROW(FormatError(
3670  fmt::format("precision not allowed in {} format specifier",
3671  arg.type == Arg::POINTER ? "pointer" : "integer")));
3672  }
3673  }
3674 
3675  // Parse type.
3676  if (*s != '}' && *s)
3677  spec.type_ = static_cast<char>(*s++);
3678  }
3679 
3680  if (*s++ != '}')
3681  FMT_THROW(FormatError("missing '}' in format string"));
3682 
3683  // Format argument.
3684  internal::BasicArgFormatter<Char>(*this, spec, s - 1).visit(arg);
3685  return s;
3686 }
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
Definition: format.h:1460
Definition: format.h:983
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
Definition: format.h:362
Definition: format.h:1460
unsigned parse_nonnegative_int(const Char *&s)
Definition: format.h:3439
T max(const T &x, const T &y)
Definition: g3dmath.h:320
internal::Arg parse_arg_name(const Char *&s)
Definition: format.h:3504
Definition: format.h:1460
char Char
Definition: bzlib_private.h:41
unsigned uint_value
Definition: format.h:958
Definition: format.h:1465
Definition: format.h:1465
int int_value
Definition: format.h:957
void check_sign(const Char *&s, const Arg &arg)
Definition: format.h:3467
internal::Arg parse_arg_index(const Char *&s)
Definition: format.h:3492
Definition: format.h:1460
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
void require_numeric_argument(const Arg &arg, char spec)
Definition: format.h:3458
Definition: format.h:1465
ULongLong ulong_long_value
Definition: format.h:960
const FieldDescriptor value
Definition: descriptor.h:1522
Type type
Definition: format.h:984
LongLong long_long_value
Definition: format.h:959
Definition: format.h:1460
#define FMT_THROW(x)
Definition: format.h:166
Definition: format.h:1465
bool is_name_start(Char c)
Definition: format.h:3432

+ Here is the call graph for this function:

template<typename Char >
internal::Arg fmt::BasicFormatter< Char >::get_arg ( BasicStringRef< Char arg_name,
const char *&  error 
)
inlineprivate
3480  {
3481  if (check_no_auto_index(error)) {
3482  map_.init(args());
3483  const internal::Arg *arg = map_.find(arg_name);
3484  if (arg)
3485  return *arg;
3486  error = "argument not found";
3487  }
3488  return internal::Arg();
3489 }
internal::ArgMap< Char > map_
Definition: format.h:1896
bool check_no_auto_index(const char *&error)
Definition: format.h:1850
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
const ArgList & args() const
Definition: format.h:1829

+ Here is the call graph for this function:

template<typename Char >
internal::Arg fmt::BasicFormatter< Char >::parse_arg_index ( const Char *&  s)
inlineprivate
3492  {
3493  const char *error = 0;
3494  internal::Arg arg = *s < '0' || *s > '9' ?
3495  next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
3496  if (error) {
3497  FMT_THROW(FormatError(
3498  *s != '}' && *s != ':' ? "invalid format string" : error));
3499  }
3500  return arg;
3501 }
Arg next_arg(const char *&error)
Definition: format.h:1837
unsigned parse_nonnegative_int(const Char *&s)
Definition: format.h:3439
Definition: document.h:390
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
#define FMT_THROW(x)
Definition: format.h:166
internal::Arg get_arg(BasicStringRef< Char > arg_name, const char *&error)
Definition: format.h:3479

+ Here is the call graph for this function:

template<typename Char >
internal::Arg fmt::BasicFormatter< Char >::parse_arg_name ( const Char *&  s)
inlineprivate
3504  {
3505  assert(internal::is_name_start(*s));
3506  const Char *start = s;
3507  Char c;
3508  do {
3509  c = *++s;
3510  } while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
3511  const char *error = 0;
3512  internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
3513  if (error)
3514  FMT_THROW(FormatError(error));
3515  return arg;
3516 }
char Char
Definition: bzlib_private.h:41
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
#define FMT_THROW(x)
Definition: format.h:166
internal::Arg get_arg(BasicStringRef< Char > arg_name, const char *&error)
Definition: format.h:3479
bool is_name_start(Char c)
Definition: format.h:3432

+ Here is the call graph for this function:

template<typename CharType>
BasicWriter<Char>& fmt::BasicFormatter< CharType >::writer ( )
inline

Returns a reference to the writer associated with this formatter.

1924 { return writer_; }
BasicWriter< Char > & writer_
Definition: format.h:1895

Member Data Documentation

template<typename CharType>
internal::ArgMap<Char> fmt::BasicFormatter< CharType >::map_
private
template<typename CharType>
BasicWriter<Char>& fmt::BasicFormatter< CharType >::writer_
private

The documentation for this class was generated from the following file: