From 8a6080eb1400b9b7414e2ec8b995268315448cb5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 26 Aug 2006 16:48:01 +0000 Subject: [PATCH] * Refactoring. --- src/libexpr/primops.cc | 7 +------ src/libutil/util.cc | 13 +++++++++---- src/libutil/util.hh | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 50712a725..9fbab559e 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -146,12 +146,7 @@ static void processBinding(EvalState & state, Expr e, Derivation & drv, else if (matchUri(e, s)) ss.push_back(aterm2String(s)); else if (e == eTrue) ss.push_back("1"); else if (e == eFalse) ss.push_back(""); - - else if (matchInt(e, n)) { - ostringstream st; - st << n; - ss.push_back(st.str()); - } + else if (matchInt(e, n)) ss.push_back(int2String(n)); else if (matchAttrs(e, es)) { Expr a = queryAttr(e, "type"); diff --git a/src/libutil/util.cc b/src/libutil/util.cc index f34bd9e05..02745498f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -360,10 +360,7 @@ Nest::~Nest() static string escVerbosity(Verbosity level) { - int l = (int) level; - ostringstream st; - st << l; - return st.str(); + return int2String((int) level); } @@ -829,6 +826,14 @@ bool statusOk(int status) } +string int2String(int n) +{ + ostringstream str; + str << n; + return str.str(); +} + + bool string2Int(const string & s, int & n) { istringstream str(s); diff --git a/src/libutil/util.hh b/src/libutil/util.hh index fcf995af8..22e614d95 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -292,6 +292,7 @@ bool statusOk(int status); /* Parse a string into an integer. */ +string int2String(int n); bool string2Int(const string & s, int & n);