]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/strutl.h
Join with aliencode
[apt.git] / apt-pkg / contrib / strutl.h
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
b2e465d6 3// $Id: strutl.h,v 1.16 2001/02/20 07:03:17 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;
6c139d6e
AL
56
57int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 58inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
be4401bf 59inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
6c139d6e 60int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
9c14e3d6 61inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
be4401bf 62inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
b2e465d6 63inline int stringcasecmp(string A,string B) {return stringcasecmp(A.begin(),A.end(),B.begin(),B.end());};
6c139d6e 64
93bf083d
AL
65class URI
66{
be4401bf
AL
67 void CopyFrom(string From);
68
93bf083d
AL
69 public:
70
71 string Access;
72 string User;
73 string Password;
74 string Host;
75 string Path;
76 unsigned int Port;
77
492f957a 78 operator string();
e3c43919 79 inline void operator =(string From) {CopyFrom(From);};
be4401bf 80 inline bool empty() {return Access.empty();};
b2e465d6 81 static string SiteOnly(string URI);
93bf083d 82
be4401bf
AL
83 URI(string Path) {CopyFrom(Path);};
84 URI() : Port(0) {};
93bf083d
AL
85};
86
b2e465d6
AL
87struct SubstVar
88{
89 const char *Subst;
90 const string *Contents;
91};
92string SubstVar(string Str,const struct SubstVar *Vars);
93string SubstVar(string Str,string Subst,string Contents);
94
95struct RxChoiceList
96{
97 void *UserData;
98 const char *Str;
99 bool Hit;
100};
101unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
102 const char **ListEnd);
103
104#undef APT_FORMAT2
105
6c139d6e 106#endif