]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
1bc849af | 3 | // $Id: strutl.h,v 1.12 1999/02/01 08:11:57 jgg Exp $ |
6c139d6e AL |
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 | /*}}}*/ | |
6c139d6e AL |
16 | #ifndef STRUTL_H |
17 | #define STRUTL_H | |
18 | ||
492f957a | 19 | #ifdef __GNUG__ |
cdcc6d34 | 20 | #pragma interface "apt-pkg/strutl.h" |
492f957a AL |
21 | #endif |
22 | ||
6c139d6e AL |
23 | #include <stdlib.h> |
24 | #include <string> | |
0a8a80e5 | 25 | #include <vector> |
492f957a | 26 | #include <time.h> |
6c139d6e AL |
27 | |
28 | char *_strstrip(char *String); | |
29 | char *_strtabexpand(char *String,size_t Len); | |
30 | bool ParseQuoteWord(const char *&String,string &Res); | |
08e8f724 | 31 | bool ParseCWord(const char *String,string &Res); |
6c139d6e | 32 | string QuoteString(string Str,const char *Bad); |
1bc849af | 33 | string DeQuoteString(string Str); |
6c139d6e AL |
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); | |
ad00ae81 | 38 | string URItoFileName(string URI); |
0a8a80e5 | 39 | string TimeRFC1123(time_t Date); |
24231681 | 40 | bool StrToTime(string Val,time_t &Result); |
0a8a80e5 AL |
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); | |
6c139d6e AL |
44 | |
45 | int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd); | |
9c14e3d6 | 46 | inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));}; |
be4401bf | 47 | inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));}; |
6c139d6e | 48 | int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd); |
9c14e3d6 | 49 | inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));}; |
be4401bf | 50 | inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));}; |
6c139d6e | 51 | |
93bf083d AL |
52 | class URI |
53 | { | |
be4401bf AL |
54 | void CopyFrom(string From); |
55 | ||
93bf083d AL |
56 | public: |
57 | ||
58 | string Access; | |
59 | string User; | |
60 | string Password; | |
61 | string Host; | |
62 | string Path; | |
63 | unsigned int Port; | |
64 | ||
492f957a | 65 | operator string(); |
be4401bf AL |
66 | inline operator =(string From) {CopyFrom(From);}; |
67 | inline bool empty() {return Access.empty();}; | |
93bf083d | 68 | |
be4401bf AL |
69 | URI(string Path) {CopyFrom(Path);}; |
70 | URI() : Port(0) {}; | |
93bf083d AL |
71 | }; |
72 | ||
6c139d6e | 73 | #endif |