From 38ccb12eb080cd71807635e155abf0f4265a49f7 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 17 Jan 2003 05:49:03 +0000 Subject: [PATCH] Use stringstream in place of sprintf. --- LineInfo.cc | 30 +++++++++++++++++++++++++----- LineInfo.h | 11 +++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/LineInfo.cc b/LineInfo.cc index fb10d197f..98f7541ce 100644 --- a/LineInfo.cc +++ b/LineInfo.cc @@ -17,13 +17,18 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: LineInfo.cc,v 1.3 2002/08/12 01:34:58 steve Exp $" +#ident "$Id: LineInfo.cc,v 1.4 2003/01/17 05:49:03 steve Exp $" #endif # include "config.h" # include "LineInfo.h" -# include +# include + +LineInfo::LineInfo() +: file_(0), lineno_(0) +{ +} LineInfo::~LineInfo() { @@ -31,9 +36,11 @@ LineInfo::~LineInfo() string LineInfo::get_line() const { - char buf[8]; - sprintf(buf, "%u", lineno_); - return string(file_? file_ : "") + ":" + buf; + ostringstream buf; + buf << (file_? file_ : "") << ":" << lineno_; + + string res = buf.str(); + return res; } void LineInfo::set_line(const LineInfo&that) @@ -42,8 +49,21 @@ void LineInfo::set_line(const LineInfo&that) lineno_ = that.lineno_; } +void LineInfo::set_file(const char*f) +{ + file_ = f; +} + +void LineInfo::set_lineno(unsigned n) +{ + lineno_ = n; +} + /* * $Log: LineInfo.cc,v $ + * Revision 1.4 2003/01/17 05:49:03 steve + * Use stringstream in place of sprintf. + * * Revision 1.3 2002/08/12 01:34:58 steve * conditional ident string using autoconfig. * diff --git a/LineInfo.h b/LineInfo.h index db72f7b1f..31d713602 100644 --- a/LineInfo.h +++ b/LineInfo.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: LineInfo.h,v 1.6 2002/08/12 01:34:58 steve Exp $" +#ident "$Id: LineInfo.h,v 1.7 2003/01/17 05:49:03 steve Exp $" #endif # include @@ -35,15 +35,15 @@ class LineInfo { public: - LineInfo() : file_(0), lineno_(0) { } + LineInfo(); ~LineInfo(); string get_line() const; void set_line(const LineInfo&that); - void set_file(const char*f) { file_ = f; } - void set_lineno(unsigned n) { lineno_ = n; } + void set_file(const char*f); + void set_lineno(unsigned n); private: const char* file_; @@ -52,6 +52,9 @@ class LineInfo { /* * $Log: LineInfo.h,v $ + * Revision 1.7 2003/01/17 05:49:03 steve + * Use stringstream in place of sprintf. + * * Revision 1.6 2002/08/12 01:34:58 steve * conditional ident string using autoconfig. *