#include <SBuf.h>

Collaboration diagram for SBuf:

Classes

class  Locker
 

Public Types

typedef MemBlob::size_type size_type
 
typedef SBufIterator const_iterator
 
typedef SBufReverseIterator const_reverse_iterator
 

Public Member Functions

 SBuf ()
 create an empty (zero-size) SBuf More...
 
 SBuf (const SBuf &S)
 
 SBuf (SBuf &&S)
 
 SBuf (const char *S, size_type n)
 
 SBuf (const char *S)
 
 SBuf (const std::string &s)
 Constructor: import std::string. Contents are copied. More...
 
 ~SBuf ()
 
SBufassign (const SBuf &S)
 
SBufoperator= (const SBuf &S)
 
SBufoperator= (SBuf &&S)
 
SBufassign (const char *S, size_type n)
 
SBufassign (const char *S)
 
SBufoperator= (const char *S)
 
void clear ()
 
SBufappend (const SBuf &S)
 
SBufappend (const char c)
 Append a single character. The character may be NUL (\0). More...
 
SBufappend (const char *S, size_type Ssize)
 
SBufappend (const char *S)
 
SBufPrintf (const char *fmt,...) PRINTF_FORMAT_ARG2
 
SBufappendf (const char *fmt,...) PRINTF_FORMAT_ARG2
 
SBufvappendf (const char *fmt, va_list vargs)
 
std::ostream & print (std::ostream &os) const
 print the SBuf contents to the supplied ostream More...
 
std::ostream & dump (std::ostream &os) const
 
char operator[] (size_type pos) const
 
char at (size_type pos) const
 
void setAt (size_type pos, char toset)
 
