Update of /cvsroot/pclasses/pclasses2/include/pclasses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25449/include/pclasses
Added Files:
StringList.h
Log Message:
- Added generic StringList implementation
- Added more operations to Unicode::String
--- NEW FILE: StringList.h ---
/***************************************************************************
* Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef P_StringList_h
#define P_StringList_h
#include <list>
namespace P {
//! String list
template <class StringType>
class StringList: public std::list<StringType> {
public:
typedef std::list<StringType> string_list;
StringList()
: string_list() { }
StringList(const string_list& lst)
: string_list(lst) { }
StringList(const StringType& str, const StringType& separator)
{
*this = fromString(str, separator);
}
//! Join all strings into a single string
StringType join(const StringType& separator) const
{
StringType ret;
typename string_list::const_iterator i = begin();
while(i != end())
{
ret += *i;
++i;
if(i != end())
ret += separator;
}
return ret;
}
//! Tokenize string into list of strings
static string_list fromString(const StringType& str,
const StringType& separator)
{
if(str.empty())
return string_list();
typename StringType::size_type tokenBegin = 0;
typename StringType::size_type tokenEnd;
StringType token;
string_list lst;
while(tokenEnd != StringType::npos)
{
tokenEnd = str.find(separator, tokenBegin);
token = str.substr(tokenBegin, tokenEnd - tokenBegin);
lst.push_back(token);
tokenBegin = tokenEnd + separator.size();
}
return lst;
}
};
} // !namespace P
#endif
|