]> git.ipfire.org Git - thirdparty/squid.git/blob - src/wordlist.cc
Rework wordlistDestroy and refine documentation for wordlist as suggested by Alex
[thirdparty/squid.git] / src / wordlist.cc
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 03 Configuration File Parsing */
10
11 #include "squid.h"
12 #include "MemBuf.h"
13 #include "wordlist.h"
14
15 void
16 wordlistDestroy(wordlist ** list)
17 {
18 while (*list != nullptr) {
19 const char *k = wordlistChopHead(list);
20 safe_free(k);
21 }
22 }
23
24 const char *
25 wordlistAdd(wordlist ** list, const char *key)
26 {
27 while (*list)
28 list = &(*list)->next;
29
30 *list = new wordlist(key);
31 return (*list)->key;
32 }
33
34 void
35 wordlistJoin(wordlist ** list, wordlist ** wl)
36 {
37 while (*list)
38 list = &(*list)->next;
39
40 *list = *wl;
41
42 *wl = NULL;
43 }
44
45 void
46 wordlistAddWl(wordlist ** list, wordlist * wl)
47 {
48 while (*list)
49 list = &(*list)->next;
50
51 for (; wl; wl = wl->next, list = &(*list)->next) {
52 *list = new wordlist(wl->key);
53 }
54 }
55
56 void
57 wordlistCat(const wordlist * w, MemBuf * mb)
58 {
59 while (NULL != w) {
60 mb->appendf("%s\n", w->key);
61 w = w->next;
62 }
63 }
64
65 SBufList
66 ToSBufList(wordlist *wl)
67 {
68 SBufList rv;
69 while (wl != NULL) {
70 rv.push_back(SBuf(wl->key));
71 wl = wl->next;
72 }
73 return rv;
74 }
75
76 char *
77 wordlistChopHead(wordlist **wl)
78 {
79 if (*wl == nullptr)
80 return nullptr;
81
82 wordlist *w = *wl;
83 char *rv = w->key;
84 *wl = w->next;
85 delete w;
86 return rv;
87 }
88