From ffeed000b3136ffba3a247a7485427e09f8a2433 Mon Sep 17 00:00:00 2001 From: helly Date: Tue, 1 May 2007 20:37:49 +0000 Subject: [PATCH] - Simplify replaceParam() by turning it into template This allows to get rid of sprintf --- re2c/code.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/re2c/code.cc b/re2c/code.cc index 4d51e2e6..d260a019 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -4,6 +4,7 @@ #include #include #include +#include #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 +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) -- 2.50.1