apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

strutl.h File Reference
#include <cstring>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
#include <apt-pkg/string_view.h>
#include <stddef.h>
#include <time.h>
#include "macros.h"
Include dependency graph for strutl.h:

Go to the source code of this file.

Classes

class  URI
 
struct  SubstVar
 
struct  RxChoiceList
 

Namespaces

namespace  APT
 
namespace  APT::String
 

Macros

#define tolower_ascii   tolower_ascii_inline
 
#define isspace_ascii   isspace_ascii_inline
 
#define APT_MKSTRCMP(name, func)
 
#define APT_MKSTRCMP2(name, func)
 

Functions

std::string Strip (const std::string &str)
 
bool Endswith (const std::string &s, const std::string &end)
 
bool Startswith (const std::string &s, const std::string &start)
 
std::string Join (std::vector< std::string > list, const std::string &sep)
 
size_t DisplayLength (StringView str)
 
bool UTF8ToCodeset (const char *codeset, const std::string &orig, std::string *dest)
 
char * _strstrip (char *String)
 
char * _strrstrip (char *String)
 
Use SubstVar to avoid memory headaches char * _strtabexpand (char *String, size_t Len)
 
bool ParseQuoteWord (const char *&String, std::string &Res)
 
bool ParseCWord (const char *&String, std::string &Res)
 
std::string QuoteString (const std::string &Str, const char *Bad)
 
std::string DeQuoteString (const std::string &Str)
 
std::string DeQuoteString (std::string::const_iterator const &begin, std::string::const_iterator const &end)
 
std::string DeEscapeString (const std::string &input)
 
std::string SizeToStr (double Bytes)
 
std::string TimeToStr (unsigned long Sec)
 
std::string Base64Encode (const std::string &Str)
 
std::string OutputInDepth (const unsigned long Depth, const char *Separator=" ")
 
std::string URItoFileName (const std::string &URI)
 
std::string TimeRFC1123 (time_t Date, bool const NumericTimezone)
 
bool RFC1123StrToTime (const std::string &str, time_t &time)
 
bool FTPMDTMStrToTime (const char *const str, time_t &time)
 
std::string LookupTag (const std::string &Message, const char *Tag, const char *Default=0)
 
int StringToBool (const std::string &Text, int Default=-1)
 
bool ReadMessages (int Fd, std::vector< std::string > &List)
 
bool StrToNum (const char *Str, unsigned long &Res, unsigned Len, unsigned Base=0)
 
bool StrToNum (const char *Str, unsigned long long &Res, unsigned Len, unsigned Base=0)
 
bool Base256ToNum (const char *Str, unsigned long &Res, unsigned int Len)
 
bool Base256ToNum (const char *Str, unsigned long long &Res, unsigned int Len)
 
bool Hex2Num (const APT::StringView Str, unsigned char *Num, unsigned int Length)
 
bool TokSplitString (char Tok, char *Input, char **List, unsigned long ListMax)
 
std::vector< std::string > VectorizeString (std::string const &haystack, char const &split)
 
std::vector< std::string > StringSplit (std::string const &input, std::string const &sep, unsigned int maxsplit=std::numeric_limits< unsigned int >::max())
 
bool iovprintf (std::ostream &out, const char *format, va_list &args, ssize_t &size)
 
void ioprintf (std::ostream &out, const char *format,...)
 
void strprintf (std::string &out, const char *format,...)
 
char * safe_snprintf (char *Buffer, char *End, const char *Format,...)
 
bool CheckDomainList (const std::string &Host, const std::string &List)
 
static int tolower_ascii_unsafe (int const c)
 
static int tolower_ascii_inline (int const c)
 
static int isspace_ascii_inline (int const c)
 
std::string StripEpoch (const std::string &VerStr)
 
int stringcmp (const char *A, const char *AEnd, const char *B, const char *BEnd)
 
int stringcasecmp (const char *A, const char *AEnd, const char *B, const char *BEnd)
 
int stringcmp (const char *A, const char *AEnd, const char *B)
 
int stringcmp (const std::string &A, const char *B)
 
