]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/strutl.h
fixed typo in fileutl.cc (damn you, studly caps...)
[apt.git] / apt-pkg / contrib / strutl.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
f8081133 3// $Id: strutl.h,v 1.17 2001/02/23 05:45:27 jgg Exp $
6c139d6e
AL
4/* ######################################################################
5
b2e465d6 6 String Util - These are some useful string functions
6c139d6e
AL
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 27
b2e465d6
AL
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
6c139d6e
AL
35char *_strstrip(char *String);
36char *_strtabexpand(char *String,size_t Len);
37bool ParseQuoteWord(const char *&String,string &Res);
b2e465d6 38bool ParseCWord(const char *&String,string &Res);
6c139d6e 39string QuoteString(string Str,const char *Bad);
1bc849af 40string DeQuoteString(string Str);
6c139d6e
AL
41string SizeToStr(double Bytes);
42string TimeToStr(unsigned long Sec);
6c139d6e 43string Base64Encode(string Str);
ad00ae81 44string URItoFileName(string URI);
0a8a80e5 45string TimeRFC1123(time_t Date);
24231681 46bool StrToTime(string Val,time_t &Result);
0a8a80e5
AL
47string LookupTag(string Message,const char *Tag,const char *Default = 0);
48int StringToBool(string Text,int Default = -1);
49bool ReadMessages(int Fd, vector<string> &List);
ddc1d8d0 50bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
6e52073f
AL
51bool Hex2Num(const char *Start,const char *End,unsigned char *Num,
52 unsigned int Length);
b2e465d6
AL
53bool TokSplitString(char Tok,char *Input,char **List,
54 unsigned long ListMax);
55void ioprintf(ostream &out,const char *format,...) APT_FORMAT2;
f8081133 56bool CheckDomainList(string Host,string List);
6c139d6e
AL
57
58int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 59inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
be4401bf 60inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
6c139d6e 61int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 62inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
be4401bf 63inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
b2e465d6 64inline int stringcasecmp(string A,string B) {return stringcasecmp(A.begin(),A.end(),B.begin(),B.end());};
6c139d6e 65
93bf083d
AL
66class URI
67{
be4401bf
AL
68 void CopyFrom(string From);
69
93bf083d
AL
70 public:
71
72 string Access;
73 string User;
74 string Password;
75 string Host;
76 string Path;
77 unsigned int Port;
78
492f957a 79 operator string();
e3c43919 80 inline void operator =(string From) {CopyFrom(From);};
be4401bf 81 inline bool empty() {return Access.empty();};
b2e465d6 82 static string SiteOnly(string URI);
93bf083d 83
be4401bf
AL
84 URI(string Path) {CopyFrom(Path);};
85 URI() : Port(0) {};
93bf083d
AL
86};
87
b2e465d6
AL
88struct SubstVar
89{
90 const char *Subst;
91 const string *Contents;
92};
93string SubstVar(string Str,const struct SubstVar *Vars);
94string SubstVar(string Str,string Subst,string Contents);
95
96struct RxChoiceList
97{
98 void *UserData;
99 const char *Str;
100 bool Hit;
101};
102unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
103 const char **ListEnd);
104
105#undef APT_FORMAT2
106
6c139d6e 107#endif