summaryrefslogtreecommitdiffstats
path: root/akregator/src/mk4storage/metakit/include/mk4str.h
blob: 7124a29ea2b38fd51f29bdd3140a872bffa290dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// mk4str.h --
// $Id$
// This is part of Metakit, see http://www.equi4.com/metakit/

/** @file
 * Declarations of the string package.
 */

#ifndef __MK4STR_H__
#define __MK4STR_H__

/////////////////////////////////////////////////////////////////////////////

#if q4_MFC                      // Microsoft Foundation Classes

#ifdef _WINDOWS
#include <afxwin.h>
#else
#include <afxcoll.h>
#endif

#if _MSC_VER == 800
// MSVC 1.52 thinks a typedef has no constructor, use define instead
#define c4_String CString
#elif _MSC_VER >= 1300
// VC 7.0 does not like "class" (6-2-2002, Zhang Dehua)
typedef CString c4_String;
#else
typedef class CString c4_String;
#endif

#elif q4_STD                    // STL and standard strings

#include <string>

#if !defined (d4_std)           // the default is to use namespaces
#define d4_std std
#endif

    /// STL-based string class, modeled after the MFC version
class c4_String : public d4_std::string
{
    typedef d4_std::string string;

public:
    c4_String ();
    c4_String (char ch, int nDup =1);
    c4_String (const char* str);
    c4_String (const void* ptr, int len);
    c4_String (const d4_std::string& s);
    c4_String (const c4_String& s);
    ~c4_String ();

    const c4_String& operator= (const c4_String&);

    operator const char* () const;

    char operator[] (int i) const;
    
    friend c4_String operator+ (const c4_String&, const c4_String&);
    friend c4_String operator+ (const c4_String&, const char*);
    friend c4_String operator+ (const char*, const c4_String&);

    const c4_String& operator+= (const c4_String& s);
    const c4_String& operator+= (const char* s);
    
    int GetLength() const;
    bool IsEmpty() const;
    void Empty();
    
    c4_String Mid(int nFirst, int nCount =25000) const;
    c4_String Left(int nCount) const;
    c4_String Right(int nCount) const;
                    
    int Compare(const char* str) const;
    int CompareNoCase(const char* str) const;
    
    bool operator< (const c4_String& str) const;

    int Find(char ch) const;
    int ReverseFind(char ch) const;
    int FindOneOf(const char* set) const;
    
    int Find(const char* sub) const;
    
    c4_String SpanIncluding(const char* set) const;
    c4_String SpanExcluding(const char* set) const;
};

bool operator== (const c4_String&, const c4_String&);
bool operator!= (const c4_String&, const c4_String&);
    
d4_inline bool operator== (const c4_String& s1, const char* s2);
d4_inline bool operator== (const char* s1, const c4_String& s2);

d4_inline bool operator!= (const c4_String& s1, const char* s2);
d4_inline bool operator!= (const char* s1, const c4_String& s2);

#else                           // Universal replacement classes

    /// An efficient string class, modeled after the MFC version
class c4_String
{
public:
    c4_String ();
    c4_String (char ch, int nDup =1);
    c4_String (const char* str);
    c4_String (const unsigned char* str);
    c4_String (const void* ptr, int len);
    c4_String (const c4_String& s);
    ~c4_String ();

    const c4_String& operator= (const c4_String&);

    operator const char* () const;
    operator const unsigned char* () const;
    
    char operator[] (int i) const;
    
    friend c4_String operator+ (const c4_String&, const c4_String&);
    friend c4_String operator+ (const c4_String&, const char*);
    friend c4_String operator+ (const char*, const c4_String&);
//  friend c4_String operator+ (const c4_String&, char);
//  friend c4_String operator+ (char, const c4_String&);

    const c4_String& operator+= (const c4_String& s);
    const c4_String& operator+= (const char* s);
//  const c4_String& operator+= (char c);
    
    int GetLength() const;
    bool IsEmpty() const;
    void Empty(); // free up the data
    
    c4_String Mid(int nFirst, int nCount =25000) const;
    c4_String Left(int nCount) const; // first nCount chars
    c4_String Right(int nCount) const; // last nCount chars
                    
    friend bool operator== (const c4_String&, const c4_String&); // memcmp
    friend bool operator!= (const c4_String&, const c4_String&); // opposite
    
        // only defined for strings having no zero bytes inside them:
        
    int Compare(const char* str) const; // strcmp
    int CompareNoCase(const char* str) const; // stricmp
    
    bool operator< (const c4_String& str) const;

    int Find(char ch) const; // strchr
    int ReverseFind(char ch) const; // strrchr
    int FindOneOf(const char* set) const; // strpbrk
    
    int Find(const char* sub) const; // strstr
    
    c4_String SpanIncluding(const char* set) const; // strspn
    c4_String SpanExcluding(const char* set) const; // strcspn
    
private:
    void Init(const void* p, int n);
    const char* Data() const;
    int FullLength() const;
    
    unsigned char* _value;
};

bool operator== (const c4_String& s1, const char* s2);
bool operator== (const char* s1, const c4_String& s2);

bool operator!= (const c4_String& s1, const char* s2);
bool operator!= (const char* s1, const c4_String& s2);

#endif // q4_MFC elif q4_STD else q4_UNIV

/////////////////////////////////////////////////////////////////////////////

#if q4_INLINE
#include "mk4str.inl"
#endif

/////////////////////////////////////////////////////////////////////////////

#endif // __MK4STR_H__