strutl.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: strutl.h,v 1.12 1999/02/01 08:11:57 jgg Exp $
  4. /* ######################################################################
  5. String Util - These are some usefull string functions
  6. _strstrip is a function to remove whitespace from the front and end
  7. of a string.
  8. This source is placed in the Public Domain, do with it what you will
  9. It was originally written by Jason Gunthorpe <jgg@gpu.srv.ualberta.ca>
  10. ##################################################################### */
  11. /*}}}*/
  12. #ifndef STRUTL_H
  13. #define STRUTL_H
  14. #ifdef __GNUG__
  15. #pragma interface "apt-pkg/strutl.h"
  16. #endif
  17. #include <stdlib.h>
  18. #include <string>
  19. #include <vector>
  20. #include <time.h>
  21. char *_strstrip(char *String);
  22. char *_strtabexpand(char *String,size_t Len);
  23. bool ParseQuoteWord(const char *&String,string &Res);
  24. bool ParseCWord(const char *String,string &Res);
  25. string QuoteString(string Str,const char *Bad);
  26. string DeQuoteString(string Str);
  27. string SizeToStr(double Bytes);
  28. string TimeToStr(unsigned long Sec);
  29. string SubstVar(string Str,string Subst,string Contents);
  30. string Base64Encode(string Str);
  31. string URItoFileName(string URI);
  32. string TimeRFC1123(time_t Date);
  33. bool StrToTime(string Val,time_t &Result);
  34. string LookupTag(string Message,const char *Tag,const char *Default = 0);
  35. int StringToBool(string Text,int Default = -1);
  36. bool ReadMessages(int Fd, vector<string> &List);
  37. int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
  38. inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
  39. inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
  40. int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
  41. inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
  42. inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
  43. class URI
  44. {
  45. void CopyFrom(string From);
  46. public:
  47. string Access;
  48. string User;
  49. string Password;
  50. string Host;
  51. string Path;
  52. unsigned int Port;
  53. operator string();
  54. inline operator =(string From) {CopyFrom(From);};
  55. inline bool empty() {return Access.empty();};
  56. URI(string Path) {CopyFrom(Path);};
  57. URI() : Port(0) {};
  58. };
  59. #endif