Minor cleanups, fix for checksum lowercase bug
[ntk/apt.git] / apt-pkg / contrib / strutl.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
ddc1d8d0 3// $Id: strutl.h,v 1.14 1999/07/26 17:46:08 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
28char *_strstrip(char *String);
29char *_strtabexpand(char *String,size_t Len);
30bool ParseQuoteWord(const char *&String,string &Res);
08e8f724 31bool ParseCWord(const char *String,string &Res);
6c139d6e 32string QuoteString(string Str,const char *Bad);
1bc849af 33string DeQuoteString(string Str);
6c139d6e
AL
34string SizeToStr(double Bytes);
35string TimeToStr(unsigned long Sec);
36string SubstVar(string Str,string Subst,string Contents);
37string Base64Encode(string Str);
ad00ae81 38string URItoFileName(string URI);
0a8a80e5 39string TimeRFC1123(time_t Date);
24231681 40bool StrToTime(string Val,time_t &Result);
0a8a80e5
AL
41string LookupTag(string Message,const char *Tag,const char *Default = 0);
42int StringToBool(string Text,int Default = -1);
43bool ReadMessages(int Fd, vector<string> &List);
ddc1d8d0 44bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
6c139d6e
AL
45
46int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 47inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
be4401bf 48inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
6c139d6e 49int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 50inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
be4401bf 51inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
6c139d6e 52
93bf083d
AL
53class URI
54{
be4401bf
AL
55 void CopyFrom(string From);
56
93bf083d
AL
57 public:
58
59 string Access;
60 string User;
61 string Password;
62 string Host;
63 string Path;
64 unsigned int Port;
65
492f957a 66 operator string();
e3c43919 67 inline void operator =(string From) {CopyFrom(From);};
be4401bf 68 inline bool empty() {return Access.empty();};
93bf083d 69
be4401bf
AL
70 URI(string Path) {CopyFrom(Path);};
71 URI() : Port(0) {};
93bf083d
AL
72};
73
6c139d6e 74#endif