X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/38d2959ffb8c6f5f291b2910014a67b1b352ab4c..f009dd15f385e9df4ca0482a940870350ba2d160:/apt-pkg/contrib/strutl.h diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 185cdc3fc..c5c8e2382 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -22,6 +22,9 @@ #include #include #include +#ifdef APT_PKG_EXPOSE_STRING_VIEW +#include +#endif #include #include @@ -40,6 +43,7 @@ namespace APT { namespace String { std::string Strip(const std::string &s); bool Endswith(const std::string &s, const std::string &ending); + bool Startswith(const std::string &s, const std::string &starting); } } @@ -65,21 +69,24 @@ std::string URItoFileName(const std::string &URI); std::string TimeRFC1123(time_t Date); bool RFC1123StrToTime(const char* const str,time_t &time) APT_MUSTCHECK; bool FTPMDTMStrToTime(const char* const str,time_t &time) APT_MUSTCHECK; -APT_DEPRECATED bool StrToTime(const std::string &Val,time_t &Result); +APT_DEPRECATED_MSG("Use RFC1123StrToTime or FTPMDTMStrToTime as needed instead") bool StrToTime(const std::string &Val,time_t &Result); 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 &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 std::string &Str,unsigned char *Num,unsigned int Length); - +#ifdef APT_PKG_EXPOSE_STRING_VIEW +APT_HIDDEN bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length); +#endif // input changing string split bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); // split a given string by a char -std::vector VectorizeString(std::string const &haystack, char const &split) APT_CONST; +std::vector VectorizeString(std::string const &haystack, char const &split) APT_PURE; /* \brief Return a vector of strings from string "input" where "sep" * is used as the delimiter string. @@ -103,7 +110,23 @@ void ioprintf(std::ostream &out,const char *format,...) APT_PRINTF(2); void strprintf(std::string &out,const char *format,...) APT_PRINTF(2); char *safe_snprintf(char *Buffer,char *End,const char *Format,...) APT_PRINTF(3); bool CheckDomainList(const std::string &Host, const std::string &List); -int tolower_ascii(int const c) APT_CONST APT_HOT; + +/* Do some compat mumbo jumbo */ +#define tolower_ascii tolower_ascii_inline +#define isspace_ascii isspace_ascii_inline + +APT_CONST APT_HOT +static inline int tolower_ascii_inline(int const c) +{ + return (c >= 'A' && c <= 'Z') ? c + 32 : c; +} +APT_CONST APT_HOT +static inline int isspace_ascii_inline(int const c) +{ + // 9='\t',10='\n',11='\v',12='\f',13='\r',32=' ' + return (c >= 9 && c <= 13) || c == ' '; +} + std::string StripEpoch(const std::string &VerStr); #define APT_MKSTRCMP(name,func) \ @@ -151,9 +174,9 @@ inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);} class URI { void CopyFrom(const std::string &From); - + public: - + std::string Access; std::string User; std::string Password; @@ -165,6 +188,7 @@ class URI inline void operator =(const std::string &From) {CopyFrom(From);} inline bool empty() {return Access.empty();}; static std::string SiteOnly(const std::string &URI); + static std::string ArchiveOnly(const std::string &URI); static std::string NoUserPassword(const std::string &URI); URI(std::string Path) {CopyFrom(Path);}