]> granicus.if.org Git - re2c/commitdiff
- Simplify replaceParam() by turning it into template
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Tue, 1 May 2007 20:37:49 +0000 (20:37 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Tue, 1 May 2007 20:37:49 +0000 (20:37 +0000)
  This allows to get rid of sprintf

re2c/code.cc

index 4d51e2e6feb74ee8268e80473629aae2c57e9cf7..d260a019cbac7070b878ea0ff10b26652b0318bc 100644 (file)
@@ -4,6 +4,7 @@
 #include <ctype.h>
 #include <iomanip>
 #include <iostream>
+#include <sstream>
 #include "substr.h"
 #include "globals.h"
 #include "dfa.h"
@@ -27,27 +28,23 @@ static std::string indent(uint ind)
        return str;
 }
 
-static std::string replaceParam(std::string str, const std::string& param, const std::string& value)
+template<typename _Ty>
+std::string replaceParam(std::string str, const std::string& param, const _Ty& value)
 {
+       std::ostringstream strValue;
+
+       strValue << value;
+
        std::string::size_type pos;
 
        while((pos = str.find(param)) != std::string::npos)
        {
-               str.replace(pos, param.length(), value);
+               str.replace(pos, param.length(), strValue.str());
        }
 
        return str;
 }
 
-static std::string replaceParam(std::string str, const std::string& param, int value)
-{
-       char tmp[16];
-
-       sprintf(tmp, "%d", value);
-
-       return replaceParam(str, param, tmp);
-}
-
 static void genYYFill(std::ostream &o, uint ind, uint need)
 {
        if (bUseYYFillParam)