#include <SquidString.h>

Collaboration diagram for String:

Public Types

typedef size_t size_type
 

Public Member Functions

 String ()=default
 
 String (char const *)
 
 String (String const &)
 
 String (String &&S)
 
 ~String ()
 
Stringoperator= (char const *)
 
Stringoperator= (String const &)
 
Stringoperator= (String &&S)
 
bool operator== (String const &) const
 
bool operator!= (String const &) const
 
char operator[] (unsigned int aPos) const
 
size_type size () const
 
int psize () const
 
char const * rawBuf () const
 
char const * termedBuf () const
 
void assign (const char *str, int len)
 
void clean ()
 
void reset (char const *str)
 
void append (char const *buf, int len)
 
void append (char const *buf)
 
void append (char const)
 
void append (String const &)
 
void absorb (String &old)
 
const char * pos (char const *aString) const
 
const char * pos (char const ch) const
 
size_type find (char const ch) const
 
size_type find (char const *aString) const
 
const char * rpos (char const ch) const
 
size_type rfind (char const ch) const
 
int cmp (char const *) const
 
int cmp (char const *, size_type count) const
 
int cmp (String const &) const
 
int caseCmp (char const *) const
 
int caseCmp (char const *, size_type count) const
 
int caseCmp (String const &str) const
 
bool canGrowBy (const size_type growthLen) const
 whether appending growthLen characters is safe (i.e., unlikely to assert) More...
 
String substr (size_type from, size_type to) const
 
void cut (size_type newLength)
 

Static Public Member Functions

static size_type SizeMaxXXX ()
 
static bool CanGrowTo (size_type totalLen, const size_type extras=0)
 

Static Public Attributes

static const size_type npos = static_cast<size_type>(-1)
 

Private Member Functions

void allocAndFill (const char *str, int len)
 
void allocBuffer (size_type sz)
 
void setBuffer (char *buf, size_type sz)
 
bool defined () const
 
bool undefined () const
 
void set (char const *loc, char const ch)
 
void cutPointer (char const *loc)
 

Static Private Member Functions

static bool SafeAdd (size_type &base, size_type extra)
 returns true after increasing the first argument by extra if the sum does not exceed SizeMax_ More...
 

Private Attributes

size_type size_ = 0
 
size_type len_ = 0
 
char * buf_ = nullptr
 

Static Private Attributes

static const size_type SizeMax_ = 65535
 

Detailed Description

Definition at line 25 of file SquidString.h.

Member Typedef Documentation

◆ size_type

Definition at line 38 of file SquidString.h.

Constructor & Destructor Documentation

◆ String() [1/4]

String::String ( )
default

◆ String() [2/4]

String::String ( char const *  aString)

Definition at line 36 of file String.cc.

References allocAndFill().

◆ String() [3/4]

String::String ( String const &  old)

Definition at line 96 of file String.cc.

References allocAndFill(), rawBuf(), and size().

◆ String() [4/4]

String::String ( String &&  S)
inline

Definition at line 32 of file SquidString.h.

◆ ~String()

String::~String ( )

Definition at line 116 of file String.cc.

References clean().

Member Function Documentation

◆ absorb()

void String::absorb ( String old)

Definition at line 179 of file String.cc.

References buf_, clean(), len_, setBuffer(), and size_.

Referenced by append().

◆ allocAndFill()

void String::allocAndFill ( const char *  str,
int  len 
)
private

Definition at line 87 of file String.cc.

References allocBuffer(), assert, buf_, and len_.

Referenced by String(), assign(), operator=(), and reset().

◆ allocBuffer()

void String::allocBuffer ( String::size_type  sz)
private

Definition at line 18 of file String.cc.

References assert, memAllocString(), setBuffer(), and undefined().

Referenced by allocAndFill(), and append().

◆ append() [1/4]

void String::append ( char const *  buf)

Definition at line 157 of file String.cc.

References append(), and assert.

◆ append() [2/4]

◆ append() [3/4]

void String::append ( char const  chr)

Definition at line 164 of file String.cc.

References append().

◆ append() [4/4]

void String::append ( String const &  old)

Definition at line 173 of file String.cc.

References append(), len_, and rawBuf().

◆ assign()

◆ canGrowBy()

bool String::canGrowBy ( const size_type  growthLen) const
inline

Definition at line 124 of file SquidString.h.

References CanGrowTo(), and size().