int compare (const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const
 
int compare (const SBuf &S, const SBufCaseSensitive isCaseSensitive) const
 
int cmp (const SBuf &S, const size_type n) const
 shorthand version for compare() More...
 
int cmp (const SBuf &S) const
 
int caseCmp (const SBuf &S, const size_type n) const
 shorthand version for case-insensitive compare() More...
 
int caseCmp (const SBuf &S) const
 
int compare (const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const
 Comparison with a C-string. More...
 
int compare (const char *s, const SBufCaseSensitive isCaseSensitive) const
 
int cmp (const char *S, const size_type n) const
 Shorthand version for C-string compare(). More...
 
int cmp (const char *S) const
 
int caseCmp (const char *S, const size_type n) const
 Shorthand version for case-insensitive C-string compare(). More...
 
int caseCmp (const char *S) const
 
bool startsWith (const SBuf &S, const SBufCaseSensitive isCaseSensitive=caseSensitive) const
 
bool operator== (const SBuf &S) const
 
bool operator!= (const SBuf &S) const
 
bool operator< (const SBuf &S) const
 
bool operator> (const SBuf &S) const
 
bool operator<= (const SBuf &S) const
 
bool operator>= (const SBuf &S) const
 
SBuf consume (size_type n=npos)
 
size_type copy (char *dest, size_type n) const
 
const char * rawContent () const
 
char * rawAppendStart (size_type anticipatedSize)
 
void rawAppendFinish (const char *start, size_type actualSize)
 
size_type spaceSize () const
 
const char * c_str ()
 
size_type length () const
 Returns the number of bytes stored in SBuf. More...
 
int plength () const
 
bool isEmpty () const
 
void reserveSpace (size_type minSpace)
 
void reserveCapacity (size_type minCapacity)
 
size_type reserve (const SBufReservationRequirements &requirements)
 
SBufchop (size_type pos, size_type n=npos)
 
SBuftrim (const SBuf &toRemove, bool atBeginning=true, bool atEnd=true)
 
SBuf substr (size_type pos, size_type n=npos) const
 
size_type find (char c, size_type startPos=0) const
 
size_type find (const SBuf &str, size_type startPos=0) const
 
size_type rfind (char c, size_type endPos=npos) const
 
size_type rfind (const SBuf &str, size_type endPos=npos) const
 
size_type findFirstOf (const CharacterSet &set, size_type startPos=0) const
 
size_type findLastOf (const CharacterSet &set, size_type endPos=npos) const
 
size_type findFirstNotOf (const CharacterSet &set, size_type startPos=0) const
 
size_type findLastNotOf (const CharacterSet &set, size_type endPos=npos) const
 
void toLower ()
 converts all characters to lower case; More...
 
void toUpper ()
 converts all characters to upper case; More...
 
std::string toStdString () const
 std::string export function More...
 
const_iterator begin () const
 
const_iterator end () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 

Static Public Member Functions

static const SBufStatsGetStats ()
 gets global statistic information More...
 

Public Attributes

const InstanceId< SBufid
 

Static Public Attributes

static const size_type npos = 0xffffffff
 
static const size_type maxSize = 0xfffffff
 Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb. More...
 

Private Member Functions

char * buf () const
 
char * bufEnd () const
 
size_type estimateCapacity (size_type desired) const
 
void reAlloc (size_type newsize)
 
void cow (size_type minsize=npos)
 
void checkAccessBounds (const size_type pos) const
 
char * rawSpace (size_type minSize)
 
SBuflowAppend (const char *memArea, size_type areaSize)
 

Static Private Member Functions

static MemBlob::Pointer GetStorePrototype ()
 

Private Attributes

MemBlob::Pointer store_
 memory block, possibly shared with other SBufs More...
 
size_type off_ = 0
 our content start offset from the beginning of shared store_ More...
 
size_type len_ = 0
 number of our content bytes in shared store_ More...
 

Static Private Attributes

static SBufStats stats
 class-wide statistics More...
 

Friends

class Locker
 

Detailed Description

A String or Buffer. Features: refcounted backing store, cheap copy and sub-stringing operations, copy-on-write to isolate change operations to each instance. Where possible, we're trying to mimic std::string's interface.

Definition at line 93 of file SBuf.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 97 of file SBuf.h.

◆ const_reverse_iterator

Definition at line 98 of file SBuf.h.

◆ size_type

Definition at line 96 of file SBuf.h.

Constructor & Destructor Documentation

◆ SBuf() [1/6]

SBuf::SBuf ( )

Definition at line 28 of file SBuf.cc.

References SBufStats::alloc, debugs, SBufStats::live, and stats.

◆ SBuf() [2/6]

SBuf::SBuf ( const SBuf S)

Definition at line 35 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocCopy, debugs, id, SBufStats::live, and stats.

◆ SBuf() [3/6]

SBuf::SBuf ( SBuf &&  S)
inline

Definition at line 107 of file SBuf.h.

References SBufStats::moves, and stats.

◆ SBuf() [4/6]

SBuf::SBuf ( const char *  S,
size_type  n 
)
explicit

Constructor: import c-style string

Create a new SBuf containing a COPY of the contents of the c-string

Parameters
Sthe c string to be copied
nhow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring
Note
it is the caller's responsibility not to go out of bounds
bounds is 0 <= pos < length(); caller must pay attention to signedness

Definition at line 52 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocFromCString, append(), SBufStats::live, and stats.

◆ SBuf() [5/6]

SBuf::SBuf ( const char *  S)
explicit

Definition at line 60 of file SBuf.cc.

References SBufStats::alloc, SBufStats::allocFromCString, append(), SBufStats::live, npos, and stats.

◆ SBuf() [6/6]

SBuf::SBuf ( const std::string &  s)
explicit

Definition at line 44 of file SBuf.cc.

References SBufStats::alloc, debugs, SBufStats::live, lowAppend(), and stats.

◆ ~SBuf()

SBuf::~SBuf ( )

Definition at line 68 of file SBuf.cc.

References debugs, len_, SBufStats::live, SBufStats::RecordSBufSizeAtDestruct(), and stats.

Member Function Documentation

◆ append() [1/4]

SBuf & SBuf::append ( const char *  S)
inline

Definition at line 208 of file SBuf.h.

References append(), and npos.

Referenced by append().

◆ append() [2/4]

SBuf & SBuf::append ( const char *  S,
size_type  Ssize 
)

Append operation for C-style strings.

Append the supplied c-string to the SBuf; extend storage as needed.

Parameters
Sthe c string to be copied. Can be NULL.
Ssizehow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring. If S is NULL, Ssize is ignored.
Note
to append a std::string use the pattern cstr_append(stdstr.data(), stdstd.length())

Definition at line 195 of file SBuf.cc.

References debugs, lowAppend(), and npos.

◆ append() [3/4]

SBuf & SBuf::append ( const char  c)

Definition at line 208 of file SBuf.cc.

References lowAppend().

◆ append() [4/4]

SBuf & SBuf::append ( const SBuf S)

Append operation

Append the supplied SBuf to the current one; extend storage as needed.

Definition at line 185 of file SBuf.cc.

References buf(), GetStorePrototype(), isEmpty(), length(), lowAppend(), and store_.

Referenced by SBuf(), HttpHeader::addVia(), Adaptation::History::allLogString(), applyTlsDetailsToSSL(), assembleVaryKey(), assign(), AnyP::Uri::authority(), bio_sbuf_puts(), bio_sbuf_write(), clientReplyContext::buildReplyHeader(), Ftp::Gateway::buildTitleUrl(), Auth::User::BuildUserKey(), carpSelectParent(), ErrorState::compile(), ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), MemStore::copyFromShm(), Cp1251ToUtf8(), Security::ServerOptions::createStaticServerContext(), Auth::UserRequest::denyMessageFromHelper(), MessageDelayPool::dump(), AnyP::Uri::Encode(), NotePairs::find(), Ftp::Gateway::ftpRealm(), AccessLogEntry::getLogMethod(), Store::ParsingBuffer::growSpace(), Downloader::handleReply(), Ftp::Gateway::htmlifyListEntry(), httpHeaderQuoteString(), Ssl::InRamCertificateDbKey(), Security::IssuerName(), JoinContainerIntoSBuf(), Latin1ToUtf8(), Fs::Ufs::UFSSwapDir::logFile(), mimeGetIconURL(), Ipc::Mem::Segment::Name(), IcmpConfig::parse(), Notes::parse(), HttpHeaderEntry::parse(), parse_externalAclHelper(), parse_obsolete(), Security::PeerOptions::parseOptions(), parseQuotedStringSuffix(), PidFilenameCalc(), prepareAcceleratedURL(), Kid::processName(), ProcessRoles(), ErrorPageFile::setDefault(), Security::SubjectName(), Ssl::CertValidationHelper::Submit(), Ssl::Helper::Submit(), Adaptation::History::sumLogString(), TestSBuf::testAppendSBuf(), TestSBuf::testAppendStdString(), TestHttp1Parser::testDripFeed(), TestSBuf::testFindSBuf(), TestSBuf::testGrow(), TestHttp1Parser::testParseRequestLineInvalid(), TestHttp1Parser::testParseRequestLineMethods(), TestHttp1Parser::testParseRequestLineProtocols(), TestHttp1Parser::testParseRequestLineStrange(), TestHttp1Parser::testParseRequestLineTerminators(), TestCacheManager::testParseUrl(), TestSBuf::testRawContent(), TestSBuf::testReserve(), Notes::toString(), tunnelStartShoveling(), Security::PeerOptions::updateTlsVersionLimits(), Ftp::UrlWith2f(), and Fs::Ufs::UFSSwapDir::writeCleanStart().

◆ appendf()

◆ assign() [1/3]

SBuf & SBuf::assign ( const char *  S)
inline

Definition at line 170 of file SBuf.h.

References assign(), and npos.

Referenced by assign().

◆ assign() [2/3]

SBuf & SBuf::assign ( const char *  S,
size_type  n 
)

Import a c-string into a SBuf, copying the data.

It is the caller's duty to free the imported string, if needed.

Parameters
Sthe c string to be copied
nhow many bytes to import into the SBuf. If it is npos or unspecified, imports to end-of-cstring
Note
it is the caller's responsibility not to go out of bounds
to assign a std::string use the pattern: assign(stdstr.data(), stdstd.length())

Definition at line 96 of file SBuf.cc.

References append(), clear(), and debugs.

◆ assign() [3/3]

◆ at()

char SBuf::at ( size_type  pos) const
inline

random-access read to any char within the SBuf.

Exceptions
std::exceptionwhen access is out of bounds
Note
bounds is 0 <= pos < length(); caller must pay attention to signedness

Definition at line 249 of file SBuf.h.

References checkAccessBounds(), and operator[]().

Referenced by TestSBuf::testSubscriptOpFail(), and uriParseScheme().

◆ begin()

const_iterator SBuf::begin ( ) const
inline

Definition at line 583 of file SBuf.h.

Referenced by compileREs(), AnyP::Uri::parseUrn(), and TestSBuf::testIterators().

◆ buf()

char * SBuf::buf ( ) const
inlineprivate

obtains a char* to the beginning of this SBuf in memory.

Note
the obtained string is NOT null-terminated.

Definition at line 645 of file SBuf.h.

References MemBlob::mem, off_, and store_.

Referenced by append(), c_str(), compare(), copy(), dump(), find(), findFirstNotOf(), findFirstOf(), findLastNotOf(), findLastOf(), operator==(), print(), Printf(), rawContent(), reAlloc(), rfind(), toStdString(), trim(), and vappendf().

◆ bufEnd()

char * SBuf::bufEnd ( ) const
inlineprivate

returns the pointer to the first char after this SBuf end

No checks are made that the space returned is safe, checking that is up to the caller.

Definition at line 652 of file SBuf.h.

References len_, MemBlob::mem, off_, and store_.

Referenced by findFirstNotOf(), findFirstOf(), rawAppendFinish(), rawSpace(), and trim().

◆ c_str()

const char * SBuf::c_str ( )

exports a null-terminated reference to the SBuf internal storage.

Warning
ACCESSING RAW STORAGE IS DANGEROUS! DO NOT EVER USE THE RETURNED POINTER FOR WRITING

The returned value points to an internal location whose contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the SBuf object. Such a call may be implicit (e.g., when SBuf is destroyed upon leaving the current context). This is a very UNSAFE way of accessing the data. This call never returns NULL.

See also
rawContent
Note
the memory management system guarantees that the exported region of memory will remain valid will remain valid only if the caller keeps holding a valid reference to the SBuf object and does not write or append to it

Definition at line 516 of file SBuf.cc.

References buf(), SBufStats::nulTerminate, SBufStats::rawAccess, rawSpace(), SBufStats::setChar, MemBlob::size, stats, and store_.

Referenced by Security::KeyLog::KeyLog(), RegexPattern::RegexPattern(), Ssl::ServerBump::ServerBump(), Note::Value::Value(), Adaptation::Ecap::HeaderRep::add(), Ftp::Gateway::appendSuccessHeader(), applyTlsDetailsToSSL(), asnAddNet(), asnCacheStart(), Format::Format::assemble(), ConnStateData::buildFakeRequest(), clientReplyContext::buildReplyHeader(), Downloader::buildRequest(), ConnStateData::buildSslCertGenerationParams(), Fs::Ufs::UFSSwapDir::closeTmpSwapLog(), ConfigureCurrentKid(), constructHelperQuery(), Ipc::Port::CoordinatorAddr(), MemStore::copyFromShm(), copyOneHeaderFromClientsideRequestToUpstreamRequest(), Ftp::Relay::createHttpReply(), Auth::UserRequest::denyMessageFromHelper(), Fs::Ufs::UFSSwapDir::DirClean(), DiskerOpen(), ClientHttpRequest::doCallouts(), MessageDelayPool::dump(), Auth::SchemesConfig::expand(), ProxyProtocol::One::ExtractIp(), FileRename(), HeaderManglers::find(), Ftp::Gateway::ftpAuthRequired(), ftpSendType(), ConnStateData::handleRequestBodyData(), htcpClear(), Ftp::Gateway::htmlifyListEntry(), HttpStateData::httpBuildRequestHeader(), Acl::TypedOption< Recipient >::import(), Ipc::StoreMap::Init(), Ssl::InitClientContext(), Ssl::IcapPeerConnector::initialize(), Security::BlindPeerConnector::initialize(), Ssl::PeekingPeerConnector::initialize(), MimeIcon::load(), Security::KeyData::loadCertificates(), logfilePrintf(), Ftp::Gateway::loginFailed(), Ipc::Port::MakeAddr(), Acl::ServerNameCheck::match(), ACLCertificateData::match(), Client::maybePurgeOthers(), mimeGetIconURL(), IcmpSquid::Open(), File::open(), Fs::Ufs::UFSSwapDir::openLog(), Fs::Ufs::UFSSwapDir::openTmpSwapLog(), Store::PackFields(), ESIContext::parse(), Notes::parse(), parse_externalAclHelper(), parse_obsolete(), ParseAclWithAction(), Http::Message::parseHeader(), AnyP::Uri::parseHost(), Ftp::Server::parseOneRequest(), Security::PeerOptions::parseOptions(), AnyP::Uri::parseUrn(), CommonNamesPrinter::printName(), ProcessMacros(), clientReplyContext::purgeAllCached(), clientReplyContext::purgeDoPurge(), purgeEntriesByHeader(), refreshCheck(), RemoveInstance(), Ftp::Relay::sendCommand(), HappyConnOpener::status(), Ssl::CertValidationHelper::Submit(), Ssl::Helper::Submit(), TestSBuf::testComparisons(), TestSBuf::testFindFirstNotOf(), TestSBuf::testReserve(), Notes::toString(), NotePairs::toString(), HttpHeader::updateOrAddStr(), uriParseScheme(), urnParseReply(), Adaptation::Ecap::ServiceRep::wantsUrl(), watch_child(), WIN32_InstallService(), WIN32_RemoveService(), WIN32_sendSignal(), WIN32_SetServiceCommandLine(), WIN32_StartService(), WIN32_Subsystem_Init(), UFSCleanLog::write(), Fs::Ufs::UFSSwapDir::writeCleanDone(), and Fs::Ufs::UFSSwapDir::writeCleanStart().

◆ caseCmp() [1/4]

int SBuf::caseCmp ( const char *  S) const
inline

Definition at line 308 of file SBuf.h.

References caseInsensitive, compare(), and npos.

◆ caseCmp() [2/4]

int SBuf::caseCmp ( const char *  S,
const size_type  n 
) const
inline

Definition at line 305 of file SBuf.h.

References caseInsensitive, and compare().

◆ caseCmp() [3/4]

int SBuf::caseCmp ( const SBuf S) const
inline

Definition at line 286 of file SBuf.h.

References caseInsensitive, compare(), and npos.

◆ caseCmp() [4/4]

◆ checkAccessBounds()

void SBuf::checkAccessBounds ( const size_type  pos) const
inlineprivate

Definition at line 664 of file SBuf.h.

References length(), and Must.

Referenced by at(), and setAt().

◆ chop()

SBuf & SBuf::chop ( size_type  pos,
size_type  n = npos 
)

slicing method

Removes SBuf prefix and suffix, leaving a sequence of 'n' bytes starting from position 'pos', first byte is at pos 0. It is an in-place-modifying version of substr.

Parameters
posstart sub-stringing from this byte. If it is npos or it is greater than the SBuf length, the SBuf is cleared and an empty SBuf is returned.
nmaximum number of bytes of the resulting SBuf. npos means "to end of SBuf". if it is 0, the SBuf is cleared and an empty SBuf is returned. if it overflows the end of the SBuf, it is capped to the end of SBuf
See also
substr, trim

Definition at line 530 of file SBuf.cc.

References SBufStats::chop, clear(), len_, length(), npos, off_, and stats.

Referenced by consume(), Http::One::Parser::getHostHeaderField(), Ftp::Server::handleUserRequest(), prepareAcceleratedURL(), substr(), TestSBuf::testChop(), TestSBuf::testCopy(), HttpStateData::truncateVirginBody(), and Security::PeerOptions::updateTlsVersionLimits().

◆ clear()

◆ cmp() [1/4]

int SBuf::cmp ( const char *  S) const
inline

Definition at line 300 of file SBuf.h.

References caseSensitive, compare(), and npos.

◆ cmp() [2/4]

int SBuf::cmp ( const char *  S,
const size_type  n 
) const
inline

Definition at line 297 of file SBuf.h.

References caseSensitive, and compare().

◆ cmp() [3/4]

int SBuf::cmp ( const SBuf S) const
inline

Definition at line 278 of file SBuf.h.

References caseSensitive, compare(), and npos.

◆ cmp() [4/4]

◆ compare() [1/4]

int SBuf::compare ( const char *  s,
const SBufCaseSensitive  isCaseSensitive 
) const
inline

Definition at line 292 of file SBuf.h.

References compare(), and npos.

◆ compare() [2/4]

int SBuf::compare ( const char *  s,
const SBufCaseSensitive  isCaseSensitive,
const size_type  n 
) const

◆ compare() [3/4]

int SBuf::compare ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive 
) const
inline

