]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/strutl.h
fixed typo in fileutl.cc (damn you, studly caps...)
[apt.git] / apt-pkg / contrib / strutl.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: strutl.h,v 1.17 2001/02/23 05:45:27 jgg Exp $
4 /* ######################################################################
5
6 String Util - These are some useful string functions
7
8 _strstrip is a function to remove whitespace from the front and end
9 of a string.
10
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>
13
14 ##################################################################### */
15 /*}}}*/
16 #ifndef STRUTL_H
17 #define STRUTL_H
18
19 #ifdef __GNUG__
20 #pragma interface "apt-pkg/strutl.h"
21 #endif
22
23 #include <stdlib.h>
24 #include <string>
25 #include <vector>
26 #include <time.h>
27
28 #ifdef __GNUG__
29 // Methods have a hidden this parameter that is visible to this attribute
30 #define APT_FORMAT2 __attribute__ ((format (printf, 2, 3)))
31 #else
32 #define APT_FORMAT2
33 #endif
34
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,
52 unsigned int Length);
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);
57
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());};
65
66 class URI
67 {
68 void CopyFrom(string From);
69
70 public:
71
72 string Access;
73 string User;
74 string Password;
75 string Host;
76 string Path;
77 unsigned int Port;
78
79 operator string();
80 inline void operator =(string From) {CopyFrom(From);};
81 inline bool empty() {return Access.empty();};
82 static string SiteOnly(string URI);
83
84 URI(string Path) {CopyFrom(Path);};
85 URI() : Port(0) {};
86 };
87
88 struct SubstVar
89 {
90 const char *Subst;
91 const string *Contents;
92 };
93 string SubstVar(string Str,const struct SubstVar *Vars);
94 string SubstVar(string Str,string Subst,string Contents);
95
96 struct RxChoiceList
97 {
98 void *UserData;
99 const char *Str;
100 bool Hit;
101 };
102 unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
103 const char **ListEnd);
104
105 #undef APT_FORMAT2
106
107 #endif