add support for better error message back
This commit is contained in:
parent
f2e75f74cc
commit
0616edd08e
472
format.cc
472
format.cc
@ -411,246 +411,252 @@ void fmt::BasicFormatter<Char>::CheckSign(const Char *&s, const Arg &arg) {
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
void fmt::BasicFormatter<Char>::DoFormat() {
|
void fmt::BasicFormatter<Char>::DoFormat() {
|
||||||
const Char *start = format_;
|
const Char *start = format_;
|
||||||
|
const Char *original = format_; // capture the format string before it is reset
|
||||||
format_ = 0;
|
format_ = 0;
|
||||||
next_arg_index_ = 0;
|
next_arg_index_ = 0;
|
||||||
const Char *s = start;
|
const Char *s = start;
|
||||||
BasicWriter<Char> &writer = *writer_;
|
BasicWriter<Char> &writer = *writer_;
|
||||||
while (*s) {
|
try {
|
||||||
Char c = *s++;
|
while (*s) {
|
||||||
if (c != '{' && c != '}') continue;
|
Char c = *s++;
|
||||||
if (*s == c) {
|
if (c != '{' && c != '}') continue;
|
||||||
writer.buffer_.append(start, s);
|
if (*s == c) {
|
||||||
start = ++s;
|
writer.buffer_.append(start, s);
|
||||||
continue;
|
start = ++s;
|
||||||
}
|
continue;
|
||||||
if (c == '}')
|
|
||||||
throw FormatError("unmatched '}' in format");
|
|
||||||
num_open_braces_= 1;
|
|
||||||
writer.buffer_.append(start, s - 1);
|
|
||||||
|
|
||||||
const Arg &arg = ParseArgIndex(s);
|
|
||||||
|
|
||||||
FormatSpec spec;
|
|
||||||
int precision = -1;
|
|
||||||
if (*s == ':') {
|
|
||||||
++s;
|
|
||||||
|
|
||||||
// Parse fill and alignment.
|
|
||||||
if (Char c = *s) {
|
|
||||||
const Char *p = s + 1;
|
|
||||||
spec.align_ = ALIGN_DEFAULT;
|
|
||||||
do {
|
|
||||||
switch (*p) {
|
|
||||||
case '<':
|
|
||||||
spec.align_ = ALIGN_LEFT;
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
spec.align_ = ALIGN_RIGHT;
|
|
||||||
break;
|
|
||||||
case '=':
|
|
||||||
spec.align_ = ALIGN_NUMERIC;
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
spec.align_ = ALIGN_CENTER;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (spec.align_ != ALIGN_DEFAULT) {
|
|
||||||
if (p != s) {
|
|
||||||
if (c == '}') break;
|
|
||||||
if (c == '{')
|
|
||||||
ReportError(s, "invalid fill character '{'");
|
|
||||||
s += 2;
|
|
||||||
spec.fill_ = c;
|
|
||||||
} else ++s;
|
|
||||||
if (spec.align_ == ALIGN_NUMERIC && arg.type > LAST_NUMERIC_TYPE)
|
|
||||||
ReportError(s, "format specifier '=' requires numeric argument");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (--p >= s);
|
|
||||||
}
|
}
|
||||||
|
if (c == '}')
|
||||||
|
throw FormatError("unmatched '}' in format");
|
||||||
|
num_open_braces_= 1;
|
||||||
|
writer.buffer_.append(start, s - 1);
|
||||||
|
|
||||||
// Parse sign.
|
const Arg &arg = ParseArgIndex(s);
|
||||||
switch (*s) {
|
|
||||||
case '+':
|
|
||||||
CheckSign(s, arg);
|
|
||||||
spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
CheckSign(s, arg);
|
|
||||||
break;
|
|
||||||
case ' ':
|
|
||||||
CheckSign(s, arg);
|
|
||||||
spec.flags_ |= SIGN_FLAG;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*s == '#') {
|
FormatSpec spec;
|
||||||
if (arg.type > LAST_NUMERIC_TYPE)
|
int precision = -1;
|
||||||
ReportError(s, "format specifier '#' requires numeric argument");
|
if (*s == ':') {
|
||||||
spec.flags_ |= HASH_FLAG;
|
|
||||||
++s;
|
++s;
|
||||||
}
|
|
||||||
|
|
||||||
// Parse width and zero flag.
|
// Parse fill and alignment.
|
||||||
if ('0' <= *s && *s <= '9') {
|
if (Char c = *s) {
|
||||||
if (*s == '0') {
|
const Char *p = s + 1;
|
||||||
if (arg.type > LAST_NUMERIC_TYPE)
|
spec.align_ = ALIGN_DEFAULT;
|
||||||
ReportError(s, "format specifier '0' requires numeric argument");
|
do {
|
||||||
spec.align_ = ALIGN_NUMERIC;
|
switch (*p) {
|
||||||
spec.fill_ = '0';
|
case '<':
|
||||||
|
spec.align_ = ALIGN_LEFT;
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
spec.align_ = ALIGN_RIGHT;
|
||||||
|
break;
|
||||||
|
case '=':
|
||||||
|
spec.align_ = ALIGN_NUMERIC;
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
spec.align_ = ALIGN_CENTER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (spec.align_ != ALIGN_DEFAULT) {
|
||||||
|
if (p != s) {
|
||||||
|
if (c == '}') break;
|
||||||
|
if (c == '{')
|
||||||
|
ReportError(s, "invalid fill character '{'");
|
||||||
|
s += 2;
|
||||||
|
spec.fill_ = c;
|
||||||
|
} else ++s;
|
||||||
|
if (spec.align_ == ALIGN_NUMERIC && arg.type > LAST_NUMERIC_TYPE)
|
||||||
|
ReportError(s, "format specifier '=' requires numeric argument");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (--p >= s);
|
||||||
}
|
}
|
||||||
// Zero may be parsed again as a part of the width, but it is simpler
|
|
||||||
// and more efficient than checking if the next char is a digit.
|
|
||||||
unsigned value = ParseUInt(s);
|
|
||||||
if (value > INT_MAX)
|
|
||||||
ReportError(s, "number is too big in format");
|
|
||||||
spec.width_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse precision.
|
// Parse sign.
|
||||||
if (*s == '.') {
|
switch (*s) {
|
||||||
++s;
|
case '+':
|
||||||
precision = 0;
|
CheckSign(s, arg);
|
||||||
|
spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
CheckSign(s, arg);
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
CheckSign(s, arg);
|
||||||
|
spec.flags_ |= SIGN_FLAG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*s == '#') {
|
||||||
|
if (arg.type > LAST_NUMERIC_TYPE)
|
||||||
|
ReportError(s, "format specifier '#' requires numeric argument");
|
||||||
|
spec.flags_ |= HASH_FLAG;
|
||||||
|
++s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse width and zero flag.
|
||||||
if ('0' <= *s && *s <= '9') {
|
if ('0' <= *s && *s <= '9') {
|
||||||
|
if (*s == '0') {
|
||||||
|
if (arg.type > LAST_NUMERIC_TYPE)
|
||||||
|
ReportError(s, "format specifier '0' requires numeric argument");
|
||||||
|
spec.align_ = ALIGN_NUMERIC;
|
||||||
|
spec.fill_ = '0';
|
||||||
|
}
|
||||||
|
// Zero may be parsed again as a part of the width, but it is simpler
|
||||||
|
// and more efficient than checking if the next char is a digit.
|
||||||
unsigned value = ParseUInt(s);
|
unsigned value = ParseUInt(s);
|
||||||
if (value > INT_MAX)
|
if (value > INT_MAX)
|
||||||
ReportError(s, "number is too big in format");
|
ReportError(s, "number is too big in format");
|
||||||
precision = value;
|
spec.width_ = value;
|
||||||
} else if (*s == '{') {
|
}
|
||||||
|
|
||||||
|
// Parse precision.
|
||||||
|
if (*s == '.') {
|
||||||
++s;
|
++s;
|
||||||
++num_open_braces_;
|
precision = 0;
|
||||||
const Arg &precision_arg = ParseArgIndex(s);
|
if ('0' <= *s && *s <= '9') {
|
||||||
ULongLong value = 0;
|
unsigned value = ParseUInt(s);
|
||||||
switch (precision_arg.type) {
|
if (value > INT_MAX)
|
||||||
case INT:
|
ReportError(s, "number is too big in format");
|
||||||
if (precision_arg.int_value < 0)
|
precision = value;
|
||||||
ReportError(s, "negative precision in format");
|
} else if (*s == '{') {
|
||||||
value = precision_arg.int_value;
|
++s;
|
||||||
break;
|
++num_open_braces_;
|
||||||
case UINT:
|
const Arg &precision_arg = ParseArgIndex(s);
|
||||||
value = precision_arg.uint_value;
|
ULongLong value = 0;
|
||||||
break;
|
switch (precision_arg.type) {
|
||||||
case LONG:
|
case INT:
|
||||||
if (precision_arg.long_value < 0)
|
if (precision_arg.int_value < 0)
|
||||||
ReportError(s, "negative precision in format");
|
ReportError(s, "negative precision in format");
|
||||||
value = precision_arg.long_value;
|
value = precision_arg.int_value;
|
||||||
break;
|
break;
|
||||||
case ULONG:
|
case UINT:
|
||||||
value = precision_arg.ulong_value;
|
value = precision_arg.uint_value;
|
||||||
break;
|
break;
|
||||||
case LONG_LONG:
|
case LONG:
|
||||||
if (precision_arg.long_long_value < 0)
|
if (precision_arg.long_value < 0)
|
||||||
ReportError(s, "negative precision in format");
|
ReportError(s, "negative precision in format");
|
||||||
value = precision_arg.long_long_value;
|
value = precision_arg.long_value;
|
||||||
break;
|
break;
|
||||||
case ULONG_LONG:
|
case ULONG:
|
||||||
value = precision_arg.ulong_long_value;
|
value = precision_arg.ulong_value;
|
||||||
break;
|
break;
|
||||||
default:
|
case LONG_LONG:
|
||||||
ReportError(s, "precision is not integer");
|
if (precision_arg.long_long_value < 0)
|
||||||
|
ReportError(s, "negative precision in format");
|
||||||
|
value = precision_arg.long_long_value;
|
||||||
|
break;
|
||||||
|
case ULONG_LONG:
|
||||||
|
value = precision_arg.ulong_long_value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ReportError(s, "precision is not integer");
|
||||||
|
}
|
||||||
|
if (value > INT_MAX)
|
||||||
|
ReportError(s, "number is too big in format");
|
||||||
|
precision = static_cast<int>(value);
|
||||||
|
if (*s++ != '}')
|
||||||
|
throw FormatError("unmatched '{' in format");
|
||||||
|
--num_open_braces_;
|
||||||
|
} else {
|
||||||
|
ReportError(s, "missing precision in format");
|
||||||
|
}
|
||||||
|
if (arg.type != DOUBLE && arg.type != LONG_DOUBLE) {
|
||||||
|
ReportError(s,
|
||||||
|
"precision specifier requires floating-point argument");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse type.
|
||||||
|
if (*s != '}' && *s)
|
||||||
|
spec.type_ = static_cast<char>(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*s++ != '}')
|
||||||
|
throw FormatError("unmatched '{' in format");
|
||||||
|
start = s;
|
||||||
|
|
||||||
|
// Format argument.
|
||||||
|
switch (arg.type) {
|
||||||
|
case INT:
|
||||||
|
writer.FormatInt(arg.int_value, spec);
|
||||||
|
break;
|
||||||
|
case UINT:
|
||||||
|
writer.FormatInt(arg.uint_value, spec);
|
||||||
|
break;
|
||||||
|
case LONG:
|
||||||
|
writer.FormatInt(arg.long_value, spec);
|
||||||
|
break;
|
||||||
|
case ULONG:
|
||||||
|
writer.FormatInt(arg.ulong_value, spec);
|
||||||
|
break;
|
||||||
|
case LONG_LONG:
|
||||||
|
writer.FormatInt(arg.long_long_value, spec);
|
||||||
|
break;
|
||||||
|
case ULONG_LONG:
|
||||||
|
writer.FormatInt(arg.ulong_long_value, spec);
|
||||||
|
break;
|
||||||
|
case DOUBLE:
|
||||||
|
writer.FormatDouble(arg.double_value, spec, precision);
|
||||||
|
break;
|
||||||
|
case LONG_DOUBLE:
|
||||||
|
writer.FormatDouble(arg.long_double_value, spec, precision);
|
||||||
|
break;
|
||||||
|
case CHAR: {
|
||||||
|
if (spec.type_ && spec.type_ != 'c')
|
||||||
|
internal::ReportUnknownType(spec.type_, "char");
|
||||||
|
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
||||||
|
CharPtr out = CharPtr();
|
||||||
|
if (spec.width_ > 1) {
|
||||||
|
Char fill = static_cast<Char>(spec.fill());
|
||||||
|
out = writer.GrowBuffer(spec.width_);
|
||||||
|
if (spec.align_ == ALIGN_RIGHT) {
|
||||||
|
std::fill_n(out, spec.width_ - 1, fill);
|
||||||
|
out += spec.width_ - 1;
|
||||||
|
} else if (spec.align_ == ALIGN_CENTER) {
|
||||||
|
out = writer.FillPadding(out, spec.width_, 1, fill);
|
||||||
|
} else {
|
||||||
|
std::fill_n(out + 1, spec.width_ - 1, fill);
|
||||||
}
|
}
|
||||||
if (value > INT_MAX)
|
|
||||||
ReportError(s, "number is too big in format");
|
|
||||||
precision = static_cast<int>(value);
|
|
||||||
if (*s++ != '}')
|
|
||||||
throw FormatError("unmatched '{' in format");
|
|
||||||
--num_open_braces_;
|
|
||||||
} else {
|
} else {
|
||||||
ReportError(s, "missing precision in format");
|
out = writer.GrowBuffer(1);
|
||||||
}
|
}
|
||||||
if (arg.type != DOUBLE && arg.type != LONG_DOUBLE) {
|
*out = arg.int_value;
|
||||||
ReportError(s,
|
break;
|
||||||
"precision specifier requires floating-point argument");
|
}
|
||||||
|
case STRING: {
|
||||||
|
if (spec.type_ && spec.type_ != 's')
|
||||||
|
internal::ReportUnknownType(spec.type_, "string");
|
||||||
|
const Char *str = arg.string.value;
|
||||||
|
std::size_t size = arg.string.size;
|
||||||
|
if (size == 0) {
|
||||||
|
if (!str)
|
||||||
|
throw FormatError("string pointer is null");
|
||||||
|
if (*str)
|
||||||
|
size = std::char_traits<Char>::length(str);
|
||||||
}
|
}
|
||||||
|
writer.FormatString(str, size, spec);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case POINTER:
|
||||||
// Parse type.
|
if (spec.type_ && spec.type_ != 'p')
|
||||||
if (*s != '}' && *s)
|
internal::ReportUnknownType(spec.type_, "pointer");
|
||||||
spec.type_ = static_cast<char>(*s++);
|
spec.flags_= HASH_FLAG;
|
||||||
}
|
spec.type_ = 'x';
|
||||||
|
writer.FormatInt(reinterpret_cast<uintptr_t>(arg.pointer_value), spec);
|
||||||
if (*s++ != '}')
|
break;
|
||||||
throw FormatError("unmatched '{' in format");
|
case CUSTOM:
|
||||||
start = s;
|
if (spec.type_)
|
||||||
|
internal::ReportUnknownType(spec.type_, "object");
|
||||||
// Format argument.
|
arg.custom.format(writer, arg.custom.value, spec);
|
||||||
switch (arg.type) {
|
break;
|
||||||
case INT:
|
default:
|
||||||
writer.FormatInt(arg.int_value, spec);
|
assert(false);
|
||||||
break;
|
break;
|
||||||
case UINT:
|
|
||||||
writer.FormatInt(arg.uint_value, spec);
|
|
||||||
break;
|
|
||||||
case LONG:
|
|
||||||
writer.FormatInt(arg.long_value, spec);
|
|
||||||
break;
|
|
||||||
case ULONG:
|
|
||||||
writer.FormatInt(arg.ulong_value, spec);
|
|
||||||
break;
|
|
||||||
case LONG_LONG:
|
|
||||||
writer.FormatInt(arg.long_long_value, spec);
|
|
||||||
break;
|
|
||||||
case ULONG_LONG:
|
|
||||||
writer.FormatInt(arg.ulong_long_value, spec);
|
|
||||||
break;
|
|
||||||
case DOUBLE:
|
|
||||||
writer.FormatDouble(arg.double_value, spec, precision);
|
|
||||||
break;
|
|
||||||
case LONG_DOUBLE:
|
|
||||||
writer.FormatDouble(arg.long_double_value, spec, precision);
|
|
||||||
break;
|
|
||||||
case CHAR: {
|
|
||||||
if (spec.type_ && spec.type_ != 'c')
|
|
||||||
internal::ReportUnknownType(spec.type_, "char");
|
|
||||||
typedef typename BasicWriter<Char>::CharPtr CharPtr;
|
|
||||||
CharPtr out = CharPtr();
|
|
||||||
if (spec.width_ > 1) {
|
|
||||||
Char fill = static_cast<Char>(spec.fill());
|
|
||||||
out = writer.GrowBuffer(spec.width_);
|
|
||||||
if (spec.align_ == ALIGN_RIGHT) {
|
|
||||||
std::fill_n(out, spec.width_ - 1, fill);
|
|
||||||
out += spec.width_ - 1;
|
|
||||||
} else if (spec.align_ == ALIGN_CENTER) {
|
|
||||||
out = writer.FillPadding(out, spec.width_, 1, fill);
|
|
||||||
} else {
|
|
||||||
std::fill_n(out + 1, spec.width_ - 1, fill);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
out = writer.GrowBuffer(1);
|
|
||||||
}
|
}
|
||||||
*out = arg.int_value;
|
}
|
||||||
break;
|
} catch (const FormatError &e) {
|
||||||
}
|
// rethrow FormatError with the format string pointed to by start
|
||||||
case STRING: {
|
throw BasicFormatError<Char>(e.what(), original);
|
||||||
if (spec.type_ && spec.type_ != 's')
|
|
||||||
internal::ReportUnknownType(spec.type_, "string");
|
|
||||||
const Char *str = arg.string.value;
|
|
||||||
std::size_t size = arg.string.size;
|
|
||||||
if (size == 0) {
|
|
||||||
if (!str)
|
|
||||||
throw FormatError("string pointer is null");
|
|
||||||
if (*str)
|
|
||||||
size = std::char_traits<Char>::length(str);
|
|
||||||
}
|
|
||||||
writer.FormatString(str, size, spec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case POINTER:
|
|
||||||
if (spec.type_ && spec.type_ != 'p')
|
|
||||||
internal::ReportUnknownType(spec.type_, "pointer");
|
|
||||||
spec.flags_= HASH_FLAG;
|
|
||||||
spec.type_ = 'x';
|
|
||||||
writer.FormatInt(reinterpret_cast<uintptr_t>(arg.pointer_value), spec);
|
|
||||||
break;
|
|
||||||
case CUSTOM:
|
|
||||||
if (spec.type_)
|
|
||||||
internal::ReportUnknownType(spec.type_, "object");
|
|
||||||
arg.custom.format(writer, arg.custom.value, spec);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
writer.buffer_.append(start, s);
|
writer.buffer_.append(start, s);
|
||||||
}
|
}
|
||||||
@ -687,6 +693,18 @@ template void fmt::BasicFormatter<char>::CheckSign(
|
|||||||
|
|
||||||
template void fmt::BasicFormatter<char>::DoFormat();
|
template void fmt::BasicFormatter<char>::DoFormat();
|
||||||
|
|
||||||
|
#ifdef FMT_FORMAT_STRING_IN_ERRORS
|
||||||
|
std::string fmt::FormatErrorMessage(const std::string &message, const char *format) {
|
||||||
|
fmt::Writer w;
|
||||||
|
w << "error: " << message << " while parsing format string " << format;
|
||||||
|
return w.str();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::string fmt::FormatErrorMessage(const std::string &message, const char *format) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
template void fmt::BasicWriter<wchar_t>::FormatDouble<double>(
|
template void fmt::BasicWriter<wchar_t>::FormatDouble<double>(
|
||||||
@ -719,3 +737,21 @@ template void fmt::BasicFormatter<wchar_t>::CheckSign(
|
|||||||
const wchar_t *&s, const Arg &arg);
|
const wchar_t *&s, const Arg &arg);
|
||||||
|
|
||||||
template void fmt::BasicFormatter<wchar_t>::DoFormat();
|
template void fmt::BasicFormatter<wchar_t>::DoFormat();
|
||||||
|
|
||||||
|
#ifdef FMT_FORMAT_STRING_IN_ERRORS
|
||||||
|
std::string fmt::FormatErrorMessage(const std::string &message, const wchar_t *format) {
|
||||||
|
|
||||||
|
int size = FMT_SNPRINTF(NULL, 0, "%ls", format);
|
||||||
|
char* buf = (char*)malloc(size+1);
|
||||||
|
FMT_SNPRINTF(buf, size+1, "%ls", format);
|
||||||
|
|
||||||
|
fmt::Writer w;
|
||||||
|
w << "error: " << message << " while parsing format string " << buf;
|
||||||
|
free(buf);
|
||||||
|
return w.str();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::string fmt::FormatErrorMessage(const std::string &message, const wchar_t *format) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
23
format.h
23
format.h
@ -315,6 +315,20 @@ class FormatError : public std::runtime_error {
|
|||||||
: std::runtime_error(message) {}
|
: std::runtime_error(message) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string FormatErrorMessage(const std::string &message, const char *format);
|
||||||
|
std::string FormatErrorMessage(const std::string &message, const wchar_t *format);
|
||||||
|
|
||||||
|
template <typename Char>
|
||||||
|
class BasicFormatError : public std::runtime_error {
|
||||||
|
private:
|
||||||
|
std::basic_string<Char> format_;
|
||||||
|
public:
|
||||||
|
explicit BasicFormatError(const std::string &message, const Char *format)
|
||||||
|
: std::runtime_error(fmt::FormatErrorMessage(message, format)), format_(format){}
|
||||||
|
virtual ~BasicFormatError() throw() {}
|
||||||
|
const Char *format() const { return format_.c_str(); }
|
||||||
|
};
|
||||||
|
|
||||||
enum Alignment {
|
enum Alignment {
|
||||||
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
||||||
};
|
};
|
||||||
@ -402,6 +416,11 @@ class IntFormatter : public SpecT {
|
|||||||
*/
|
*/
|
||||||
IntFormatter<int, TypeSpec<'b'> > bin(int value);
|
IntFormatter<int, TypeSpec<'b'> > bin(int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an integer formatter that formats the value in base 2.
|
||||||
|
*/
|
||||||
|
IntFormatter<int, TypeSpec<'B'> > binu(int value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns an integer formatter that formats the value in base 8.
|
Returns an integer formatter that formats the value in base 8.
|
||||||
*/
|
*/
|
||||||
@ -439,7 +458,9 @@ IntFormatter<int, AlignTypeSpec<TYPE_CODE> > pad(
|
|||||||
inline IntFormatter<TYPE, TypeSpec<'b'> > bin(TYPE value) { \
|
inline IntFormatter<TYPE, TypeSpec<'b'> > bin(TYPE value) { \
|
||||||
return IntFormatter<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \
|
return IntFormatter<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \
|
||||||
} \
|
} \
|
||||||
\
|
inline IntFormatter<TYPE, TypeSpec<'B'> > binu(TYPE value) { \
|
||||||
|
return IntFormatter<TYPE, TypeSpec<'B'> >(value, TypeSpec<'B'>()); \
|
||||||
|
} \
|
||||||
inline IntFormatter<TYPE, TypeSpec<'o'> > oct(TYPE value) { \
|
inline IntFormatter<TYPE, TypeSpec<'o'> > oct(TYPE value) { \
|
||||||
return IntFormatter<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \
|
return IntFormatter<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \
|
||||||
} \
|
} \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user