Definition at line 270 of file SBuf.h.

References compare(), and npos.

◆ compare() [4/4]

int SBuf::compare ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive,
const size_type  n 
) const

compare to other SBuf, str(case)cmp-style

Parameters
isCaseSensitiveone of caseSensitive or caseInsensitive
ncompare up to this many bytes. if npos (default), compare whole SBufs
Return values
>0argument of the call is greater than called SBuf
<0argument of the call is smaller than called SBuf
0argument of the call has the same contents of called SBuf

Definition at line 352 of file SBuf.cc.

References buf(), caseSensitive, compare(), SBufStats::compareSlow, debugs, length(), memcasecmp(), min(), npos, stats, and substr().

Referenced by caseCmp(), cmp(), compare(), SBufEqual::operator()(), CaseInsensitiveSBufEqual::operator()(), startsWith(), and TestSBuf::testStringOps().

◆ consume()

SBuf SBuf::consume ( size_type  n = npos)

Consume bytes at the head of the SBuf

Consume N chars at SBuf head, or to SBuf's end, whichever is shorter. If more bytes are consumed than available, the SBuf is emptied

Parameters
nhow many bytes to remove; could be zero. npos (or no argument) means 'to the end of SBuf'
Returns
a new SBuf containing the consumed bytes.

Definition at line 481 of file SBuf.cc.

