fix printing pointers
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@449 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
f09bf76ce3
commit
32b4c0a8fa
2 changed files with 16 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Copyright (c) 2005 by Andrei Alexandrescu
|
// Copyright (c) 2005 by Andrei Alexandrescu
|
||||||
|
// Copyright (c) 2006 Peter Kümmel
|
||||||
// Permission to use, copy, modify, distribute, and sell this software for any
|
// Permission to use, copy, modify, distribute, and sell this software for any
|
||||||
// purpose is hereby granted without fee, provided that the above copyright
|
// purpose is hereby granted without fee, provided that the above copyright
|
||||||
// notice appear in all copies and that both that copyright notice and this
|
// notice appear in all copies and that both that copyright notice and this
|
||||||
|
@ -138,16 +139,22 @@ namespace Loki
|
||||||
FormatWithCurrentFlags(i);
|
FormatWithCurrentFlags(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrintfState& operator()(void* n) {
|
||||||
|
if (result_ == -1) return *this; // don't even bother
|
||||||
|
PrintUsing_printf(n,"p");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
PrintfState& operator()(double n) {
|
PrintfState& operator()(double n) {
|
||||||
if (result_ == -1) return *this; // don't even bother
|
if (result_ == -1) return *this; // don't even bother
|
||||||
PrintFloatingPoint(n);
|
PrintUsing_printf(n,"eEfgG");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState& operator()(long double n) {
|
PrintfState& operator()(long double n) {
|
||||||
if (result_ == -1) return *this; // don't even bother
|
if (result_ == -1) return *this; // don't even bother
|
||||||
PrintFloatingPoint(n);
|
PrintUsing_printf(n,"eEfgG");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,14 +327,14 @@ namespace Loki
|
||||||
result_ += x;
|
result_ += x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Double>
|
template <class Value>
|
||||||
void PrintFloatingPoint(Double n) {
|
void PrintUsing_printf(Value n, const char* check_fmt_char) {
|
||||||
const Char *const fmt = format_ - 1;
|
const Char *const fmt = format_ - 1;
|
||||||
assert(*fmt == '%');
|
assert(*fmt == '%');
|
||||||
// enforce format string validity
|
// enforce format string validity
|
||||||
ReadLeaders();
|
ReadLeaders();
|
||||||
// enforce format spec
|
// enforce format spec
|
||||||
if (!strchr("eEfgG", *format_)) {
|
if (!strchr(check_fmt_char, *format_)) {
|
||||||
result_ = -1;
|
result_ = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -340,11 +347,11 @@ namespace Loki
|
||||||
}
|
}
|
||||||
memcpy(fmtBuf, fmt, (format_ - fmt) * sizeof(Char));
|
memcpy(fmtBuf, fmt, (format_ - fmt) * sizeof(Char));
|
||||||
fmtBuf[format_ - fmt] = 0;
|
fmtBuf[format_ - fmt] = 0;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
const int stored = _snprintf_s(resultBuf,
|
const int stored = _snprintf_s(resultBuf,
|
||||||
#else
|
#else
|
||||||
const int stored = snprintf(resultBuf,
|
const int stored = snprintf(resultBuf,
|
||||||
#endif
|
#endif
|
||||||
sizeof(resultBuf) / sizeof(Char), fmtBuf, n);
|
sizeof(resultBuf) / sizeof(Char), fmtBuf, n);
|
||||||
if (stored < 0) {
|
if (stored < 0) {
|
||||||
result_ = -1;
|
result_ = -1;
|
||||||
|
|
|
@ -176,9 +176,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a random type character
|
// Generate a random type character
|
||||||
/* disable %p tests
|
static const string type("cdeEfgGinopsuxX");
|
||||||
static const string type("cdeEfgGinopsuxX");*/
|
|
||||||
static const string type("cdeEfgGinosuxX");
|
|
||||||
|
|
||||||
const char typeSpec = type[RandomInt(0u, type.size() - 1)];
|
const char typeSpec = type[RandomInt(0u, type.size() - 1)];
|
||||||
// Generate an optional type prefix
|
// Generate an optional type prefix
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue