]> git.ipfire.org Git - thirdparty/squid.git/blame_incremental - src/acl/StringData.cc
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / acl / StringData.cc
... / ...
CommitLineData
1/*
2 * Copyright (C) 1996-2025 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 28 Access Control */
10
11#include "squid.h"
12#include "acl/Checklist.h"
13#include "acl/StringData.h"
14#include "ConfigParser.h"
15#include "debug/Stream.h"
16
17void
18ACLStringData::insert(const char *value)
19{
20 stringValues.insert(SBuf(value));
21}
22
23bool
24ACLStringData::match(const SBuf &tf)
25{
26 if (stringValues.empty())
27 return 0;
28
29 debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
30
31 bool found = (stringValues.find(tf) != stringValues.end());
32 debugs(28, 3, "aclMatchStringList: '" << tf << "' " << (found ? "found" : "NOT found"));
33
34 return found;
35}
36
37// XXX: performance regression due to SBuf(char*) data-copies.
38bool
39ACLStringData::match(char const *toFind)
40{
41 if (!toFind) {
42 // TODO: Check whether we can Assure(toFind) instead.
43 debugs(28, 3, "not matching a nil c-string");
44 return false;
45 }
46 return match(SBuf(toFind));
47}
48
49SBufList
50ACLStringData::dump() const
51{
52 SBufList sl;
53 sl.insert(sl.end(), stringValues.begin(), stringValues.end());
54 return sl;
55}
56
57void
58ACLStringData::parse()
59{
60 while (const char *t = ConfigParser::strtokFile())
61 stringValues.insert(SBuf(t));
62}
63
64bool
65ACLStringData::empty() const
66{
67 return stringValues.empty();
68}
69