00001
00002
00003
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
00024 #define c4_String CString
00025 #elif _MSC_VER >= 1300
00026
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
00124
00125
00126 const c4_String& operator+= (const c4_String& s);
00127 const c4_String& operator+= (const char* s);
00128
00129
00130 int GetLength() const;
00131 bool IsEmpty() const;
00132 void Empty();
00133
00134 c4_String Mid(int nFirst, int nCount =25000) const;
00135 c4_String Left(int nCount) const;
00136 c4_String Right(int nCount) const;
00137
00138 friend bool operator== (const c4_String&, const c4_String&);
00139 friend bool operator!= (const c4_String&, const c4_String&);
00140
00141
00142
00143 int Compare(const char* str) const;
00144 int CompareNoCase(const char* str) const;
00145
00146 bool operator< (const c4_String& str) const;
00147
00148 int Find(char ch) const;
00149 int ReverseFind(char ch) const;
00150 int FindOneOf(const char* set) const;
00151
00152 int Find(const char* sub) const;
00153
00154 c4_String SpanIncluding(const char* set) const;
00155 c4_String SpanExcluding(const char* set) const;
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__