small gcc and msvc8 corrections

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@220 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-08-27 12:47:56 +00:00
parent 0f678b97e2
commit cdb70a208b
2 changed files with 8 additions and 6 deletions

View file

@ -22,6 +22,8 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include <cassert>
#include <locale>
// Crude writing method: writes straight to the file, unbuffered // Crude writing method: writes straight to the file, unbuffered
// Must be combined with a buffer to work properly (and efficiently) // Must be combined with a buffer to work properly (and efficiently)
@ -314,7 +316,7 @@ private:
} }
memcpy(fmtBuf, fmt, (format_ - fmt) * sizeof(Char)); memcpy(fmtBuf, fmt, (format_ - fmt) * sizeof(Char));
fmtBuf[format_ - fmt] = 0; fmtBuf[format_ - fmt] = 0;
const int stored = snprintf(resultBuf, const int stored = _snprintf(resultBuf,
sizeof(resultBuf) / sizeof(Char), fmtBuf, n); sizeof(resultBuf) / sizeof(Char), fmtBuf, n);
if (stored < 0) { if (stored < 0) {
result_ = -1; result_ = -1;
@ -402,14 +404,14 @@ private:
} }
void ParseDecimalUInt(unsigned int& dest) { void ParseDecimalUInt(unsigned int& dest) {
if (!std::isdigit(*format_)) return; if (!std::isdigit(*format_, std::locale())) return;
unsigned int r = 0; unsigned int r = 0;
do { do {
// TODO: inefficient - rewrite // TODO: inefficient - rewrite
r *= 10; r *= 10;
r += *format_ - '0'; r += *format_ - '0';
++format_; ++format_;
} while (std::isdigit(*format_)); } while (std::isdigit(*format_, std::locale()));
dest = r; dest = r;
} }
@ -444,7 +446,7 @@ private:
blank = 4, blank = 4,
alternateForm = 8, alternateForm = 8,
fillZeros = 16, fillZeros = 16,
forceShort = 32, forceShort = 32
}; };
bool LeftJustify() const { return (flags_ & leftJustify) != 0; } bool LeftJustify() const { return (flags_ & leftJustify) != 0; }

View file

@ -9,7 +9,7 @@
// warranty. // warranty.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "loki/SafeFormat.h" #include "SafeFormat.h"
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <utility> #include <utility>
@ -55,7 +55,7 @@ void TestCase(const string& fmt, T value) {
char buf[4096]; char buf[4096];
std::string s; std::string s;
const int i1 = SPrintf(s, fmt.c_str())(value); const int i1 = SPrintf(s, fmt.c_str())(value);
const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value); const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value);
if (i1 != i2 || s != buf) { if (i1 != i2 || s != buf) {
cout << cout <<
"\nReference: " << i2 << "\nReference: " << i2 <<