Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mk4str.h

Go to the documentation of this file.
00001 // mk4str.h --
00002 // $Id: mk4str.h,v 1.7 2003/11/23 01:42:50 wcvs Exp $
00003 // This is part of Metakit, see https://www.equi4.com/metakit/
00004 
00009 #ifndef __MK4STR_H__
00010 #define __MK4STR_H__
00011 
00013 
00014 #if q4_MFC                      // Microsoft Foundation Classes
00015 
00016 #ifdef _WINDOWS
00017 #include <afxwin.h>
00018 #else
00019 #include <afxcoll.h>
00020 #endif
00021 
00022 #if _MSC_VER == 800
00023 // MSVC 1.52 thinks a typedef has no constructor, use define instead
00024 #define c4_String CString
00025 #elif _MSC_VER >= 1300
00026 // VC 7.0 does not like "class" (6-2-2002, Zhang Dehua)
00027 typedef CString c4_String;
00028 #else
00029 typedef class CString c4_String;
00030 #endif
00031 
00032 #elif q4_STD                    // STL and standard strings
00033 
00034 #include <string>
00035 
00036 #if !defined (d4_std)           // the default is to use namespaces
00037 #define d4_std std
00038 #endif
00039 
00041 class c4_String : public d4_std::string
00042 {
00043     typedef d4_std::string string;
00044 
00045 public:
00046     c4_String ();
00047     c4_String (char ch, int nDup =1);
00048     c4_String (const char* str);
00049     c4_String (const void* ptr, int len);
00050     c4_String (const d4_std::string& s);
00051     c4_String (const c4_String& s);
00052     ~c4_String ();
00053 
00054     const c4_String& operator= (const c4_String&);
00055 
00056     operator const char* () const;
00057 
00058     char operator[] (int i) const;
00059     
00060     friend c4_String operator+ (const c4_String&, const c4_String&);
00061     friend c4_String operator+ (const c4_String&, const char*);
00062     friend c4_String operator+ (const char*, const c4_String&);
00063 
00064     const c4_String& operator+= (const c4_String& s);
00065     const c4_String& operator+= (const char* s);
00066     
00067     int GetLength() const;
00068     bool IsEmpty() const;
00069     void Empty();
00070     
00071     c4_String Mid(int nFirst, int nCount =25000) const;
00072     c4_String Left(int nCount) const;
00073     c4_String Right(int nCount) const;
00074                     
00075     int Compare(const char* str) const;
00076     int CompareNoCase(const char* str) const;
00077     
00078     bool operator< (const c4_String& str) const;
00079 
00080     int Find(char ch) const;
00081     int ReverseFind(char ch) const;
00082     int FindOneOf(const char* set) const;
00083     
00084     int Find(const char* sub) const;
00085     
00086     c4_String SpanIncluding(const char* set) const;
00087     c4_String SpanExcluding(const char* set) const;
00088 };
00089 
00090 bool operator== (const c4_String&, const c4_String&);
00091 bool operator!= (const c4_String&, const c4_String&);
00092     
00093 d4_inline bool operator== (const c4_String& s1, const char* s2);
00094 d4_inline bool operator== (const char* s1, const c4_String& s2);
00095 
00096 d4_inline bool operator!= (const c4_String& s1, const char* s2);
00097 d4_inline bool operator!= (const char* s1, const c4_String& s2);
00098 
00099 #else                           // Universal replacement classes
00100 
00102 class c4_String
00103 {
00104 public:
00105     c4_String ();
00106     c4_String (char ch, int nDup =1);
00107     c4_String (const char* str);
00108     c4_String (const unsigned char* str);
00109     c4_String (const void* ptr, int len);
00110     c4_String (const c4_String& s);
00111     ~c4_String ();
00112 
00113     const c4_String& operator= (const c4_String&);
00114 
00115     operator const char* () const;
00116     operator const unsigned char* () const;
00117     
00118     char operator[] (int i) const;
00119     
00120     friend c4_String operator+ (const c4_String&, const c4_String&);
00121     friend c4_String operator+ (const c4_String&, const char*);
00122     friend c4_String operator+ (const char*, const c4_String&);
00123 //  friend c4_String operator+ (const c4_String&, char);
00124 //  friend c4_String operator+ (char, const c4_String&);
00125 
00126     const c4_String& operator+= (const c4_String& s);
00127     const c4_String& operator+= (const char* s);
00128 //  const c4_String& operator+= (char c);
00129     
00130     int GetLength() const;
00131     bool IsEmpty() const;
00132     void Empty(); // free up the data
00133     
00134     c4_String Mid(int nFirst, int nCount =25000) const;
00135     c4_String Left(int nCount) const; // first nCount chars
00136     c4_String Right(int nCount) const; // last nCount chars
00137                     
00138     friend bool operator== (const c4_String&, const c4_String&); // memcmp
00139     friend bool operator!= (const c4_String&, const c4_String&); // opposite
00140     
00141         // only defined for strings having no zero bytes inside them:
00142         
00143     int Compare(const char* str) const; // strcmp
00144     int CompareNoCase(const char* str) const; // stricmp
00145     
00146     bool operator< (const c4_String& str) const;
00147 
00148     int Find(char ch) const; // strchr
00149     int ReverseFind(char ch) const; // strrchr
00150     int FindOneOf(const char* set) const; // strpbrk
00151     
00152     int Find(const char* sub) const; // strstr
00153     
00154     c4_String SpanIncluding(const char* set) const; // strspn
00155     c4_String SpanExcluding(const char* set) const; // strcspn
00156     
00157 private:
00158     void Init(const void* p, int n);
00159     const char* Data() const;
00160     int FullLength() const;
00161     
00162     unsigned char* _value;
00163 };
00164 
00165 bool operator== (const c4_String& s1, const char* s2);
00166 bool operator== (const char* s1, const c4_String& s2);
00167 
00168 bool operator!= (const c4_String& s1, const char* s2);
00169 bool operator!= (const char* s1, const c4_String& s2);
00170 
00171 #endif // q4_MFC elif q4_STD else q4_UNIV
00172 
00174 
00175 #if q4_INLINE
00176 #include "mk4str.inl"
00177 #endif
00178 
00180 
00181 #endif // __MK4STR_H__


Metakit C++ API Reference - https://www.equi4.com/metakit.html - extracted with Doxygen