diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index c84b58ae..6b6cac05 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: smallut.cpp,v 1.27 2007-10-19 15:25:19 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: smallut.cpp,v 1.28 2008-05-08 09:57:29 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -168,8 +168,7 @@ bool samecharset(const string &cs1, const string &cs2) return mcs1 == mcs2; } - -bool stringToStrings(const string &s, std::list &tokens) +template bool stringToStrings(const string &s, T &tokens) { string current; tokens.clear(); @@ -258,10 +257,18 @@ bool stringToStrings(const string &s, std::list &tokens) } return true; } - -void stringsToString(const list &tokens, string &s) +bool stringToStrings(const string &s, list &tokens) { - for (list::const_iterator it = tokens.begin(); + return stringToStrings >(s, tokens); +} +bool stringToStrings(const string &s, vector &tokens) +{ + return stringToStrings >(s, tokens); +} + +template void stringsToString(const T &tokens, string &s) +{ + for (typename T::const_iterator it = tokens.begin(); it != tokens.end(); it++) { bool hasblanks = false; if (it->find_first_of(" \t\n") != string::npos) @@ -283,6 +290,14 @@ void stringsToString(const list &tokens, string &s) s.append(1, '"'); } } +void stringsToString(const list &tokens, string &s) +{ + stringsToString >(tokens, s); +} +void stringsToString(const vector &tokens, string &s) +{ + stringsToString >(tokens, s); +} void stringToTokens(const string& str, list& tokens, const string& delims, bool skipinit) diff --git a/src/utils/smallut.h b/src/utils/smallut.h index 6dbcee8d..3ce1fd92 100644 --- a/src/utils/smallut.h +++ b/src/utils/smallut.h @@ -16,14 +16,16 @@ */ #ifndef _SMALLUT_H_INCLUDED_ #define _SMALLUT_H_INCLUDED_ -/* @(#$Id: smallut.h,v 1.27 2007-05-21 12:03:52 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: smallut.h,v 1.28 2008-05-08 09:57:29 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include +#include #include #ifndef NO_NAMESPACES using std::string; using std::list; +using std::vector; using std::map; #endif /* NO_NAMESPACES */ @@ -45,10 +47,13 @@ extern bool samecharset(const string &cs1, const string &cs2); * dquotes can be escaped with \ etc... */ extern bool stringToStrings(const string &s, list &tokens); +extern bool stringToStrings(const string &s, vector &tokens); + /** * Inverse operation: */ extern void stringsToString(const list &tokens, string &s); +extern void stringsToString(const vector &tokens, string &s); /** * Split input string. No handling of quoting