added: Toa() for long long, int, short and unsigned as well
fixed: when serializing Date the year has at least 4 digits e.g. 0001 when the year is equal to one git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1093 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
date.o: date.h
|
||||
date.o: date.h ../convert/convert.h ../convert/inttostr.h
|
||||
date.o: ../convert/strtoint.h ../convert/text.h ../convert/misc.h
|
||||
|
29
date/date.h
29
date/date.h
@@ -40,7 +40,7 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
#include "convert/convert.h"
|
||||
|
||||
|
||||
namespace PT
|
||||
@@ -493,6 +493,9 @@ private:
|
||||
|
||||
void AssertRange(int & val, int val_min, int val_max);
|
||||
|
||||
template<class Stream>
|
||||
void SerializeInt(Stream & out, int val, size_t min_width) const;
|
||||
|
||||
template<class Stream>
|
||||
void SerializeInt(Stream & out, int val) const;
|
||||
|
||||
@@ -512,17 +515,29 @@ private:
|
||||
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Date::SerializeInt(Stream & out, int val, size_t min_width) const
|
||||
{
|
||||
char buf[64];
|
||||
size_t len;
|
||||
|
||||
if( Toa(val, buf, sizeof(buf) / sizeof(char), 10, &len) )
|
||||
{
|
||||
for(size_t i = len ; i < min_width ; ++i)
|
||||
{
|
||||
out << '0';
|
||||
}
|
||||
|
||||
out << buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Date::SerializeInt(Stream & out, int val) const
|
||||
{
|
||||
if( val >= 0 && val < 10 )
|
||||
out << '0';
|
||||
|
||||
out << val;
|
||||
SerializeInt(out, val, 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -530,8 +545,8 @@ void Date::SerializeInt(Stream & out, int val) const
|
||||
template<class Stream>
|
||||
void Date::SerializeYearMonthDay(Stream & out) const
|
||||
{
|
||||
// !! IMPROVE ME the year should be printed with 4 digits, e.g. 0001 when the year is equal to one
|
||||
out << year << '-';
|
||||
SerializeInt(out, year, 4);
|
||||
out << '-';
|
||||
SerializeInt(out, month);
|
||||
out << '-';
|
||||
SerializeInt(out, day);
|
||||
|
Reference in New Issue
Block a user