]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/strutl.h
f93184a24c35748c294b4dcd46593f09fc53ce38
[apt.git] / apt-pkg / contrib / strutl.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: strutl.h,v 1.9 1998/11/01 05:27:38 jgg Exp $
4 /* ######################################################################
5
6 String Util - These are some usefull 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 #include <stdlib.h>
20 #include <string>
21 #include <vector>
22
23 char *_strstrip(char *String);
24 char *_strtabexpand(char *String,size_t Len);
25 bool ParseQuoteWord(const char *&String,string &Res);
26 bool ParseCWord(const char *String,string &Res);
27 string QuoteString(string Str,const char *Bad);
28 string SizeToStr(double Bytes);
29 string TimeToStr(unsigned long Sec);
30 string SubstVar(string Str,string Subst,string Contents);
31 string Base64Encode(string Str);
32 string URItoFileName(string URI);
33 string TimeRFC1123(time_t Date);
34 bool StrToTime(string Val,time_t &Result);
35 string LookupTag(string Message,const char *Tag,const char *Default = 0);
36 int StringToBool(string Text,int Default = -1);
37 bool ReadMessages(int Fd, vector<string> &List);
38
39 int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
40 inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
41 inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
42 int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
43 inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
44 inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
45
46 class URI
47 {
48 void CopyFrom(string From);
49
50 public:
51
52 string Access;
53 string User;
54 string Password;
55 string Host;
56 string Path;
57 unsigned int Port;
58
59 inline operator string();
60 inline operator =(string From) {CopyFrom(From);};
61 inline bool empty() {return Access.empty();};
62
63 URI(string Path) {CopyFrom(Path);};
64 URI() : Port(0) {};
65 };
66
67 #endif