|
a/src/utils/smallut.cpp |
|
b/src/utils/smallut.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.27 2007-10-19 15:25:19 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: smallut.cpp,v 1.28 2008-05-08 09:57:29 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
166 |
}
|
166 |
}
|
167 |
}
|
167 |
}
|
168 |
return mcs1 == mcs2;
|
168 |
return mcs1 == mcs2;
|
169 |
}
|
169 |
}
|
170 |
|
170 |
|
171 |
|
171 |
template <class T> bool stringToStrings(const string &s, T &tokens)
|
172 |
bool stringToStrings(const string &s, std::list<string> &tokens)
|
|
|
173 |
{
|
172 |
{
|
174 |
string current;
|
173 |
string current;
|
175 |
tokens.clear();
|
174 |
tokens.clear();
|
176 |
enum states {SPACE, TOKEN, INQUOTE, ESCAPE};
|
175 |
enum states {SPACE, TOKEN, INQUOTE, ESCAPE};
|
177 |
states state = SPACE;
|
176 |
states state = SPACE;
|
|
... |
|
... |
256 |
case ESCAPE:
|
255 |
case ESCAPE:
|
257 |
return false;
|
256 |
return false;
|
258 |
}
|
257 |
}
|
259 |
return true;
|
258 |
return true;
|
260 |
}
|
259 |
}
|
|
|
260 |
bool stringToStrings(const string &s, list<string> &tokens)
|
|
|
261 |
{
|
|
|
262 |
return stringToStrings<list<string> >(s, tokens);
|
|
|
263 |
}
|
|
|
264 |
bool stringToStrings(const string &s, vector<string> &tokens)
|
|
|
265 |
{
|
|
|
266 |
return stringToStrings<vector<string> >(s, tokens);
|
|
|
267 |
}
|
261 |
|
268 |
|
262 |
void stringsToString(const list<string> &tokens, string &s)
|
269 |
template <class T> void stringsToString(const T &tokens, string &s)
|
263 |
{
|
270 |
{
|
264 |
for (list<string>::const_iterator it = tokens.begin();
|
271 |
for (typename T::const_iterator it = tokens.begin();
|
265 |
it != tokens.end(); it++) {
|
272 |
it != tokens.end(); it++) {
|
266 |
bool hasblanks = false;
|
273 |
bool hasblanks = false;
|
267 |
if (it->find_first_of(" \t\n") != string::npos)
|
274 |
if (it->find_first_of(" \t\n") != string::npos)
|
268 |
hasblanks = true;
|
275 |
hasblanks = true;
|
269 |
if (it != tokens.begin())
|
276 |
if (it != tokens.begin())
|
|
... |
|
... |
280 |
}
|
287 |
}
|
281 |
}
|
288 |
}
|
282 |
if (hasblanks)
|
289 |
if (hasblanks)
|
283 |
s.append(1, '"');
|
290 |
s.append(1, '"');
|
284 |
}
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
void stringsToString(const list<string> &tokens, string &s)
|
|
|
294 |
{
|
|
|
295 |
stringsToString<list<string> >(tokens, s);
|
|
|
296 |
}
|
|
|
297 |
void stringsToString(const vector<string> &tokens, string &s)
|
|
|
298 |
{
|
|
|
299 |
stringsToString<vector<string> >(tokens, s);
|
285 |
}
|
300 |
}
|
286 |
|
301 |
|
287 |
void stringToTokens(const string& str, list<string>& tokens,
|
302 |
void stringToTokens(const string& str, list<string>& tokens,
|
288 |
const string& delims, bool skipinit)
|
303 |
const string& delims, bool skipinit)
|
289 |
{
|
304 |
{
|