int stringcmp (const std::string &A, const std::string &B)
 
int stringcmp (const std::string &A, const char *B, const char *BEnd)
 
int stringcasecmp (const char *A, const char *AEnd, const char *B)
 
int stringcasecmp (const std::string &A, const char *B)
 
int stringcasecmp (const std::string &A, const std::string &B)
 
int stringcasecmp (const std::string &A, const char *B, const char *BEnd)
 
size_t strv_length (const char **str_array)
 
const char * DeNull (const char *s)
 
std::string SubstVar (std::string Str, const struct SubstVar *Vars)
 
std::string SubstVar (const std::string &Str, const std::string &Subst, const std::string &Contents)
 
unsigned long RegexChoice (RxChoiceList *Rxs, const char **ListBegin, const char **ListEnd)
 

Macro Definition Documentation

◆ APT_MKSTRCMP

#define APT_MKSTRCMP (   name,
  func 
)
Value:
inline APT_PURE int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));} \
inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
inline APT_PURE int name(const std::string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));} \
inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());} \
inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);}
#define APT_PURE
Definition: macros.h:56

Definition at line 150 of file strutl.h.

◆ APT_MKSTRCMP2

#define APT_MKSTRCMP2 (   name,
  func 
)
Value:
inline APT_PURE int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));} \
inline APT_PURE int name(const std::string& A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));} \
inline APT_PURE int name(const std::string& A,const std::string& B) {return func(A.begin(),A.end(),B.begin(),B.end());} \
inline APT_PURE int name(const std::string& A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);}

Definition at line 157 of file strutl.h.

◆ isspace_ascii

#define isspace_ascii   isspace_ascii_inline

Definition at line 129 of file strutl.h.

◆ tolower_ascii

#define tolower_ascii   tolower_ascii_inline

Definition at line 128 of file strutl.h.

Function Documentation

◆ _strrstrip()

char* _strrstrip ( char *  String)

Definition at line 237 of file strutl.cc.

Referenced by _strstrip(), and StartsWithGPGClearTextSignature().

◆ _strstrip()

char* _strstrip ( char *  String)

◆ _strtabexpand()

Use SubstVar to avoid memory headaches char* _strtabexpand ( char *  String,
size_t  Len 
)

Definition at line 250 of file strutl.cc.

References I.

◆ Base256ToNum() [1/2]

bool Base256ToNum ( const char *  Str,
unsigned long &  Res,
unsigned int  Len 
)

Definition at line 1208 of file strutl.cc.

References Base256ToNum().

◆ Base256ToNum() [2/2]

bool Base256ToNum ( const char *  Str,
unsigned long long &  Res,
unsigned int  Len 
)

Definition at line 1191 of file strutl.cc.

Referenced by Base256ToNum(), and ExtractTar::Go().

◆ Base64Encode()

std::string Base64Encode ( const std::string &  Str)

Definition at line 573 of file strutl.cc.

References I.

Referenced by HttpMethod::SendReq(), and UnwrapHTTPConnect().

◆ CheckDomainList()

bool CheckDomainList ( const std::string &  Host,
const std::string &  List 
)

Definition at line 1527 of file strutl.cc.

References stringcasecmp().

Referenced by HttpServerState::Open(), and FTPConn::Open().

◆ DeEscapeString()

std::string DeEscapeString ( const std::string &  input)

Definition at line 1561 of file strutl.cc.

Referenced by FindMountPointForDevice().

◆ DeNull()

const char* DeNull ( const char *  s)
inline

Definition at line 190 of file strutl.h.

Referenced by Dump(), DumpPackage(), and GetVersion().

◆ DeQuoteString() [1/2]

◆ DeQuoteString() [2/2]

std::string DeQuoteString ( std::string::const_iterator const &  begin,
std::string::const_iterator const &  end 
)

Definition at line 408 of file strutl.cc.

References I.

◆ FTPMDTMStrToTime()

bool FTPMDTMStrToTime ( const char *const  str,
time_t &  time 
)

Definition at line 1131 of file strutl.cc.

