]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/strutl.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: strutl.h,v 1.17 2001/02/23 05:45:27 jgg Exp $
4 /* ######################################################################
6 String Util - These are some useful string functions
8 _strstrip is a function to remove whitespace from the front and end
11 This source is placed in the Public Domain, do with it what you will
12 It was originally written by Jason Gunthorpe <jgg@gpu.srv.ualberta.ca>
14 ##################################################################### */
20 #pragma interface "apt-pkg/strutl.h"
29 // Methods have a hidden this parameter that is visible to this attribute
30 #define APT_FORMAT2 __attribute__ ((format (printf, 2, 3)))
35 char *_strstrip(char *String
);
36 char *_strtabexpand(char *String
,size_t Len
);
37 bool ParseQuoteWord(const char *&String
,string
&Res
);
38 bool ParseCWord(const char *&String
,string
&Res
);
39 string
QuoteString(string Str
,const char *Bad
);
40 string
DeQuoteString(string Str
);
41 string
SizeToStr(double Bytes
);
42 string
TimeToStr(unsigned long Sec
);
43 string
Base64Encode(string Str
);
44 string
URItoFileName(string URI
);
45 string
TimeRFC1123(time_t Date
);
46 bool StrToTime(string Val
,time_t &Result
);
47 string
LookupTag(string Message
,const char *Tag
,const char *Default
= 0);
48 int StringToBool(string Text
,int Default
= -1);
49 bool ReadMessages(int Fd
, vector
<string
> &List
);
50 bool StrToNum(const char *Str
,unsigned long &Res
,unsigned Len
,unsigned Base
= 0);
51 bool Hex2Num(const char *Start
,const char *End
,unsigned char *Num
,
53 bool TokSplitString(char Tok
,char *Input
,char **List
,
54 unsigned long ListMax
);
55 void ioprintf(ostream
&out
,const char *format
,...) APT_FORMAT2
;
56 bool CheckDomainList(string Host
,string List
);
58 int stringcmp(const char *A
,const char *AEnd
,const char *B
,const char *BEnd
);
59 inline int stringcmp(const char *A
,const char *AEnd
,const char *B
) {return stringcmp(A
,AEnd
,B
,B
+strlen(B
));};
60 inline int stringcmp(string A
,const char *B
) {return stringcmp(A
.begin(),A
.end(),B
,B
+strlen(B
));};
61 int stringcasecmp(const char *A
,const char *AEnd
,const char *B
,const char *BEnd
);
62 inline int stringcasecmp(const char *A
,const char *AEnd
,const char *B
) {return stringcasecmp(A
,AEnd
,B
,B
+strlen(B
));};
63 inline int stringcasecmp(string A
,const char *B
) {return stringcasecmp(A
.begin(),A
.end(),B
,B
+strlen(B
));};
64 inline int stringcasecmp(string A
,string B
) {return stringcasecmp(A
.begin(),A
.end(),B
.begin(),B
.end());};
68 void CopyFrom(string From
);
80 inline void operator =(string From
) {CopyFrom(From
);};
81 inline bool empty() {return Access
.empty();};
82 static string
SiteOnly(string URI
);
84 URI(string Path
) {CopyFrom(Path
);};
91 const string
*Contents
;
93 string
SubstVar(string Str
,const struct SubstVar
*Vars
);
94 string
SubstVar(string Str
,string Subst
,string Contents
);
102 unsigned long RegexChoice(RxChoiceList
*Rxs
,const char **ListBegin
,
103 const char **ListEnd
);