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.cc File Reference
#include <config.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <limits>
#include <locale>
#include <sstream>
#include <memory>
#include <string>
#include <vector>
#include <ctype.h>
#include <errno.h>
#include <iconv.h>
#include <regex.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <apti18n.h>
Include dependency graph for strutl.cc:

Go to the source code of this file.


namespace  APT
namespace  APT::String


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 string &orig, string *dest)
char * _strstrip (char *String)
char * _strrstrip (char *String)
char * _strtabexpand (char *String, size_t Len)
bool ParseQuoteWord (const char *&String, string &Res)
bool ParseCWord (const char *&String, string &Res)
string QuoteString (const string &Str, const char *Bad)
string DeQuoteString (const string &Str)
string DeQuoteString (string::const_iterator const &begin, string::const_iterator const &end)
string SizeToStr (double Size)
string TimeToStr (unsigned long Sec)
string SubstVar (const string &Str, const string &Subst, const string &Contents)
string SubstVar (string Str, const struct SubstVar *Vars)
std::string OutputInDepth (const unsigned long Depth, const char *Separator)
string URItoFileName (const string &URI)
string Base64Encode (const string &S)
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)
std::string LookupTag (const std::string &Message, const char *TagC, const char *Default)
int StringToBool (const string &Text, int Default)
string TimeRFC1123 (time_t Date, bool const NumericTimezone)
bool ReadMessages (int Fd, vector< string > &List)
static int MonthConv (char const *const Month)
static time_t timegm (struct tm *t)
bool RFC1123StrToTime (std::string const &str, time_t &time)
bool FTPMDTMStrToTime (const char *const str, time_t &time)
bool StrToNum (const char *Str, unsigned long &Res, unsigned Len, unsigned Base)
bool StrToNum (const char *Str, unsigned long long &Res, unsigned Len, unsigned Base)
bool Base256ToNum (const char *Str, unsigned long long &Res, unsigned int Len)
bool Base256ToNum (const char *Str, unsigned long &Res, unsigned int Len)
static int HexDigit (int c)
bool Hex2Num (const APT::StringView Str, unsigned char *Num, unsigned int Length)
bool TokSplitString (char Tok, char *Input, char **List, unsigned long ListMax)
vector< string > VectorizeString (string const &haystack, char const &split)
vector< string > StringSplit (std::string const &s, std::string const &sep, unsigned int maxsplit)
unsigned long RegexChoice (RxChoiceList *Rxs, const char **ListBegin, const char **ListEnd)
bool iovprintf (std::ostream &out, const char *format, va_list &args, ssize_t &size)
void ioprintf (ostream &out, const char *format,...)
void strprintf (string &out, const char *format,...)
char * safe_snprintf (char *Buffer, char *End, const char *Format,...)
string StripEpoch (const string &VerStr)
int tolower_ascii (int const c) APT_PURE APT_COLD
int isspace_ascii (int const c) APT_PURE APT_COLD
bool CheckDomainList (const string &Host, const string &List)
size_t strv_length (const char **str_array)
string DeEscapeString (const string &input)

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()

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()

string Base64Encode ( const string &  S)

Definition at line 573 of file strutl.cc.

References I.

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

◆ CheckDomainList()

bool CheckDomainList ( const string &  Host,
const string &  List 

Definition at line 1527 of file strutl.cc.

References stringcasecmp().

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

◆ DeEscapeString()

string DeEscapeString ( const string &  input)

Definition at line 1561 of file strutl.cc.

Referenced by FindMountPointForDevice().

◆ DeQuoteString() [1/2]

◆ DeQuoteString() [2/2]

string DeQuoteString ( string::const_iterator const &  begin,
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().

◆ HexDigit()

static int HexDigit ( int  c)

Definition at line 1225 of file strutl.cc.

Referenced by Hex2Num().

◆ 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()

◆ LookupTag()

◆ MonthConv()

static int MonthConv ( char const *const  Month)

Definition at line 979 of file strutl.cc.

References tolower_ascii().

Referenced by RFC1123StrToTime().

◆ OutputInDepth()

◆ ParseCWord()

bool ParseCWord ( const char *&  String,
string &  Res 

Definition at line 347 of file strutl.cc.

Referenced by ReadConfigFile().

◆ ParseQuoteWord()

bool ParseQuoteWord ( const char *&  String,
string &  Res 

◆ QuoteString()

string QuoteString ( const string &  Str,
const char *  Bad 

◆ ReadMessages()

bool ReadMessages ( int  Fd,
vector< 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.

stris the datetime string to parse
[out]timewill be the seconds since epoch of the given datetime if parsing is successful, undefined otherwise.
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()

◆ stringcmp()

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

◆ StringSplit()

vector<string> StringSplit ( std::string const &  s,
std::string const &  sep,
unsigned int  maxsplit 

◆ StringToBool()

◆ StripEpoch()

string StripEpoch ( const string &  VerStr)

Definition at line 1486 of file strutl.cc.

Referenced by pkgAcqChangelog::URI().

◆ strprintf()

void strprintf ( 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 

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 

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]

string SubstVar ( string  Str,
const struct SubstVar Vars 

Definition at line 530 of file strutl.cc.

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

◆ timegm()

static time_t timegm ( struct tm *  t)

Definition at line 1017 of file strutl.cc.

Referenced by FTPMDTMStrToTime(), and RFC1123StrToTime().

◆ TimeRFC1123()

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

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()

int tolower_ascii ( int const  c)

Definition at line 1503 of file strutl.cc.

References tolower_ascii_inline().

Referenced by LookupTag(), MonthConv(), debRecordParserBase::Name(), and stringcasecmp().

◆ URItoFileName()

◆ UTF8ToCodeset()

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

Definition at line 155 of file strutl.cc.

Referenced by debRecordParserBase::LongDesc().

◆ VectorizeString()