]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/wordlist.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_WORDLIST_H
10 #define SQUID_SRC_WORDLIST_H
13 #include "sbuf/List.h"
19 /// minimal iterator for read-only traversal of wordlist objects
20 class WordlistIterator
23 using value_type
= const char *;
25 explicit WordlistIterator(const wordlist
* const wl
): w(wl
) {}
27 auto operator ==(const WordlistIterator
&rhs
) const { return this->w
== rhs
.w
; }
28 auto operator !=(const WordlistIterator
&rhs
) const { return this->w
!= rhs
.w
; }
30 inline value_type
operator *() const;
31 inline WordlistIterator
&operator++();
37 /** A list of C-strings
39 * \deprecated use SBufList instead
43 MEMPROXY_CLASS(wordlist
);
44 friend char *wordlistChopHead(wordlist
**);
47 using const_iterator
= WordlistIterator
;
49 wordlist() : key(nullptr), next(nullptr) {}
50 // create a new wordlist node, with a copy of k as key
51 explicit wordlist(const char *k
) : key(xstrdup(k
)), next(nullptr) {}
53 wordlist(const wordlist
&) = delete;
54 wordlist
&operator=(const wordlist
&) = delete;
56 auto begin() const { return const_iterator(this); }
57 auto end() const { return const_iterator(nullptr); }
63 // does not free data members.
64 ~wordlist() = default;
69 /** Add a null-terminated c-string to a wordlist
71 * \deprecated use SBufList.push_back(SBuf(word)) instead
73 const char *wordlistAdd(wordlist
**, const char *);
75 /** Concatenate a wordlist
77 * \deprecated use SBufListContainerJoin(SBuf()) from sbuf/Algorithms.h instead
79 void wordlistCat(const wordlist
*, MemBuf
*);
81 /// destroy a wordlist
82 void wordlistDestroy(wordlist
**);
84 /** Remove and destroy the first element while preserving and returning its key
86 * \note the returned key must be freed by the caller using safe_free
87 * \note wl is altered so that it points to the second element
88 * \return nullptr if pointed-to wordlist is nullptr.
90 char *wordlistChopHead(wordlist
**);
92 inline WordlistIterator
&
93 WordlistIterator::operator++()
99 inline WordlistIterator::value_type
100 WordlistIterator::operator*() const
105 #endif /* SQUID_SRC_WORDLIST_H */