References chop(), debugs, length(), min(), npos, and substr().

Referenced by Parser::Tokenizer::consume(), ConnStateData::consumeInput(), Parser::Tokenizer::consumeTrailing(), TunnelStateData::copyClientBytes(), TunnelStateData::copyServerBytes(), Http::One::Parser::getHostHeaderField(), ConnStateData::parseProxyProtocolHeader(), Parser::Tokenizer::suffix(), TestSBuf::testReserve(), tunnelStartShoveling(), and HttpStateData::writeReplyBody().

◆ copy()

SBuf::size_type SBuf::copy ( char *  dest,
size_type  n 
) const

Copy SBuf contents into user-supplied C buffer.

Export a copy of the SBuf's contents into the user-supplied buffer, up to the user-supplied-length. No zero-termination is performed

Returns
num the number of actually-copied chars.

Definition at line 500 of file SBuf.cc.

References buf(), SBufStats::copyOut, length(), min(), and stats.

Referenced by Ftp::Gateway::loginParser(), and SBufToCstring().

◆ cow()

void SBuf::cow ( SBuf::size_type  newsize = npos)
private

copy-on-write: make sure that we are the only holder of the backing store. If not, reallocate. If a new size is specified, and it is greater than the current length, the backing store will be extended as needed

Definition at line 878 of file SBuf.cc.

References assert, MemBlob::consume(), SBufStats::cowAvoided, SBufStats::cowShift, debugs, length(), npos, off_, reAlloc(), spaceSize(), stats, store_, and MemBlob::syncSize().

Referenced by rawSpace(), reserveCapacity(), and setAt().

◆ dump()

std::ostream & SBuf::dump ( std::ostream &  os) const

print SBuf contents and debug information about the SBuf to an ostream

Debug function, dumps to a stream information on the current SBuf, including low-level details and statistics.

Definition at line 303 of file SBuf.cc.

References buf(), MemBlob::dump(), len_, length(), off_, print(), and store_.

◆ end()

const_iterator SBuf::end ( ) const
inline

Definition at line 587 of file SBuf.h.

References length().

Referenced by TestSBuf::testIterators(), and Acl::Tree::treeDump().

◆ estimateCapacity()

size_type SBuf::estimateCapacity ( size_type  desired) const
inlineprivate

Try to guesstimate how big a MemBlob to allocate. The result is guaranteed to be to be at least the desired size.

Definition at line 658 of file SBuf.h.

◆ find() [1/2]

SBuf::size_type SBuf::find ( char  c,
size_type  startPos = 0 
) const

Find first occurrence of character in SBuf

Returns the index in the SBuf of the first occurrence of char c.

Returns
npos if the char was not found
Parameters
startPosif specified, ignore any occurrences before that position if startPos is npos or greater than length() npos is always returned if startPos is less than zero, it is ignored

Definition at line 584 of file SBuf.cc.

References buf(), SBufStats::find, length(), npos, and stats.

Referenced by asnAddNet(), EssentialVersion(), find(), Ftp::Gateway::loginParser(), AnyP::Uri::parseHost(), clientReplyContext::purgeDoPurge(), and TestSBuf::testFindSBuf().

◆ find() [2/2]

SBuf::size_type SBuf::find ( const SBuf str,
size_type  startPos = 0 
) const

Find first occurrence of SBuf in SBuf.

Returns the index in the SBuf of the first occurrence of the sequence contained in the str argument.

Parameters
startPosif specified, ignore any occurrences before that position if startPos is npos or greater than length() npos is always returned
Returns
npos if the SBuf was not found

Definition at line 604 of file SBuf.cc.

References buf(), debugs, find(), SBufStats::find, length(), npos, and stats.

◆ findFirstNotOf()

SBuf::size_type SBuf::findFirstNotOf ( const CharacterSet set,
size_type  startPos = 0 
) const

Find first occurrence character NOT in character set

Returns
npos if all characters in the SBuf are from set
Parameters
startPosif specified, ignore any occurrences before that position if npos, then npos is always returned

TODO: rename to camelCase

Definition at line 746 of file SBuf.cc.

References buf(), bufEnd(), cur, debugs, SBufStats::find, length(), CharacterSet::name, npos, and stats.

Referenced by Http::One::Parser::getHostHeaderField(), IgnorePlaceholder(), TestSBuf::testFindFirstNotOf(), and Notes::validateKey().

◆ findFirstOf()

SBuf::size_type SBuf::findFirstOf ( const CharacterSet set,
size_type  startPos = 0 
) const

Find first occurrence of character of set in SBuf