Referenced by append(), HttpStateData::httpBuildRequestHeader(), and strListAdd().

◆ CanGrowTo()

static bool String::CanGrowTo ( size_type  totalLen,
const size_type  extras = 0 
)
inlinestatic

Whether creating a totalLen-character string is safe (i.e., unlikely to assert). Optional extras can be used for overflow-safe length addition. Implementation has to add 1 because many String allocation methods do.

Definition at line 122 of file SquidString.h.

References SafeAdd().

Referenced by canGrowBy().

◆ caseCmp() [1/3]

◆ caseCmp() [2/3]

int String::caseCmp ( char const *  aString,
String::size_type  count 
) const

Definition at line 276 of file String.cc.

References nilCmp(), size(), and termedBuf().

◆ caseCmp() [3/3]

int String::caseCmp ( String const &  str) const
inline

Definition at line 115 of file SquidString.h.

References caseCmp(), rawBuf(), and size().

◆ clean()

◆ cmp() [1/3]

◆ cmp() [2/3]

int String::cmp ( char const *  aString,
String::size_type  count 
) const

Definition at line 246 of file String.cc.

References nilCmp(), size(), and termedBuf().

◆ cmp() [3/3]

int String::cmp ( String const &  aString) const

Definition at line 256 of file String.cc.

References nilCmp(), size(), and termedBuf().

◆ cut()

void String::cut ( String::size_type  newLength)

Definition at line 203 of file String.cc.

References buf_, and len_.

Referenced by clientFollowXForwardedForCheck(), and Adaptation::ServiceGroup::finalize().

◆ cutPointer()

void String::cutPointer ( char const *  loc)
inlineprivate

Definition at line 155 of file SquidString.h.

References buf_, len_, and size_.

◆ defined()

bool String::defined ( ) const
inlineprivate

Definition at line 135 of file SquidString.h.

References buf_.

Referenced by clean(), and undefined().

◆ find() [1/2]

String::size_type String::find ( char const *  aString) const

Definition at line 439 of file String.cc.

References npos, pos(), and rawBuf().

◆ find() [2/2]

String::size_type String::find ( char const  ch) const

offset from string start of the first occurrence of ch returns String::npos if ch is not found

Definition at line 429 of file String.cc.

References npos, pos(), and rawBuf().

Referenced by strListIsSubstr().

◆ operator!=()

bool String::operator!= ( String const &  that) const

Definition at line 68 of file String.cc.

References cmp().

◆ operator=() [1/3]

String & String::operator= ( char const *  aString)

Definition at line 43 of file String.cc.

References reset().

◆ operator=() [2/3]

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

Definition at line 43 of file SquidString.h.

References buf_, clean(), len_, and size_.

◆ operator=() [3/3]

String & String::operator= ( String const &  old)

Definition at line 50 of file String.cc.

References allocAndFill(), clean(), rawBuf(), and size().

◆ operator==()

bool String::operator== ( String const &  that) const

Definition at line 59 of file String.cc.

References cmp().

◆ operator[]()

char String::operator[] ( unsigned int  aPos) const
inline

Retrieve a single character in the string.

Parameters
aPosPosition of character to retrieve.

Definition at line 63 of file SquidString.h.

References assert, buf_, and size_.

◆ pos() [1/2]

const char * String::pos ( char const *  aString) const

Definition at line 405 of file String.cc.

References termedBuf(), and undefined().

Referenced by Http::ContentLengthInterpreter::checkField(), esiEnableProcessing(), and find().

◆ pos() [2/2]

const char * String::pos ( char const  ch) const

Definition at line 413 of file String.cc.

References termedBuf(), and undefined().

◆ psize()

int String::psize ( ) const
inline

variant of size() suited to be used for printf-alikes. throws when size() >= INT_MAX

Definition at line 77 of file SquidString.h.

References INT_MAX, Must, and size().

Referenced by Ipc::TypedMsgHdr::putString(), and HttpReply::sanityCheckStartLine().

◆ rawBuf()

◆ reset()

void String::reset ( char const *  str)

Definition at line 122 of file String.cc.

References allocAndFill(), and clean().

Referenced by ftpReadCwd(), and operator=().

◆ rfind()

String::size_type String::rfind ( char const  ch) const

Definition at line 449 of file String.cc.

References npos, rawBuf(), and rpos().

◆ rpos()

const char * String::rpos ( char const  ch) const

