strutl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: strutl.h,v 1.2 1999/10/24 06:53:12 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 "dsync/strutl.h"
  16. #endif
  17. #include <stdlib.h>
  18. #include <string>
  19. #include <vector>
  20. #include <time.h>
  21. #include <string.h>
  22. using namespace std;
  23. char *_strstrip(char *String);
  24. char *_strtabexpand(char *String,size_t Len);
  25. bool ParseQuoteWord(const char *&String,string &Res);
  26. bool ParseCWord(const char *String,string &Res);
  27. string QuoteString(string Str,const char *Bad);
  28. string DeQuoteString(string Str);
  29. string SizeToStr(double Bytes);
  30. string TimeToStr(unsigned long Sec);
  31. string SubstVar(string Str,string Subst,string Contents);
  32. string Base64Encode(string Str);
  33. string URItoFileName(string URI);
  34. string TimeRFC1123(time_t Date);
  35. bool StrToTime(string Val,time_t &Result);
  36. string LookupTag(string Message,const char *Tag,const char *Default = 0);
  37. int StringToBool(string Text,int Default = -1);
  38. bool ReadMessages(int Fd, vector<string> &List);
  39. bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
  40. bool Hex2Num(const char *Start,const char *End,unsigned char *Num,
  41. unsigned int Length);
  42. int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
  43. inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
  44. inline int stringcmp(string A,const char *B) {return stringcmp(A.c_str(),A.c_str()+strlen(A.c_str()),B,B+strlen(B));};
  45. int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
  46. inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
  47. inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.c_str(),A.c_str()+strlen(A.c_str()),B,B+strlen(B));};
  48. class URI
  49. {
  50. void CopyFrom(string From);
  51. public:
  52. string Access;
  53. string User;
  54. string Password;
  55. string Host;
  56. string Path;
  57. unsigned int Port;
  58. operator string();
  59. inline void operator =(string From) {CopyFrom(From);};
  60. inline bool empty() {return Access.empty();};
  61. URI(string Path) {CopyFrom(Path);};
  62. URI() : Port(0) {};
  63. };
  64. #endif