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/mail-scan.c | 13 +------------ tools/skrewt.c | 10 ---------- tools/utils.c | 17 +++++++++++++---- tools/utils.h | 2 ++ tools/ward.c | 10 ---------- 5 files changed, 16 insertions(+), 36 deletions(-) diff --git a/tools/mail-scan.c b/tools/mail-scan.c index 3100ab6..0ed7465 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -80,18 +80,6 @@ void exeunt(const int sts){ exit(sts); } -string join(const string sep, list stuff){ - string rslt; - if (!stuff.size()) return rslt; - list::const_iterator ptr = stuff.begin(); - rslt = *ptr++; - for (; ptr != stuff.end(); ptr++){ - rslt += sep; - rslt += *ptr; - } - return rslt; -} - class watcher { public: string key; @@ -115,6 +103,7 @@ public: } }; + //////////////////////////////////////////////////////////// int main(int _argc, const char** _argv){ //// pid_t pid = getpid(); diff --git a/tools/skrewt.c b/tools/skrewt.c index 540b1cf..8c07974 100644 --- a/tools/skrewt.c +++ b/tools/skrewt.c @@ -117,16 +117,6 @@ void parse_content(const string type_spec_line, } } -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; -} - class skrewt{ public: string received_from; // envelope HELO among other things 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; +} diff --git a/tools/utils.h b/tools/utils.h index 77cff5e..1e6ac9d 100644 --- a/tools/utils.h +++ b/tools/utils.h @@ -1,8 +1,10 @@ #include #include +#include std::string noCR(const std::string bar); int cmp_casefold(const std::string& a, const std::string& b); +std::string join(const std::string sep, const std::list stuff); ///////////////////////////////////////////////////////// // Case insensitive comparison of strings diff --git a/tools/ward.c b/tools/ward.c index 8be9f70..56e626d 100644 --- a/tools/ward.c +++ b/tools/ward.c @@ -74,16 +74,6 @@ int mypid; #include "libskrewt.h" -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; -} - class skrewt{ public: string received_from; // envelope HELO among other things -- cgit v1.2.3