Definition at line 421 of file String.cc.

References termedBuf(), and undefined().

Referenced by rfind().

◆ SafeAdd()

static bool String::SafeAdd ( size_type base,
size_type  extra 
)
inlinestaticprivate

Definition at line 145 of file SquidString.h.

References SizeMax_.

Referenced by CanGrowTo().

◆ set()

void String::set ( char const *  loc,
char const  ch 
)
inlineprivate

Definition at line 149 of file SquidString.h.

References buf_, and size_.

◆ setBuffer()

void String::setBuffer ( char *  buf,
String::size_type  aSize 
)
private

Definition at line 28 of file String.cc.

References assert, buf_, size_, SizeMax_, and undefined().

Referenced by absorb(), and allocBuffer().

◆ size()

size_type String::size ( ) const
inline

Definition at line 73 of file SquidString.h.

References len_.

Referenced by String(), ESIAssign::addElement(), Format::Format::assemble(), ESIVarState::buildVary(), canGrowBy(), caseCmp(), Adaptation::Icap::Options::cfgIntHeader(), Http::ContentLengthInterpreter::checkField(), Http::ContentLengthInterpreter::checkList(), CacheManager::CheckPassword(), clientFollowXForwardedForCheck(), cmp(), Adaptation::Icap::Options::configure(), Ipc::Port::CoordinatorAddr(), copyOneHeaderFromClientsideRequestToUpstreamRequest(), copyResultsFromEntry(), HttpHeader::delAt(), ESIVariableExpression::eval(), ESIVariableLanguage::eval(), ESIAssign::evaluateVariable(), Adaptation::Icap::ModXact::expectIcapTrailers(), Adaptation::ServiceGroup::finalize(), Adaptation::Icap::ModXact::finalizeLogInfo(), Mgr::QueryParams::find(), HttpStateData::forwardUpgrade(), Mgr::QueryParams::get(), AccessLogEntry::getExtUser(), HttpHeader::getList(), Ftp::Server::handleEprtRequest(), Ftp::Server::handleEpsvRequest(), Ftp::Server::handlePasvRequest(), Ftp::Server::handlePortRequest(), HttpHdrCc::hasNoCacheWithoutParameters(), HttpHdrCc::hasNoCacheWithParameters(), HttpHdrScTarget::hasTarget(), MemObject::hasUris(), HttpStateData::httpBuildRequestHeader(), httpFixupAuthentication(), HttpHeaderEntry::length(), MemObject::logUri(), Adaptation::Icap::ModXact::makeRequestHeaders(), Adaptation::Icap::ModXact::makeUsernameHeader(), Adaptation::Ecap::XactionRep::masterxSharedValue(), ACLExtUser::match(), HttpHdrCc::noCache(), operator<<(), operator=(), HttpHdrCc::packInto(), HttpHeaderEntry::packInto(), Adaptation::ServiceConfig::parse(), Ssl::ErrorDetailFile::parse(), Http::StatusLine::parse(), HttpHdrCc::parse(), Adaptation::Icap::ModXact::parseIcapHead(), HttpHdrCc::Private(), ESIAssign::process(), psize(), Ipc::Coordinator::registerStrand(), ESIVarState::removeVariable(), HttpReply::sanityCheckStartLine(), Ftp::Relay::sendCommand(), SlowlyParseQuotedField(), statClientRequests(), HttpRequest::storeId(), clientReplyContext::storeId(), MemObject::storeId(), storeLog(), strHdrAcptLangGetItem(), StringToSBuf(), strListAdd(), substr(), Mgr::QueryParams::unpack(), Adaptation::Ecap::XactionRep::usernameValue(), Adaptation::Ecap::HeaderRep::value(), Http::One::Server::writeControlMsgAndCall(), and Ftp::Server::writeErrorReply().

◆ SizeMaxXXX()

static size_type String::SizeMaxXXX ( )
inlinestatic

The absolute size limit on data held in a String. Since Strings can be nil-terminated implicitly it is best to ensure the useful content length is strictly less than this limit.

Definition at line 71 of file SquidString.h.

References SizeMax_.

Referenced by HttpHeader::updateOrAddStr().

◆ substr()

String String::substr ( String::size_type  from,
String::size_type  to 
) const

Definition at line 190 of file String.cc.

References assign(), Must, rawBuf(), and size().

Referenced by strHdrAcptLangGetItem(), and TestString::testSubstr().