Finds the first occurrence of ANY of the characters in the supplied set in the SBuf.

Returns
npos if no character in the set could be found
Parameters
startPosif specified, ignore any occurrences before that position if npos, then npos is always returned

TODO: rename to camelCase

Definition at line 723 of file SBuf.cc.

References buf(), bufEnd(), cur, debugs, SBufStats::find, length(), CharacterSet::name, npos, and stats.

Referenced by TestSBuf::testFindFirstOf().

◆ findLastNotOf()

SBuf::size_type SBuf::findLastNotOf ( const CharacterSet set,
size_type  endPos = npos 
) const

Find last occurrence character NOT in character set

Returns
npos if all characters in the SBuf are from set
Parameters
endPosif specified, ignore any occurrences after that position if npos, then the entire SBuf is searched

Definition at line 790 of file SBuf.cc.

References buf(), cur, debugs, SBufStats::find, isEmpty(), length(), CharacterSet::name, npos, and stats.

◆ findLastOf()

SBuf::size_type SBuf::findLastOf ( const CharacterSet set,
size_type  endPos = npos 
) const

Find last occurrence of character of set in SBuf

Finds the last occurrence of ANY of the characters in the supplied set in the SBuf.

Returns
npos if no character in the set could be found
Parameters
endPosif specified, ignore any occurrences after that position if npos, the entire SBuf is searched

Definition at line 769 of file SBuf.cc.

References buf(), cur, debugs, SBufStats::find, isEmpty(), length(), CharacterSet::name, npos, and stats.

Referenced by TestTokenizer::testTokenizerSuffix().

◆ GetStats()

const SBufStats & SBuf::GetStats ( )
static

Definition at line 494 of file SBuf.cc.

References stats.

Referenced by SBufStatsAction::collect(), TestSBuf::testDumpStats(), and TestSBuf::testReserve().

◆ GetStorePrototype()

MemBlob::Pointer SBuf::GetStorePrototype ( )
staticprivate

obtain prototype store

Just-created SBufs all share to the same MemBlob. This call instantiates and returns it.

Definition at line 76 of file SBuf.cc.

Referenced by append().

◆ isEmpty()

bool SBuf::isEmpty ( ) const
inline

Check whether the SBuf is empty

Returns
true if length() == 0

Definition at line 431 of file SBuf.h.

References len_.

Referenced by HttpRequestMethod::HttpRequestMethod(), accessLogLogTo(), HttpHeader::addVia(), StoreEntry::adjustVary(), Adaptation::History::allLogString(), append(), AppendTokens(), applyTlsDetailsToSSL(), Format::Format::assemble(), assembleVaryKey(), Parser::Tokenizer::atEnd(), ConnStateData::buildSslCertGenerationParams(), cacheDigestGuessStatsReport(), carpSelectParent(), ConnStateData::checkLogging(), Helper::Reply::CheckReceivedKey(), configDoConfigure(), AccessLogEntry::detailCodeContext(), Server::doClientRead(), ACL::dumpOptions(), AccessLogEntry::effectiveVirginUrl(), ACLHTTPHeaderData::empty(), ACLNoteData::empty(), AnyP::Uri::Encode(), Auth::SchemesConfig::expand(), ConnStateData::fakeAConnectRequest(), Ssl::IcapPeerConnector::fillChecklist(), NotePairs::find(), findLastNotOf(), findLastOf(), AnyP::UriScheme::FindProtocolType(), ConnStateData::getSslContextStart(), ProxyProtocol::Header::getValues(), ConnStateData::handleChunkedRequestBody(), Ftp::Server::handleUserRequest(), HttpStateData::haveParsedReplyHeaders(), HttpRequestMethod::image(), Ssl::InitClientContext(), Security::BlindPeerConnector::initialize(), ConnStateData::initiateTunneledRequest(), internalRemoteUri(), Security::CommunicationSecrets::learnNew(), Ftp::Gateway::loginParser(), Acl::ServerNameCheck::match(), ACLStringData::match(), ACLCertificateData::match(), mimeGetIconURL(), operator<<(), ACLCertificateData::parse(), Security::HandshakeParser::parseExtensions(), ConnStateData::parseHttpRequest(), Ftp::Server::parseOneRequest(), Security::PeerOptions::parseOptions(), parsePortCfg(), ConnStateData::parseRequests(), MessageDelayConfig::parseResponseDelayPool(), Security::HandshakeParser::parseSniExtension(), ConnStateData::parseTlsHandshake(), prepareAcceleratedURL(), ConnStateData::prepareTlsSwitchingURL(), ErrorPage::BuildErrorPrinter::printLocation(), PrintSecret(), clientReplyContext::processExpired(), clientReplyContext::purgeDoPurge(), HttpStateData::readReply(), RemoveInstance(), Acl::SetKey(), MemStore::shouldCache(), ConnStateData::shouldCloseOnEof(), Parser::Tokenizer::skipRequired(), Log::Format::SquidReferer(), ConnStateData::sslCrtdHandleReply(), MemObject::stat(), storeKeyPublicByRequestMethod(), Adaptation::History::sumLogString(), ACLFilledChecklist::syncAle(), ConnStateData::terminateAll(), TestHttp1Parser::testParserConstruct(), TestTokenizer::testTokenizerInt64(), Notes::toString(), NotePairs::toString(), trim(), FwdState::tunnelEstablishmentDone(), tunnelStartShoveling(), Store::UnpackHitSwapMeta(), Adaptation::Ecap::RequestLineRep::uri(), vAinB(), varyEvaluateMatch(), ACLFilledChecklist::verifyAle(), WIN32_InstallService(), WIN32_RemoveService(), WIN32_sendSignal(), and WIN32_SetServiceCommandLine().

◆ length()

size_type SBuf::length ( ) const
inline

Definition at line 415 of file SBuf.h.

References len_.

