--- src/SBufList.cc 1970-01-01 00:00:00 +0000 +++ src/SBufList.cc 2013-11-24 16:25:17 +0000 @@ -0,0 +1,77 @@ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + */ + +#include "squid.h" +#include "SBufList.h" + +bool isMember(const SBufList & sl, const SBuf &S, SBufCaseSensitive case_sensitive) +{ + for (SBufList::const_iterator i = sl.begin(); i != sl.end(); ++i) + if (i->compare(S,case_sensitive) == 0) + return true; + return false; +} + +SBuf +SBufListJoin(const SBufList &list, const SBuf &separator) +{ + if (list.size() == 0) + return SBuf(""); + if (list.size() == 1) + return list.front(); + + SBufList::const_iterator i; + // calculate the total size of the return value + SBuf::size_type sz = 0; + for (i = list.begin(); i != list.end(); ++i) + sz += i->length(); + sz += separator.length()*list.size(); + + SBuf rv; + rv.rawSpace(sz); + + i = list.begin(); + rv.append(*i); + ++i; + for (; i!= list.end(); ++i) { + rv.append(separator); + rv.append(*i); + } + return rv; +} + +SBufList +wordlistToSBufList(wordlist *wl) +{ + SBufList rv; + while (wl != NULL) { + rv.push_back(SBuf(wl->key)); + wl = wl->next; + } + return rv; +} === added file 'src/SBufList.h' --- src/SBufList.h 1970-01-01 00:00:00 +0000 +++ src/SBufList.h 2013-11-24 16:25:17 +0000 @@ -0,0 +1,54 @@ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + */ + +#ifndef SQUID_SBUFLIST_H +#define SQUID_SBUFLIST_H + +#include "SBuf.h" +#include "wordlist.h" + +#include + +typedef std::list SBufList; + +/** check for membership + * + * \return true if the supplied SBuf is a member of the list + * \param case_sensitive one of caseSensitive or caseInsensitive + */ +bool isMember(const SBufList &, const SBuf &, SBufCaseSensitive isCaseSensitive = caseSensitive); + +/** join a SBufList into a SBuf using the supplied separator. + */ +SBuf SBufListJoin(const SBufList &list, const SBuf &separator); + +/** convert a wordlist to a SBufList + */ +SBufList wordlistToSbufList(wordlist *); + +#endif /* SQUID_SBUFLIST_H */ === added file 'src/tests/testSBufList.cc' --- src/tests/testSBufList.cc 1970-01-01 00:00:00 +0000 +++ src/tests/testSBufList.cc 2013-11-25 18:33:15 +0000 @@ -0,0 +1,34 @@ +#include "squid.h" +#include "SBufList.h" +#include "testSBufList.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( testSBufList ); + +SBuf literal("The quick brown fox jumped over the lazy dog"); +static int sbuf_tokens_number=9; +static SBuf tokens[]={ + SBuf("The",3), SBuf("quick",5), SBuf("brown",5), SBuf("fox",3), + SBuf("jumped",6), SBuf("over",4), SBuf("the",3), SBuf("lazy",4), + SBuf("dog",3) +}; + +void +testSBufList::testSBufListMembership() +{ + SBufList foo; + for (int j=0; j + +#include "OutOfBoundsException.h" + +class testSBufList : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( testSBufList ); + CPPUNIT_TEST( testSBufListMembership ); + CPPUNIT_TEST( testSBufListJoin ); + CPPUNIT_TEST_SUITE_END(); +protected: + void testSBufListMembership(); + void testSBufListJoin(); +}; + +#endif