Permalink
Browse files

Use stringstream in place of sprintf.

  • Loading branch information...
1 parent ca3bf14 commit 38ccb12eb080cd71807635e155abf0f4265a49f7 steve committed Jan 17, 2003
Showing with 32 additions and 9 deletions.
  1. +25 −5 LineInfo.cc
  2. +7 −4 LineInfo.h
View
@@ -17,23 +17,30 @@
* 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 <cstdio>
+# include <sstream>
+
+LineInfo::LineInfo()
+: file_(0), lineno_(0)
+{
+}
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.
*
View
@@ -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 <string>
@@ -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.
*

0 comments on commit 38ccb12

Please sign in to comment.