Referenced by SBufSubstrAutoTest::SBufSubstrAutoTest(), ConnStateData::abortRequestParsing(), HttpHeader::addEntry(), append(), bio_sbuf_puts(), Ftp::Gateway::buildTitleUrl(), buildUrlFromHost(), carpSelectParent(), Security::PeerConnector::certDownloadingDone(), checkAccessBounds(), ConnStateData::checkLogging(), Ftp::Gateway::checkUrlpath(), chop(), compare(), ErrorState::compile(), ErrorState::compileLegacyCode(), ErrorState::compileLogformatCode(), Parser::Tokenizer::consume(), consume(), ConnStateData::consumeInput(), HttpBody::contentSize(), HttpStateData::continueAfterParsingHeader(), copy(), TunnelStateData::copyClientBytes(), MemStore::copyFromShm(), TunnelStateData::copyServerBytes(), cow(), HttpHeader::delAt(), Http::One::RequestParser::doParse(), dump(), AnyP::Uri::Encode(), end(), FileRename(), find(), NotePairs::find(), findFirstNotOf(), findFirstOf(), findLastNotOf(), findLastOf(), Http::One::RequestParser::firstLineSize(), Http::One::ResponseParser::firstLineSize(), Parser::BinaryTokenizer::got(), ConnStateData::handleChunkedRequestBody(), Downloader::handleReply(), ConnStateData::handleRequestBodyData(), Ftp::Server::handleUserRequest(), HttpBody::hasContent(), HttpHeader::hasNamed(), Http::One::Parser::headerBlockSize(), headersEnd(), DelayTagged::id(), Parser::Tokenizer::int64(), internalRemoteUri(), RegexPattern::isDot(), JoinContainerIntoSBuf(), HttpHeaderEntry::length(), logfilePrintf(), Ftp::Gateway::loginParser(), Http::HeaderLookupTable_t::lookup(), mainHandleCommandLineOption(), Adaptation::Icap::ModXact::makeRequestHeaders(), Adaptation::Icap::Options::TransferList::matches(), HttpStateData::maybeMakeSpaceAvailable(), ConnStateData::mayNeedToReadMoreBody(), CaseInsensitiveSBufEqual::operator()(), SBufAddLength::operator()(), Http::operator<<(), operator<<(), operator==(), Store::PackFields(), HttpHeaderEntry::packInto(), HttpHeader::packInto(), AnyP::Uri::parse(), ProxyProtocol::Parse(), Http::One::TeChunkedParser::parse(), Http::One::RequestParser::parse(), Http::One::ResponseParser::parse(), ProxyProtocol::One::Parse(), parse_externalAclHelper(), Security::HandshakeParser::parseCiphers(), Security::HandshakeParser::parseCompressionMethods(), Security::HandshakeParser::parseHandshakeMessage(), ConnStateData::parseHttpRequest(), Http::One::RequestParser::parseHttpVersionField(), Security::HandshakeParser::parseModernRecord(), Ftp::Server::parseOneRequest(), ConnStateData::parseProxyProtocolHeader(), ConnStateData::parseRequests(), Http::One::RequestParser::parseUriField(), AnyP::Uri::parseUrn(), plength(), HttpRequest::prefixLen(), prepareAcceleratedURL(), ConnStateData::prepareTlsSwitchingURL(), print(), PrintSecret(), HttpStateData::processReplyHeader(), rawAppendFinish(), rawSpace(), rbegin(), File::readSmall(), Server::readSomeData(), reAlloc(), reserveSpace(), rfind(), SBufToCstring(), SBufToString(), Parser::Tokenizer::skip(), Parser::Tokenizer::skipSuffix(), startsWith(), ConnStateData::stopSending(), storeKeyPublicByRequestMethod(), strListAdd(), ConnStateData::terminateAll(), TestSBuf::testChop(), TestSBuf::testComparisons(), TestHttp1Parser::testDripFeed(), TestSBuf::testFindFirstNotOf(), TestSBuf::testFindFirstOf(), TestHttp1Parser::testParseRequestLineInvalid(), TestHttp1Parser::testParseRequestLineMethods(), TestHttp1Parser::testParseRequestLineProtocols(), TestHttp1Parser::testParseRequestLineStrange(), TestHttp1Parser::testParseRequestLineTerminators(), TestSBuf::testReserve(), testResults(), TestSBuf::testSBufLength(), TestSBuf::testSubscriptOpFail(), TestTokenizer::testTokenizerInt64(), TestTokenizer::testTokenizerSuffix(), toLower(), toStdString(), Note::toString(), toUpper(), trim(), HttpStateData::truncateVirginBody(), FwdState::tunnelEstablishmentDone(), Store::UnpackSwapMetaSize(), HttpHeader::updateOrAddStr(), Adaptation::Ecap::RequestLineRep::uri(), urnHandleReply(), ShmWriter::vappendf(), File::writeAll(), and HttpStateData::writeReplyBody().

◆ lowAppend()

SBuf & SBuf::lowAppend ( const char *  memArea,
size_type  areaSize 
)
private

Low-level append operation

Takes as input a contiguous area of memory and appends its contents to the SBuf, taking care of memory management. Does no bounds checking on the supplied memory buffer, it is the duty of the caller to ensure that the supplied area is valid.

Definition at line 863 of file SBuf.cc.

References MemBlob::append(), SBufStats::append, len_, rawSpace(), stats, and store_.

Referenced by SBuf(), and append().

◆ operator!=()

bool SBuf::operator!= ( const SBuf S) const

Definition at line 475 of file SBuf.cc.

◆ operator<()

bool SBuf::operator< ( const SBuf S) const
inline

Definition at line 321 of file SBuf.h.

References cmp().

◆ operator<=()

bool SBuf::operator<= ( const SBuf S) const
inline

Definition at line 323 of file SBuf.h.

References cmp().

◆ operator=() [1/3]

SBuf & SBuf::operator= ( const char *  S)
inline

Assignment operator. Copy a NULL-terminated c-style string into a SBuf.

Copy a c-style string into a SBuf. Shortcut for SBuf.assign(S) It is the caller's duty to free the imported string, if needed.

Note
not \0-clean

Definition at line 178 of file SBuf.h.

References assign().

◆ operator=() [2/3]

SBuf & SBuf::operator= ( const SBuf S)
inline

Assignment operator.

Current SBuf will share backing store with the assigned one.

Definition at line 141 of file SBuf.h.

References assign().

◆ operator=() [3/3]

SBuf & SBuf::operator= ( SBuf &&  S)
inline

Definition at line 142 of file SBuf.h.

References len_, SBufStats::moves, off_, stats, and store_.

◆ operator==()

bool SBuf::operator== ( const SBuf S) const

Definition at line 455 of file SBuf.cc.

References buf(), SBufStats::compareFast, SBufStats::compareSlow, debugs, id, length(), off_, stats, and store_.

◆ operator>()

bool SBuf::operator> ( const SBuf S) const
inline

Definition at line 322 of file SBuf.h.

References cmp().

◆ operator>=()

bool SBuf::operator>= ( const SBuf S) const
inline

Definition at line 324 of file SBuf.h.

References cmp().

◆ operator[]()

char SBuf::operator[] ( size_type  pos) const
inline

random-access read to any char within the SBuf

does not check access bounds. If you need that, use at()

Definition at line 242 of file SBuf.h.

References SBufStats::getChar, MemBlob::mem, off_, stats, and store_.

Referenced by at().

◆ plength()

int SBuf::plength ( ) const
inline

Get the length of the SBuf, as a signed integer

Compatibility function for printf(3) which requires a signed int

Exceptions
std::exceptionif buffer length does not fit a signed integer

