From ccb16252f0f9f55198ca2662ab8daf7199b817de Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 22 Nov 2012 16:17:08 -0800 Subject: move join() to utils --- tools/utils.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tools/utils.c') diff --git a/tools/utils.c b/tools/utils.c index 6dbbff4..691070e 100644 --- a/tools/utils.c +++ b/tools/utils.c @@ -1,4 +1,4 @@ -#include +#include "utils.h" #include #include #include /* for abs() */ @@ -6,8 +6,8 @@ ///// due to lack of interger abs() ///// and ambiguous (and inefficient) promotion #include /* for isalnum() */ -using namespace std; +using namespace std; // strip off the directory part of a path, leaving just // the basic filename @@ -28,7 +28,6 @@ int prefix(const string shorter, const string longer){ // print a time as (-)hh:mm:ss // string time_out(const int _ttt){ -using namespace std; int ttt(abs(_ttt)); int sec(ttt % 60); int min((ttt / 60) % 60); @@ -76,7 +75,6 @@ string trim(const string foo, const string bar){ static const string Pure_Enough("+-_.,@%~"); string purify(const string arg){ - using namespace std; string rslt(arg); for (string::iterator ptr = rslt.begin(); ptr != rslt.end(); ptr++){ @@ -115,3 +113,14 @@ string noCR(const string bar){ } return foo; } + +// sorta like Perl's join(...) +string join(const string sep, const list stuff){ + string rslt; + for (list::const_iterator ptr = stuff.begin(); + ptr != stuff.end(); ptr++){ + if (rslt.length()) rslt += sep; + rslt += *ptr; + } + return rslt; +} -- cgit v1.2.3