References timegm().

Referenced by FTPConn::ModTime(), and RSHConn::ModTime().

◆ Hex2Num()

bool Hex2Num ( const APT::StringView  Str,
unsigned char *  Num,
unsigned int  Length 
)

Definition at line 1239 of file strutl.cc.

References StringView::begin(), StringView::end(), HexDigit(), I, and StringView::length().

◆ ioprintf()

◆ iovprintf()

bool iovprintf ( std::ostream &  out,
const char *  format,
va_list &  args,
ssize_t &  size 
)

Definition at line 1418 of file strutl.cc.

Referenced by APT_PRINTF(), ioprintf(), pkgAcqMethod::Log(), pkgAcqMethod::Status(), and strprintf().

◆ isspace_ascii_inline()

static int isspace_ascii_inline ( int const  c)
inlinestatic

Definition at line 142 of file strutl.h.

Referenced by isspace_ascii().

◆ LookupTag()

◆ OutputInDepth()

◆ ParseCWord()

bool ParseCWord ( const char *&  String,
std::string &  Res 
)

Definition at line 347 of file strutl.cc.

Referenced by ReadConfigFile().

◆ ParseQuoteWord()

bool ParseQuoteWord ( const char *&  String,
std::string &  Res 
)

◆ QuoteString()

std::string QuoteString ( const std::string &  Str,
const char *  Bad 
)

◆ ReadMessages()

bool ReadMessages ( int  Fd,
std::vector< std::string > &  List 
)

Definition at line 883 of file strutl.cc.

References APT::String::Endswith(), and WaitFd().

Referenced by pkgAcqMethod::MediaFail(), and pkgAcqMethod::Run().

◆ RegexChoice()

unsigned long RegexChoice ( RxChoiceList Rxs,
const char **  ListBegin,
const char **  ListEnd 
)

Definition at line 1357 of file strutl.cc.

References I, and RxChoiceList::Str.

Referenced by DoGeneratePackagesAndSources().

◆ RFC1123StrToTime()

bool RFC1123StrToTime ( const std::string &  str,
time_t &  time 
)

parses time as needed by HTTP/1.1 and Debian files.

HTTP/1.1 prefers dates in RFC1123 format (but the other two obsolete date formats are supported to) and e.g. Release files use the same format in Date & Valid-Until fields.

Note: datetime strings need to be in UTC timezones (GMT, UTC, Z, +/-0000) to be parsed. Other timezones will be rejected as invalid. Previous implementations accepted other timezones, but treated them as UTC.

Parameters
stris the datetime string to parse
[out]timewill be the seconds since epoch of the given datetime if parsing is successful, undefined otherwise.
Returns
true if parsing was successful, otherwise false.

Definition at line 1040 of file strutl.cc.

References MonthConv(), strprintf(), timegm(), and VectorizeString().

Referenced by RequestState::HeaderLine(), debReleaseIndex::Load(), and pkgAcqMethod::Run().

◆ safe_snprintf()

char* safe_snprintf ( char *  Buffer,
char *  End,
const char *  Format,
  ... 
)

Definition at line 1468 of file strutl.cc.

◆ SizeToStr()

◆ stringcasecmp() [1/5]

int stringcasecmp ( const char *  A,
const char *  AEnd,
const char *  B 
)
inline

Definition at line 184 of file strutl.h.

◆ stringcasecmp() [2/5]

◆ stringcasecmp() [3/5]

int stringcasecmp ( const std::string &  A,
const char *  B 
)
inline

Definition at line 184 of file strutl.h.

◆ stringcasecmp() [4/5]

int stringcasecmp ( const std::string &  A,
const char *  B,
const char *  BEnd 
)
inline

Definition at line 184 of file strutl.h.

◆ stringcasecmp() [5/5]

int stringcasecmp ( const std::string &  A,
const std::string &  B 
)
inline

Definition at line 184 of file strutl.h.

◆ stringcmp() [1/5]

int stringcmp ( const char *  A,
const char *  AEnd,
const char *  B 
)
inline

Definition at line 183 of file strutl.h.