Definition at line 422 of file SBuf.h.

References INT_MAX, length(), and Must.

Referenced by strListIsMember(), and HttpHeader::updateOrAddStr().

◆ print()

std::ostream & SBuf::print ( std::ostream &  os) const

Definition at line 295 of file SBuf.cc.

References buf(), length(), stats, and SBufStats::toStream.

Referenced by dump(), and operator<<().

◆ Printf()

SBuf & SBuf::Printf ( const char *  fmt,
  ... 
)

Assignment operation with printf(3)-style definition

Note
arguments may be evaluated more than once, be careful of side-effects

Definition at line 214 of file SBuf.cc.

References buf(), clear(), and vappendf().

Referenced by Note::Value::Value(), Auth::User::BuildUserKey(), ACLASN::dump(), ACLMaxConnection::dump(), ACLTimeData::dump(), ACLMaxUserIP::dump(), ACLExternal::dump(), CommandLine::nextOption(), ParseAclWithAction(), Ftp::Relay::sendCommand(), acl_httpstatus_data::toStr(), and Instance::WriteOurPid().

◆ rawAppendFinish()

void SBuf::rawAppendFinish ( const char *  start,
size_type  actualSize 
)

Updates SBuf metadata to reflect appending actualSize bytes to the buffer returned by the corresponding rawAppendStart() call. Throws if rawAppendStart(actualSize) would have returned a different value now.

Parameters
startraw buffer previously returned by rawAppendStart()
actualSizethe number of appended bytes

Definition at line 144 of file SBuf.cc.

References bufEnd(), MemBlob::canAppend(), MemBlob::capacity, debugs, Here, len_, length(), maxSize, min(), Must, Must3, off_, MemBlob::size, and store_.

Referenced by HttpHeader::getAuthToken(), Comm::ReadNow(), File::readSmall(), and TestSBuf::testRawSpace().

◆ rawAppendStart()

char * SBuf::rawAppendStart ( size_type  anticipatedSize)
Returns
a buffer suitable for appending at most anticipatedSize bytes The buffer must be used "immediately" because it is invalidated by most non-constant SBuf method calls, including such calls against other SBuf objects that just happen to share the same underlying MemBlob storage!

Definition at line 136 of file SBuf.cc.

References debugs, and rawSpace().

Referenced by HttpHeader::getAuthToken(), Comm::ReadNow(), File::readSmall(), and TestSBuf::testRawSpace().

◆ rawContent()

const char * SBuf::rawContent ( ) const

exports a pointer to the SBuf internal storage.

Warning
ACCESSING RAW STORAGE IS DANGEROUS!

Returns a ead-only pointer to SBuf's content. No terminating null character is appended (use c_str() for that). The returned value points to an internal location whose contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the SBuf object. Such a call may be implicit (e.g., when SBuf is destroyed upon leaving the current context). This is a very UNSAFE way of accessing the data. This call never returns NULL.

See also
c_str
Note
the memory management system guarantees that the exported region of memory will remain valid if the caller keeps holding a valid reference to the SBuf object and does not write or append to it. For example:
SBuf foo("some string");
const char *bar = foo.rawContent();
doSomething(bar); //safe
foo.append(" other string");
doSomething(bar); //unsafe
Definition: SBuf.h:94

Definition at line 509 of file SBuf.cc.

References buf(), SBufStats::rawAccess, and stats.

Referenced by Ftp::Gateway::buildTitleUrl(), carpSelectParent(), Security::PeerConnector::certDownloadingDone(), ErrorState::compileLegacyCode(), HttpBody::content(), TunnelStateData::copyClientBytes(), TunnelStateData::copyServerBytes(), FileRename(), Parser::BinaryTokenizer::got(), HttpHeader::hasNamed(), headersEnd(), Parser::Tokenizer::int64(), internalRemoteUri(), Http::HeaderLookupTable_t::lookup(), Adaptation::Icap::ModXact::makeRequestHeaders(), HttpHeaderEntry::packInto(), HttpHeader::packInto(), AnyP::Uri::parse(), Http::One::RequestParser::parseHttpVersionField(), PrintSecret(), SBufToString(), storeKeyPublicByRequestMethod(), strListAdd(), TestSBuf::testAppendSBuf(), TestSBuf::testAppendStdString(), TestSBuf::testComparisons(), TestSBuf::testGrow(), TestSBuf::testReserve(), TestSBuf::testSBufConstructDestruct(), Store::UnpackSwapMetaSize(), HttpHeader::updateOrAddStr(), Adaptation::Ecap::RequestLineRep::uri(), ShmWriter::vappendf(), File::writeAll(), and HttpStateData::writeReplyBody().

◆ rawSpace()

char * SBuf::rawSpace ( size_type  minSize)
private

Exports a writable pointer to the SBuf internal storage.

Warning
Use with EXTREME caution, this is a dangerous operation.

Returns a pointer to the first unused byte in the SBuf's storage, which can be be used for appending. At least minSize bytes will be available for writing. The returned pointer must not be stored by the caller, as it will be invalidated by the first call to a non-const method call on the SBuf. This call guarantees to never return nullptr.

See also
reserveSpace
Note
Unlike reserveSpace(), this method does not guarantee exclusive buffer ownership. It is instead optimized for a one writer (appender), many readers scenario by avoiding unnecessary copying and allocations.
Exceptions
std::exceptionif the user tries to allocate a too big SBuf

Definition at line 157 of file SBuf.cc.

References bufEnd(), MemBlob::canAppend(), cow(), debugs, len_, length(), maxSize, Must, off_, SBufStats::rawAccess, stats, and store_.

Referenced by c_str(), lowAppend(), rawAppendStart(), and vappendf().

◆ rbegin()

◆ reAlloc()

void SBuf::reAlloc ( size_type  newsize)
private

re-allocate the backing store of the SBuf.

If there are contents in the SBuf, they will be copied over. NO verifications are made on the size parameters, it's up to the caller to make sure that the new size is big enough to hold the copied contents. The re-allocated storage MAY be bigger than the requested size due to size-chunking algorithms in MemBlock, it is guaranteed NOT to be smaller.

Definition at line 845 of file SBuf.cc.

References MemBlob::append(), buf(), MemBlob::capacity, SBufStats::cowAllocCopy, SBufStats::cowJustAlloc, debugs, length(), maxSize, Must, off_, stats, and store_.

Referenced by cow().

◆ rend()

const_reverse_iterator SBuf::rend ( ) const
inline

Definition at line 595 of file SBuf.h.

Referenced by Parser::Tokenizer::suffix(), and TestSBuf::testIterators().

◆ reserve()

◆ reserveCapacity()

void SBuf::reserveCapacity ( size_type  minCapacity)

