/** * $Id: mstring.h,v 1.22 2002/10/31 22:34:46 plasmahh Exp $ * $Revision: 1.22 $ * $Author: plasmahh $ * $Date: 2002/10/31 22:34:46 $ */ #ifndef __MSTRING_H #define __MSTRING_H #include using namespace std; #include #include #include // mainly for NetBSD compatibility #ifndef __DEFINES_H #include "defines.h" #endif #ifndef __TYPES_H #include "types.h" #endif class Exception; class x_mem; class x_implemented; extern "C" { #include } enum checksum_type { SUM, CRC8, CRC16, CRC32, CHECK8, CHECK16, CHECK32, MD5, SHA1 }; /** * @short small mstring class with basic functionality * * This mstring class tries to be as small & as fast as possible * I hope it will also be secure, although there are not * much security checks performed */ class mstring { private: /// polonger to the c-mstring, that really holds the mstring char * sp; /// we keep the length here in addition to some strlen() functions unsigned long leng; protected: public: /** * this constructor creates an empty mstring */ mstring ( ); /** * this creates a mstring of another mstring */ mstring ( const mstring & ); /** * an this constructor creates a mstring of the good old c-mstring */ mstring ( const char * ); mstring ( const uchar8 * v ); inline ~mstring() { if (sp) delete[] sp; } /** * returns the length of the saved mstring * @return length of mstring object */ inline unsigned long length( void ) const { return leng; } /** * @return if the string is empty or not */ inline bool empty( void ) { return (leng == 0); } mstring& operator += ( const mstring& v); mstring& operator += ( const char * v); inline mstring& operator += ( const uchar8 * v) { return operator+=((const char*) v); } mstring& operator = ( const mstring& v); mstring& operator = ( const char * v); bool operator == ( const mstring& v); bool operator == ( const char * v); /** * if one string is smaller than another * (similar to strcmp()) * @return true if left is smaller * @note this operator is inline, and its definition is here because * in .cpp it will not be found by other .o when linking. */ bool operator > ( const mstring& v) const; bool operator > ( const char * v) const; bool operator < ( const mstring& v) const; bool operator < ( const char * v) const; bool operator <= ( const mstring& v); bool operator <= ( const char * v); bool operator >= ( const mstring& v); bool operator >= ( const char * v); bool operator != ( const mstring& v); bool operator != ( const char * v); //mstring& operator(unsigned long posa, unsigned long posb) char operator() (unsigned long pos) const; char * operator[] (unsigned long pos); operator const char * () const { return sp; } operator const uchar8 * () const { return (const uchar8*)sp; } unsigned long lsearch( const char * v ,unsigned long spos=0) const; unsigned long lsearch( const mstring& v ,unsigned long spos=0) const; long rsearch( char * v ,unsigned long spos=0); long rsearch( mstring& v ,unsigned long spos=0); long indexof( char v); bool matches( const char * v , unsigned long pos=0) const; bool matches( const mstring& v , unsigned long pos=0) const; unsigned long checksum ( checksum_type type) const; unsigned long checksum_sum( void ) const; mstring substring( unsigned long anf, unsigned long end) const; /// only at beginning and end mstring strip_whitespaces( void ); /// everywhere mstring strip_all_whitespaces( void ); mstring& format( const char* fmtstr, ... ); friend mstring operator + ( const mstring&, const mstring&); friend mstring operator * ( uint32 v, const mstring& g); //friend bool operator < ( const mstring& a, const mstring& b); friend ostream& operator << ( ostream & o, const mstring& v); //friend mstring operator + ( const char[], const char[]); }; #else #warning Multiple inclusion of mstring.h, please cheak your includes #endif /** *$Log: mstring.h,v $ *Revision 1.22 2002/10/31 22:34:46 plasmahh *mstring fix * *Revision 1.21 2002/10/21 08:37:21 plasmahh *beginning cleanup for smtpmap release 0.8-stable * *Revision 1.20 2002/10/16 23:07:22 plasmahh *fixed memory bugs in mstring *TODO : refine of exception structure * *Revision 1.19 2002/10/01 21:06:24 plasmahh *new math things * *Revision 1.18 2002/08/15 20:40:32 plasmahh *new string manipulation functions * *Revision 1.17 2002/08/12 13:15:26 plasmahh *removed some memory leaks * *Revision 1.16 2002/08/08 20:45:53 plasmahh *some slight changes * *Revision 1.15 2002/06/11 14:17:05 plasmahh *Added operators. *Fixed sorting bug which destroyed origin list * *Revision 1.14 2002/06/10 22:10:54 plasmahh * added operators and fixed some sorting things * *Revision 1.13 2002/06/10 11:12:17 plasmahh *added namespace std using for new strict g++ compiler suites * *Revision 1.12 2002/06/09 21:23:22 plasmahh *changed a few things that might be bugs * *Revision 1.11 2002/05/28 18:47:40 plasmahh *added more or less safe format function to the mstring class *introduced a parser class *some new cool exceptions * *Revision 1.10 2002/05/23 19:48:08 plasmahh *removed some compiler warnings. *fixed one or two bugs. *refined include structure, for faster compiling *hm, what else ? don't know, I hope this works all ;) * *Revision 1.9 2002/05/15 19:41:16 plasmahh *fixed segfault bug in substring function * *Revision 1.8 2002/05/15 07:07:10 plasmahh *Added search functions to string class *played a bit ;) * *Revision 1.7 2002/05/14 16:31:13 plasmahh *Removed some compiler warnings *Added more code, hopefully fast ;) * *Revision 1.6 2002/05/13 12:58:47 plasmahh *Some improvements and missing implementations * *Revision 1.5 2002/05/05 20:24:36 plasmahh *added doygen configuration file *made dllist work *added dlliterator to dllist.h *made some test progams cooler ;) *added some exceptions... *anything else to do ?? *G* * *Revision 1.4 2002/04/30 21:35:17 plasmahh *first working exceptions *first working strings, not everything implemented, should also be tested ! * *Revision 1.3 2002/04/30 19:34:06 plasmahh *fixed segfault with new gcc/g++ compilers * *Revision 1.2 2002/04/29 22:59:08 plasmahh *implemented some parts of string class * *Revision 1.1 2002/04/29 18:51:29 plasmahh *Renamed string to mstring in order to avoid conflicts with standard libraries * *Revision 1.4 2002/04/29 18:20:23 plasmahh *some small changes in definitions * *Revision 1.3 2002/04/18 22:54:33 plasmahh *- Added defines.h for some global definitions *- Introduced _FAST_ and _SAFE_ defines for some compilation control *- Added some mstring.h operator prototypes * *Revision 1.2 2002/04/16 23:52:27 plasmahh *First prototypes for mstring class * *Revision 1.1 2002/04/16 20:46:02 plasmahh *Added mstring class and test program * */