◆ stringcmp() [2/5]

int stringcmp ( const char *  A,
const char *  AEnd,
const char *  B,
const char *  BEnd 
)

◆ stringcmp() [3/5]

int stringcmp ( const std::string &  A,
const char *  B 
)
inline

Definition at line 183 of file strutl.h.

◆ stringcmp() [4/5]

int stringcmp ( const std::string &  A,
const char *  B,
const char *  BEnd 
)
inline

Definition at line 183 of file strutl.h.

◆ stringcmp() [5/5]

int stringcmp ( const std::string &  A,
const std::string &  B 
)
inline

Definition at line 183 of file strutl.h.

◆ StringSplit()

std::vector<std::string> StringSplit ( std::string const &  input,
std::string const &  sep,
unsigned int  maxsplit = std::numeric_limits< unsigned int >::max() 
)

◆ StringToBool()

◆ StripEpoch()

std::string StripEpoch ( const std::string &  VerStr)

Definition at line 1486 of file strutl.cc.

Referenced by pkgAcqChangelog::URI().

◆ strprintf()

void strprintf ( std::string &  out,
const char *  format,
  ... 
)

Definition at line 1446 of file strutl.cc.

References iovprintf().

Referenced by RFC1123StrToTime(), SizeToStr(), and TimeToStr().

◆ StrToNum() [1/2]

bool StrToNum ( const char *  Str,
unsigned long &  Res,
unsigned  Len,
unsigned  Base = 0 
)

Definition at line 1146 of file strutl.cc.

Referenced by ExtractTar::Go(), and ARArchive::LoadHeaders().

◆ StrToNum() [2/2]

bool StrToNum ( const char *  Str,
unsigned long long &  Res,
unsigned  Len,
unsigned  Base = 0 
)

Definition at line 1163 of file strutl.cc.

References I.

◆ strv_length()

size_t strv_length ( const char **  str_array)

Definition at line 1549 of file strutl.cc.

Referenced by DoList().

◆ SubstVar() [1/2]

◆ SubstVar() [2/2]

std::string SubstVar ( std::string  Str,
const struct SubstVar Vars 
)

Definition at line 530 of file strutl.cc.

References SubstVar::Contents, SubstVar::Subst, and SubstVar().

◆ TimeRFC1123()

std::string TimeRFC1123 ( time_t  Date,
bool const  NumericTimezone 
)

returns a datetime string as needed by HTTP/1.1 and Debian files.

Note: The date will always be represented in a UTC timezone

Parameters
Dateto be represented as a string
NumericTimezoneis preferred in general, but HTTP/1.1 requires the use of GMT as timezone instead. true means that the timezone should be denoted as "+0000" while false uses "GMT".

Definition at line 853 of file strutl.cc.

References StringView::data(), and StringView::size().

Referenced by pkgAcqMetaBase::Custom600Headers(), pkgAcqIndex::Custom600Headers(), Dump(), pkgAcqBaseIndex::Failed(), formatUTCDateTime(), HttpMethod::SendReq(), pkgAcqMethod::URIDone(), pkgAcqMethod::URIStart(), and EDSP::WriteProgress().

◆ TimeToStr()

◆ TokSplitString()

bool TokSplitString ( char  Tok,
char *  Input,
char **  List,
unsigned long  ListMax 
)

◆ tolower_ascii_inline()

static int tolower_ascii_inline ( int const  c)
inlinestatic

Definition at line 137 of file strutl.h.

Referenced by debListParser::Package(), and tolower_ascii().

◆ tolower_ascii_unsafe()

static int tolower_ascii_unsafe ( int const  c)
inlinestatic

Definition at line 132 of file strutl.h.

Referenced by pkgCache< Str, Itr >::sHash(), and debListParser::VersionHash().

◆ URItoFileName()

◆ UTF8ToCodeset()

bool UTF8ToCodeset ( const char *  codeset,
const std::string &  orig,
std::string *  dest 
)

Definition at line 155 of file strutl.cc.

Referenced by debRecordParserBase::LongDesc().

◆ VectorizeString()