]> git.ipfire.org Git - thirdparty/squid.git/blame - src/wordlist.cc
Rename Packable::Printf as Packable::appendf
[thirdparty/squid.git] / src / wordlist.cc
CommitLineData
d295d770 1/*
bde978a6 2 * Copyright (C) 1996-2015 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{
18 wordlist *w = NULL;
19
20 while ((w = *list) != NULL) {
21 *list = w->next;
22 safe_free(w->key);
23 delete w;
24 }
25
26 *list = NULL;
27}
28
29const char *
30wordlistAdd(wordlist ** list, const char *key)
31{
32 while (*list)
33 list = &(*list)->next;
34
35 *list = new wordlist;
36
37 (*list)->key = xstrdup(key);
38
39 (*list)->next = NULL;
40
41 return (*list)->key;
42}
43
44void
45wordlistJoin(wordlist ** list, wordlist ** wl)
46{
47 while (*list)
48 list = &(*list)->next;
49
50 *list = *wl;
51
52 *wl = NULL;
53}
54
55void
56wordlistAddWl(wordlist ** list, wordlist * wl)
57{
58 while (*list)
59 list = &(*list)->next;
60
61 for (; wl; wl = wl->next, list = &(*list)->next) {
62 *list = new wordlist();
63 (*list)->key = xstrdup(wl->key);
64 (*list)->next = NULL;
65 }
66}
67
68void
69wordlistCat(const wordlist * w, MemBuf * mb)
70{
71 while (NULL != w) {
4391cd15 72 mb->appendf("%s\n", w->key);
d295d770 73 w = w->next;
74 }
75}
76
77wordlist *
78wordlistDup(const wordlist * w)
79{
80 wordlist *D = NULL;
81
82 while (NULL != w) {
83 wordlistAdd(&D, w->key);
84 w = w->next;
85 }
86
87 return D;
88}
514fc315
FC
89
90SBufList
91ToSBufList(wordlist *wl)
92{
93 SBufList rv;
94 while (wl != NULL) {
95 rv.push_back(SBuf(wl->key));
96 wl = wl->next;
97 }
98 return rv;
99}
f53969cc 100