Request to guarantee the SBuf's store capacity

After this method is called, the SBuf is guaranteed to have at least minCapacity bytes of total buffer size, including the currently-used portion; it is also guaranteed that after this call this SBuf has unique ownership of the underlying memory store.

Exceptions
std::exceptionif the user tries to allocate a too big SBuf

Definition at line 105 of file SBuf.cc.

References cow(), maxSize, and Must.

Referenced by AnyP::Uri::absolute(), Store::ParsingBuffer::growSpace(), reserve(), reserveSpace(), TestSBuf::testGrow(), and TestSBuf::testReserve().

◆ reserveSpace()

void SBuf::reserveSpace ( size_type  minSpace)
inline

Request to guarantee the SBuf's free store space.

After the reserveSpace request, the SBuf is guaranteed to have at least minSpace bytes of unused backing store following the currently used portion and single ownership of the backing store.

Exceptions
std::exceptionif the user tries to allocate a too big SBuf

Definition at line 440 of file SBuf.h.

References length(), maxSize, Must, and reserveCapacity().

Referenced by AnyP::Uri::Encode(), HttpStateData::maybeMakeSpaceAvailable(), and TestSBuf::testReserve().

◆ rfind() [1/2]

SBuf::size_type SBuf::rfind ( char  c,
SBuf::size_type  endPos = npos 
) const

Find last occurrence of character in SBuf

Returns the index in the SBuf of the last occurrence of char c.

Returns
npos if the char was not found
Parameters
endPosif specified, ignore any occurrences after that position. if npos or greater than length(), the whole SBuf is considered

Definition at line 692 of file SBuf.cc.

References buf(), SBufStats::find, length(), memrchr(), npos, and stats.

Referenced by Ftp::Gateway::appendSuccessHeader(), Ftp::Server::handleUserRequest(), prepareAcceleratedURL(), rfind(), TestSBuf::testFindSBuf(), and TestSBuf::testRFindSBuf().

◆ rfind() [2/2]

SBuf::size_type SBuf::rfind ( const SBuf str,
SBuf::size_type  endPos = npos 
) const

Find last occurrence of SBuf in SBuf

Returns the index in the SBuf of the last occurrence of the sequence contained in the str argument.

Returns
npos if the sequence was not found
Parameters
endPosif specified, ignore any occurrences after that position if npos or greater than length(), the whole SBuf is considered

Definition at line 656 of file SBuf.cc.

References buf(), cur, SBufStats::find, length(), npos, rfind(), and stats.

◆ setAt()

void SBuf::setAt ( size_type  pos,
char  toset 
)

direct-access set a byte at a specified operation.

Parameters
posthe position to be overwritten
tosetthe value to be written
Exceptions
std::exceptionwhen pos is of bounds
Note
bounds is 0 <= pos < length(); caller must pay attention to signedness
performs a copy-on-write if needed.

Definition at line 328 of file SBuf.cc.

References checkAccessBounds(), cow(), MemBlob::mem, off_, SBufStats::setChar, stats, and store_.

Referenced by TestSBuf::testComparisons(), TestSBuf::testSubscriptOp(), toLower(), and toUpper().

◆ spaceSize()

size_type SBuf::spaceSize ( ) const
inline

Obtain how much free space is available in the backing store.

Note
: unless the client just cow()ed, it is not guaranteed that the free space can be used.

Definition at line 393 of file SBuf.h.

References MemBlob::spaceSize(), and store_.

Referenced by cow(), Server::maybeMakeSpaceAvailable(), HttpStateData::maybeMakeSpaceAvailable(), Comm::ReadNow(), HttpStateData::readReply(), reserve(), TestSBuf::testReserve(), and vappendf().

◆ startsWith()

bool SBuf::startsWith ( const SBuf S,
const SBufCaseSensitive  isCaseSensitive = caseSensitive 
) const

check whether the entire supplied argument is a prefix of the SBuf.

Parameters
Sthe prefix to match against
isCaseSensitiveone of caseSensitive or caseInsensitive
Return values
trueargument is a prefix of the SBuf

Definition at line 442 of file SBuf.cc.

References compare(), SBufStats::compareFast, debugs, id, length(), and stats.

Referenced by ForSomeCacheManager(), internalCheck(), internalStaticCheck(), ProxyProtocol::NameToFieldType(), SBufStartsWith::operator()(), Parser::Tokenizer::skipRequired(), TestSBuf::testStartsWith(), and TestTokenizer::testTokenizerSkip().

◆ substr()

◆ toLower()

void SBuf::toLower ( )

◆ toStdString()

std::string SBuf::toStdString ( ) const
inline

◆ toUpper()

void SBuf::toUpper ( )
See also
man toupper(3)

Definition at line 824 of file SBuf.cc.

References SBufStats::caseChange, debugs, length(), setAt(), and stats.

Referenced by Ftp::Server::handleFeatReply(), Ftp::Server::parseOneRequest(), and ToUpper().

◆ trim()

SBuf & SBuf::trim ( const SBuf toRemove,
bool  atBeginning = true,
bool  atEnd = true 
)

Remove characters in the toremove set at the beginning, end or both

Parameters
toremovecharacters to be removed. Stops chomping at the first found char not in the set
atBeginningif true (default), strips at the beginning of the SBuf
atEndif true (default), strips at the end of the SBuf

Definition at line 551 of file SBuf.cc.

References buf(), bufEnd(), clear(), isEmpty(), len_, length(), off_, stats, and SBufStats::trim.

Referenced by Http::One::Parser::getHostHeaderField(), Ftp::Server::parseOneRequest(), TestSBuf::testChomp(), and Store::UnpackNewSwapMetaVaryHeaders().

◆ vappendf()

SBuf & SBuf::vappendf ( const char *  fmt,
va_list  vargs 
)

Append operation, with vsprintf(3)-style arguments.

Note
arguments may be evaluated more than once, be careful of side-effects

Definition at line 239 of file SBuf.cc.

References SBufStats::append, buf(), Here, len_, Must, Must3, rawSpace(), MemBlob::size, spaceSize(), stats, and store_.

Referenced by appendf(), logfilePrintf(), Printf(), and ShmWriter::vappendf().

Friends And Related Function Documentation

◆ Locker

friend class Locker
friend

Definition at line 627 of file SBuf.h.

Member Data Documentation

◆ id

const InstanceId<SBuf> SBuf::id

SBuf object identifier meant for test cases and debugging. Does not change when object does, including during assignment.

Definition at line 604 of file SBuf.h.

Referenced by SBuf(), assign(), operator<<(), operator==(), and startsWith().

◆ len_

size_type SBuf::len_ = 0
private

◆ maxSize

◆ npos

◆ off_

size_type SBuf::off_ = 0
private

◆ stats

◆ store_


The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors