]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/strutl.h
Moved time handling, fixed makefiles
[apt.git] / apt-pkg / contrib / strutl.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: strutl.h,v 1.15 1999/08/02 03:07:48 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 #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 char *_strstrip(char *String);
29 char *_strtabexpand(char *String,size_t Len);
30 bool ParseQuoteWord(const char *&String,string &Res);
31 bool ParseCWord(const char *String,string &Res);
32 string QuoteString(string Str,const char *Bad);
33 string DeQuoteString(string Str);
34 string SizeToStr(double Bytes);
35 string TimeToStr(unsigned long Sec);
36 string SubstVar(string Str,string Subst,string Contents);
37 string Base64Encode(string Str);
38 string URItoFileName(string URI);
39 string TimeRFC1123(time_t Date);
40 bool StrToTime(string Val,time_t &Result);
41 string LookupTag(string Message,const char *Tag,const char *Default = 0);
42 int StringToBool(string Text,int Default = -1);
43 bool ReadMessages(int Fd, vector<string> &List);
44 bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
45 bool Hex2Num(const char *Start,const char *End,unsigned char *Num,
46 unsigned int Length);
47
48 int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
49 inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
50 inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
51 int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
52 inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
53 inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
54
55 class URI
56 {
57 void CopyFrom(string From);
58
59 public:
60
61 string Access;
62 string User;
63 string Password;
64 string Host;
65 string Path;
66 unsigned int Port;
67
68 operator string();
69 inline void operator =(string From) {CopyFrom(From);};
70 inline bool empty() {return Access.empty();};
71
72 URI(string Path) {CopyFrom(Path);};
73 URI() : Port(0) {};
74 };
75
76 #endif