From 9b8fda796b620a5476e8a50edcc29a3462667fc3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Nov 2009 12:26:25 +0000 Subject: * Templatise getIntArg / string2Int. --- src/libutil/util.cc | 16 ---------------- src/libutil/util.hh | 9 +++++++-- 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 248095b342..1b86e88d7f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1055,22 +1055,6 @@ string int2String(int n) } -bool string2Int(const string & s, int & n) -{ - std::istringstream str(s); - str >> n; - return str && str.get() == EOF; -} - - -bool string2Int(const string & s, long long & n) -{ - std::istringstream str(s); - str >> n; - return str && str.get() == EOF; -} - - bool hasSuffix(const string & s, const string & suffix) { return s.size() >= suffix.size() && string(s, s.size() - suffix.size()) == suffix; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 5744e56922..2d75a7a506 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -295,9 +295,14 @@ bool statusOk(int status); /* Parse a string into an integer. */ +template bool string2Int(const string & s, N & n) +{ + std::istringstream str(s); + str >> n; + return str && str.get() == EOF; +} + string int2String(int n); -bool string2Int(const string & s, int & n); -bool string2Int(const string & s, long long & n); /* Return true iff `s' ends in `suffix'. */ -- cgit 1.4.1