]> git.ipfire.org Git - thirdparty/squid.git/blame - src/wordlist.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / wordlist.cc
CommitLineData
d295d770 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
d295d770 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
d295d770 7 */
8
bbc27441
AJ
9/* DEBUG: section 03 Configuration File Parsing */
10
f7f3304a 11#include "squid.h"
d295d770 12#include "MemBuf.h"
602d9612 13#include "wordlist.h"
d295d770 14
15void
16wordlistDestroy(wordlist ** list)
17{
2f373c58
FC
18 while (*list != nullptr) {
19 const char *k = wordlistChopHead(list);
20 safe_free(k);
d295d770 21 }
d295d770 22}
23
24const char *
25wordlistAdd(wordlist ** list, const char *key)
26{
27 while (*list)
28 list = &(*list)->next;
29
0d225c05 30 *list = new wordlist(key);
d295d770 31 return (*list)->key;
32}
33
d295d770 34void
35wordlistCat(const wordlist * w, MemBuf * mb)
36{
37 while (NULL != w) {
4391cd15 38 mb->appendf("%s\n", w->key);
d295d770 39 w = w->next;
40 }
41}
42
514fc315
FC
43SBufList
44ToSBufList(wordlist *wl)
45{
46 SBufList rv;
47 while (wl != NULL) {
48 rv.push_back(SBuf(wl->key));
49 wl = wl->next;
50 }
51 return rv;
52}
f53969cc 53
0d225c05
FC
54char *
55wordlistChopHead(wordlist **wl)
56{
57 if (*wl == nullptr)
58 return nullptr;
59
60 wordlist *w = *wl;
61 char *rv = w->key;
62 *wl = w->next;
63 delete w;
64 return rv;
65}
1a739503 66