◆ termedBuf()

char const * String::termedBuf ( ) const
inline

Returns a raw pointer to the underlying backing store. The caller requires it to be null-terminated.

Definition at line 92 of file SquidString.h.

References buf_.

Referenced by Mgr::ActionParams::ActionParams(), Mgr::Response::Response(), aclMatchExternal(), addedEntry(), Format::Format::assemble(), assembleVaryKey(), clientReplyContext::buildReplyHeader(), Ssl::ErrorDetailsManager::cacheDetails(), caseCmp(), Adaptation::Icap::Options::cfgIntHeader(), clientFollowXForwardedForCheck(), HttpHeaderEntry::clone(), IpcIoFile::close(), cmp(), ErrorState::compileLegacyCode(), CacheManager::createRequestedAction(), Mgr::Action::createStoreEntry(), Adaptation::Icap::Xaction::dnsLookupDone(), TestConfigParser::doParseQuotedTest(), Adaptation::Icap::Xaction::finalizeLogInfo(), Adaptation::Icap::ModXact::finalizeLogInfo(), Adaptation::Ecap::FindAdapterService(), HttpStateData::forwardUpgrade(), Rock::SwapDir::freeSlotsPath(), HttpHeader::getContRange(), HttpHeader::getETag(), AccessLogEntry::getExtUser(), HttpHeaderEntry::getInt(), HttpHeaderEntry::getInt64(), HttpHeader::getLastStr(), HttpHeader::getList(), HttpHeader::getStr(), HttpHeader::getTime(), HttpHeader::getTimeOrTag(), ClientHttpRequest::handleAdaptationBlock(), Client::handleAdaptationBlocked(), Ftp::Server::handleEprtRequest(), Ftp::Server::handlePortRequest(), Ftp::Server::handleRequest(), HttpHeader::hasNamed(), StoreEntry::hasOneOfEtags(), HttpStateData::httpBuildRequestHeader(), httpFixupAuthentication(), httpHeaderParseQuotedString(), TemplateFile::language(), TemplateFile::loadDefault(), MemObject::logUri(), Adaptation::Icap::ModXact::makeUsernameHeader(), ACLExtUser::match(), IpcIoFile::open(), Adaptation::Icap::Xaction::openConnection(), LoadableModule::openModule(), Adaptation::ServiceConfig::parse(), Ssl::ErrorDetailFile::parse(), HttpHeaderEntry::parse(), Rock::SwapDir::parse(), parse_HeaderWithAclList(), HttpHdrRange::parseInit(), pos(), prepareLogWithRequestDetails(), Ftp::PrintReply(), ConfigParser::QuoteString(), rpos(), Ftp::Relay::sendCommand(), ErrorPageFile::setDefault(), SlowlyParseQuotedField(), Log::Format::SquidIcap(), statClientRequests(), clientReplyContext::storeId(), MemObject::storeId(), storeLog(), strListGetItem(), TemplateFile::tryLoadTemplate(), Adaptation::Ecap::UnregisterAdapterService(), Adaptation::Ecap::HeaderRep::value(), Http::One::Server::writeControlMsgAndCall(), and Ftp::Server::writeErrorReply().

◆ undefined()

bool String::undefined ( ) const
inlineprivate

Definition at line 136 of file SquidString.h.

References defined().

Referenced by allocBuffer(), pos(), rpos(), and setBuffer().

Member Data Documentation

◆ buf_

char* String::buf_ = nullptr
private

◆ len_

size_type String::len_ = 0
private

Definition at line 141 of file SquidString.h.

Referenced by absorb(), allocAndFill(), append(), clean(), cut(), cutPointer(), operator=(), and size().

◆ npos

const size_type String::npos = static_cast<size_type>(-1)
static

Definition at line 39 of file SquidString.h.

Referenced by find(), Adaptation::ServiceConfig::grokUri(), rfind(), and strListIsSubstr().

◆ size_

size_type String::size_ = 0
private

Definition at line 139 of file SquidString.h.

Referenced by absorb(), append(), clean(), cutPointer(), operator=(), operator[](), set(), and setBuffer().

◆ SizeMax_

const size_type String::SizeMax_ = 65535
staticprivate

64K limit protects some fixed-size buffers

Definition at line 143 of file SquidString.h.

Referenced by SafeAdd(), setBuffer(), and SizeMaxXXX().


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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors