#include "HttpRequest.h"
#include "log/Config.h"
#include "MemBuf.h"
+#include "sbuf/SBufStringConvert.h"
#include "SquidConfig.h"
#include "Store.h"
#include "URL.h"
{
if (store_id.size() != 0) {
debugs(73, 3, "sent back store_id: " << store_id);
- return SBuf(store_id);
+ return SBuf(StringToSBuf(store_id));
}
debugs(73, 3, "sent back effectiveRequestUrl: " << effectiveRequestUri());
return effectiveRequestUri();
send-announce.cc \
SBufStatsAction.h \
SBufStatsAction.cc \
+ sbuf/SBufStringConvert.h \
$(SNMP_SOURCE) \
SquidMath.h \
SquidMath.cc \
#include "dlink.h"
#include "http/RequestMethod.h"
#include "RemovalPolicy.h"
+#include "SquidString.h"
#include "stmem.h"
#include "StoreIOBuffer.h"
#include "StoreIOState.h"
#include "Debug.h"
#include "HttpHeaderTools.h"
#include "sbuf/SBuf.h"
+#include "sbuf/SBufStringConvert.h"
/* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
* selected header from a given request.
return false;
}
- SBuf cvalue(value);
+ SBuf cvalue(StringToSBuf(value));
return regex_rule->match(cvalue.c_str());
}
#include "HttpRequest.h"
#include "Notes.h"
#include "parser/Tokenizer.h"
+#include "sbuf/SBufStringConvert.h"
int
ACLNoteStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
for (auto &entry: note->entries) {
if (delimiters) {
NotePairs::Entry e(entry->name.termedBuf(), "");
- Parser::Tokenizer t(SBuf(entry->value));
+ Parser::Tokenizer t(SBuf(StringToSBuf(entry->value)));
SBuf s;
while (t.token(s, *delimiters)) {
e.value = s.c_str();
#include "acl/StringData.h"
#include "ConfigParser.h"
#include "Debug.h"
+#include "sbuf/SBufStringConvert.h"
#include "wordlist.h"
ACLNoteData::ACLNoteData() : values(new ACLStringData)
ACLNoteData::dump() const
{
SBufList sl;
- sl.push_back(SBuf(name));
+ sl.push_back(StringToSBuf(name));
#if __cplusplus >= 201103L
sl.splice(sl.end(), values->dump());
#else
#include "HttpMsg.h"
#include "HttpReply.h"
#include "HttpRequest.h"
+#include "sbuf/SBufStringConvert.h"
Adaptation::Iterator::Iterator(
HttpMsg *aMsg, HttpRequest *aCause,
request = theCause;
Must(request);
Adaptation::History::Pointer ah = request->adaptHistory(true);
- SBuf gid(theGroup->id);
+ SBuf gid(StringToSBuf(theGroup->id));
ah->recordAdaptationService(gid);
}
if (Adaptation::Config::needHistory) {
Adaptation::History::Pointer ah = request->adaptHistory(true);
- SBuf uid(thePlan.current()->cfg().key);
+ SBuf uid(StringToSBuf(thePlan.current()->cfg().key));
ah->recordAdaptationService(uid);
}
#include "squid.h"
#include "base/TextException.h"
#include "ipc/TypedMsgHdr.h"
+#include "SquidString.h"
#include "tools.h"
#include <cstring>
#include "base/TextException.h"
#include "ipc/TypedMsgHdr.h"
#include "mgr/ActionParams.h"
+#include "sbuf/SBufStringConvert.h"
Mgr::ActionParams::ActionParams(): httpMethod(Http::METHOD_NONE)
{
Mgr::ActionParams::pack(Ipc::TypedMsgHdr &msg) const
{
msg.putString(httpUri);
- String foo(httpMethod.image().toString());
+ String foo(SBufToString(httpMethod.image()));
msg.putString(foo);
msg.putPod(httpFlags);
msg.putString(httpOrigin);
SBufExceptions.h \
SBufList.cc \
SBufList.h \
- SBufStream.h
\ No newline at end of file
+ SBufStream.h
const SBuf::size_type SBuf::maxSize;
SBufStats::SBufStats()
- : alloc(0), allocCopy(0), allocFromString(0), allocFromCString(0),
+ : alloc(0), allocCopy(0), allocFromCString(0),
assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
getChar(0), compareSlow(0), compareFast(0), copyOut(0),
rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
{
alloc += ss.alloc;
allocCopy += ss.allocCopy;
- allocFromString += ss.allocFromString;
allocFromCString += ss.allocFromCString;
assignFast += ss.assignFast;
clear += ss.clear;
++stats.live;
}
-SBuf::SBuf(const String &S)
- : store_(GetStorePrototype()), off_(0), len_(0)
-{
- debugs(24, 8, id << " created from string");
- assign(S.rawBuf(), S.size());
- ++stats.alloc;
- ++stats.allocFromString;
- ++stats.live;
-}
-
SBuf::SBuf(const std::string &s)
: store_(GetStorePrototype()), off_(0), len_(0)
{
debugs(24, 8, id << " created from std::string");
lowAppend(s.data(),s.length());
++stats.alloc;
- ++stats.allocFromString;
++stats.live;
}
os <<
"SBuf stats:\nnumber of allocations: " << alloc <<
"\ncopy-allocations: " << allocCopy <<
- "\ncopy-allocations from SquidString: " << allocFromString <<
"\ncopy-allocations from C String: " << allocFromCString <<
"\nlive references: " << live <<
"\nno-copy assignments: " << assignFast <<
throw OutOfBoundsException(*this, pos, __FILE__, __LINE__);
}
-String
-SBuf::toString() const
-{
- String rv;
- rv.limitInit(buf(), length());
- ++stats.copyOut;
- return rv;
-}
-
/** re-allocate the backing store of the SBuf.
*
* If there are contents in the SBuf, they will be copied over.
#include "globals.h"
#include "sbuf/MemBlob.h"
#include "SBufExceptions.h"
-#include "SquidString.h"
#include <climits>
#include <cstdarg>
public:
uint64_t alloc; ///<number of calls to SBuf constructors
uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
- uint64_t allocFromString; ///<number of copy-allocations from Strings
uint64_t allocFromCString; ///<number of copy-allocations from c-strings
uint64_t assignFast; ///<number of no-copy assignment operations
uint64_t clear; ///<number of clear operations
explicit SBuf(const char *S, size_type n);
explicit SBuf(const char *S);
- /** Constructor: import SquidString, copying contents.
- *
- * This method will be removed once SquidString has gone.
- */
- explicit SBuf(const String &S);
-
/// Constructor: import std::string. Contents are copied.
explicit SBuf(const std::string &s);
/// converts all characters to upper case; \see man toupper(3)
void toUpper();
- /** String export function
- * converts the SBuf to a legacy String, by copy.
- * \deprecated
- */
- String toString() const;
-
/// std::string export function
std::string toStdString() const { return std::string(buf(),length()); }
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_SBUF_SBUFSTRING_H_
+#define SQUID_SRC_SBUF_SBUFSTRING_H_
+
+#include "SBuf.h"
+#include "SquidString.h"
+
+/// create a new SBuf from a String
+inline SBuf
+StringToSBuf(const String &s)
+{
+ return SBuf(s.rawBuf(), s.size());
+}
+
+/// create a new String from a SBuf
+inline String
+SBufToString(const SBuf &s)
+{
+ String rv;
+ rv.limitInit(s.rawContent(), s.length());
+ return rv;
+}
+
+#endif /* SQUID_SRC_SBUF_SBUFSTRING_H_ */
SBuf::SBuf(const SBuf &S) {}
SBuf::SBuf(const char *S, size_type n) {}
SBuf::SBuf(const char *S) {}
-SBuf::SBuf(const String &S) {}
SBuf::SBuf(const std::string &s) {}
SBuf::~SBuf() {}
SBuf& SBuf::assign(const SBuf &S) STUB_RETVAL(*this)
int SBuf::scanf(const char *format, ...) STUB_RETVAL(-1)
void SBuf::toLower() STUB
void SBuf::toUpper() STUB
-String SBuf::toString() const STUB_RETVAL(String(""))
#include "sbuf/SBufAlgos.h"
#include "SBufFindTest.h"
#include "sbuf/SBufStream.h"
-#include "SquidString.h"
#include "testSBuf.h"
#include "unitTestMain.h"
CPPUNIT_ASSERT_EQUAL(s4,s3);
}
- // TEST: go via SquidString adapters.
- {
- String str(fox);
- SBuf s1(str);
- CPPUNIT_ASSERT_EQUAL(literal,s1);
- }
-
// TEST: go via std::string adapter.
{
std::string str(fox);