1 /*
2 * ===========================
3 * VDK Visual Development Kit
4 * Version 1.2.3
5 * October 1998, August 2000
6 * ===========================
7 *
8 * Copyright (C) 1998, Mario Motta
9 * Developed by Mario Motta <mmotta@guest.net>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 * 02111-130
25 */
26 
27 #ifndef VDKSTRING_H
28 #define VDKSTRING_H
29 
30 // No, users still can use it without a warning... V 2.5.0
31 //#warning "VDKString use is obsolete, use VDKUString instead."
32 
33 #define MAXPRINTFLEN	65535	// max size for Sprintf and Concatf buffer
34 #define INT_DATE		0		// for FormatDate
35 #define ENG_DATE		1
36 #define EUR_DATE		2
37 
38 struct STRING
39 {
40 	char* s;
41 	unsigned int ref ;
42 };
43 
44 /*!
45 \class VDKString
46 \brief Implements famous cont referenced string objects
47 This string object is deprecated and should not be used in newly written code,
48 use VDKUString instead.
49 */
50 class VDKString
51 {
52 protected:
53 	STRING* p;
54 public:
55 /*!
56 Constructor, makes an empty string
57 \code
58 VDKString s;
59 \endcode
60 */
61 	VDKString();
62 /*!
63 Constructor
64 \param s a null terminated C string
65 \code
66 VDKString s = "uncle bill";
67 \endcode
68 */
69 
70 	VDKString (const char*s);
71 /*!
72 Constructor
73 \param c a single character
74 \code
75 VDKString s(c);
76 \endcode
77 */
78 
79 	VDKString (const char& c);
80 /*!
81 Copy-initializer
82 \param s a VDKString reference
83 \code
84 VDKString s = "uncle bill";
85 VDKString s1 = s;
86 \endcode
87 */
88 
89 	VDKString(const VDKString& s);
90 
91 /*!
92 Destructor
93 */
94 	~VDKString();
95 /*!
96 Assignement operator
97 \param s a VDKString reference
98 \code
99 VDKString s = "uncle bill";
100 VDKString s1 = s;
101 VDKString s2 = "uncle sam";
102 s = s2;
103 \endcode
104 */
105 	VDKString& operator = (const VDKString& s);
106 
107 /*!
108 Assignement operator
109 \param s a null terminated C string
110 \code
111 VDKString s = "uncle bill";
112 s = "uncle sam";
113 \endcode
114 */
115 	VDKString& operator = (const char* s);
116 
117 /*!
118 VDKString to char* casting
119 ** warning ** can violate data hiding OO concept
120 */
121 	operator char*() { return p->s; }
122 
123 /*!
124 Equality operator
125 */
126 	int operator == (const VDKString& s) const ;
127 /*!
128 less than operator
129 */
130 	int operator < (const VDKString& s) const ;
131 /*!
132 greater than operator
133 */
134 	int operator > (const VDKString& s)  const ;
135 /*!
136 less-equal operator
137 */
138 	int operator <= (const VDKString& s) const ;
139 /*!
140 greater-equal operator
141 */
142 	int operator >= (const VDKString& s) const ;
143 /*!
144 disequality operator
145 */
146 	int operator != (const VDKString& s) const ;
147 /*!
148 cat to this
149 \param s a null terminated string
150 \code
151 VDKString s = "uncle bill";
152 s += " is a smart boy";
153 \endcode
154 */
155 	VDKString& operator += (const char* s);
156 /*!
157 cat to this
158 \param s a VDKString
159 \code
160 VDKString s = "uncle bill";
161 VDKString s1 = " is a smart boy";
162 s += s1;
163 \endcode
164 */
165 	VDKString& operator += (const VDKString& s);
166 /*!
167 Returns a VDKString concatenated\param s a null terminated string
168 \code
169 VDKString s = "uncle bill";
170 VDKString s1 = s + " is a smart boy";
171 \endcode
172 */
173 	VDKString operator + (const char* s) const;
174 	friend VDKString operator + (const char* s, const VDKString& vdks);
175 /*!
176 Returns a VDKString concatenated
177 \param s a VDKString
178 */
179 	VDKString operator + (const VDKString& s) const;
180 /*!
181 Returns true if this is an empty string
182 */
183 	bool isNull() const;
184 /*!
185 as strlen()
186 */
187 	int size() const;
188 /*!
189 index operator for const instances returns NULL if ix >= size
190 */
191 	char operator [] (unsigned int ix) const;
192 /*!
193 string pointer access for const instances
194 */
195 	const char* c_str() const;
196 /*!
197 Removes a part of the string, beginning at 'begin' on 'len' length.
198 Modifies and returns the resulting VDKString.
199 \param begin char number where begins the selection (0 based)
200 \param len   selection length
201 */
202 	VDKString& DelSelection(unsigned int begin, unsigned int len);
203 /*!
204 Removes all trailing spaces.
205 Modifies and returns the resulting VDKString.
206 */
207 	VDKString& RTrim();
208 /*!
209 Removes all leading spaces.
210 Modifies and returns the resulting VDKString.
211 */
212 	VDKString& LTrim();
213 /*!
214 Removes all leading and trailing spaces.
215 Modifies and returns the resulting VDKString.
216 */
217 	VDKString& Trim();
218 /*!
219 Returns the number of the specified char 'car' contained in the string.
220 \param car char to be counted
221 \code
222 VDKString s = "uncle bill";
223 int NumCar = s.CharCount('l');	// NumCar value is 3
224 \endcode
225 */
226 	unsigned int CharCount(const char car) const;
227 /*!
228 Returns the number of the specified string 'str' contained in the string.
229 \param str string to be counted
230 \code
231 VDKString s = "uncle bill brother bill";
232 int NumCar = s.CharCount("bill");	// NumCar value is 2
233 \endcode
234 */
235 	unsigned int CharCount(const char *str) const;
236 /*!
237 Returns the upper case VDKString after having modify it.
238 \warning Does not modify unknown characters.
239 \warning Upper case characters are assumed without accents.
240 */
241 	VDKString& UpperCase();
242 /*!
243 Returns the lower case VDKString after having modify it.
244 \warning Upper case characters are assumed without accents.
245 */
246 	VDKString& LowerCase();
247 /*!
248 Returns true if this is an empty string meaning
249 NULL buffer or strlen() == 0.
250 */
251 	bool isEmpty() const;
252 /*!
253 Strcat() to the existing string (printf style).
254 Modifies and returns the resulting VDKString.
255 \warning Final string is 65534 chars max.
256 \warning Returns the previous string in case of memory overflow
257 or buffer overflow.
258 \param format	a NULL terminated string
259 \param ...		a list of parameters
260 \code
261 VDKString s = "uncle bill";
262 s.Concatf("%s", " is a smart boy");	// s value is "uncle bill is a smart boy"
263 \endcode
264 */
265 	VDKString& Concatf(const char* format, ...);
266 /*!
267 Assignment to string (printf style).
268 Modifies and returns the resulting VDKString.
269 \warning Final string is 65534 chars max.
270 \warning Returns the previous string in case of memory overflow
271 or buffer overflow.
272 \param format	a NULL terminated string
273 \param ...		a list of parameters
274 \code
275 VDKString s;
276 s.Sprintf("%s is %d years old", "uncle bill", 40);	// s value is "uncle bill is 40 years old"
277 \endcode
278 */
279 	VDKString& Sprintf(const char* format, ...);
280 /*!
281 Extract the specified part of a formatted string.
282 Modifies and returns the resulting VDKString.
283 \warning Returns an isNull() string if the specified part not found.
284 \param i	the desired part position (starting at 1)
285 \param sep	the parts separator, '|' by default
286 \code
287 VDKString s = "one|two|three|four";
288 VDKString p = s;
289 p.GetPart(2);		// p value is "two"
290 \endcode
291 */
292 	VDKString& GetPart(unsigned int i, const char sep = '|');
293 /*!
294 Extract the specified part of a formatted string.
295 Modifies and returns the resulting VDKString.
296 \warning Returns an isNull() string if the specified part not found.
297 \param i	the desired part position (starting at 1)
298 \param sep	the parts separator, "|" by default
299 \code
300 VDKString s = "one#!#two#!#three#!#four";
301 VDKString p = s;
302 p.GetPart(2, "#!#");		// p value is "two"
303 \endcode
304 */
305 	VDKString& GetPart(unsigned int i, const char *sep = "|");
306 /*!
307 Returns the first occurrence position of the specified char 'car' (0 based)
308 or -1 if 'car ' not found.
309 \param car char to be searched for
310 */
311 	int GetFCharPos(const char car) const;
312 /*!
313 Returns the last occurrence position of the specified char 'car' (0 based)
314 or -1 if 'car ' not found.
315 \param car char to be searched for
316 */
317 	int GetLCharPos(const char car) const;
318 /*!
319 Returns the converted string to double.
320 See atof() for details.
321 */
322 	double StrtoDouble() const;
323 /*!
324 Returns the converted string to int.
325 See atoi() for details.
326 */
327 	int StrtoInt() const;
328 /*!
329 Extract a part of the string beginning at 'start' upon 'len' length.
330 Modifies and returns the resulting VDKString.
331 \param start	first char position  (0 based)
332 \param len		maximum length of the resulting string
333 */
334 	VDKString& SubStr(unsigned int start, unsigned int len);
335 /*!
336 Cut the string at 'len' length.
337 Modifies and returns the resulting VDKString.
338 \param len		length of the resulting string
339 */
340 	VDKString& Cut(unsigned int len);
341 /*!
342 Pad left of string with a specified char 'car' upon 'len' length.
343 Modifies and returns the resulting VDKString.
344 \param len		length of the resulting string
345 \param car		char to be padded
346 */
347 	VDKString& LPad(unsigned int len, const char car);
348 /*!
349 Pad right of string with a specified char 'car' upon 'len' length.
350 Modifies and returns the resulting VDKString.
351 \param len		length of the resulting string
352 \param car		char to be padded
353 */
354 	VDKString& RPad(unsigned int len, const char car);
355 /*!
356 Double all 'car' chars in the string (for SQL purpose).
357 Modifies and returns the resulting VDKString.
358 \param car		char to be doubled, '\'' (cote) by default
359 \code
360 VDKString s = "Don't do that";
361 VDKString p = s;
362 p.DoublaChar(); // p value is "Don''t do that"
363 \endcode
364 */
365 	VDKString& DoubleChar(const char car = '\'');
366 /*!
367 Replace all 'torep' chars in the string (for Windows/Unix compatibility purpose).
368 Modifies and returns the resulting VDKString.
369 \param torep		char to be replaced, '\\' (antislash) by default
370 \param rep			char to replace torep, '\\' (slash) by default
371 \code
372 VDKString s = "c:\\windows\\foo.txt";
373 VDKString p = s;
374 p.ReplaceChar(); // p value is "c:/windows/foo.txt"
375 \endcode
376 */
377 	VDKString& ReplaceChar(const char torep = '\\', const char rep = '/');
378 /*!
379 Returns a VDKString containing a formatted date according to
380 parameters settings.
381 Modifies and returns the resulting VDKString.
382 \warning Only complete dates are supported.
383 That's to say days and months on two digits
384 and years on 4 digits. For ex. : 02/03/2000.
385 \param sep	desired separator. If 0, no separator left
386 \param orig	date style staying in VDKString buffer
387 \param ret	date style to return
388 \code
389 VDKString s = "12/25/2000";
390 VDKString p = s;
391 p.FormatDate(0, ENG_DATE, INT_DATE); // p value is "20001225"
392 
393 VDKString s = "12/25/2000";
394 VDKString p = s;
395 p.FormatDate('-', ENG_DATE, EUR_DATE); // p value is "25-12-2000"
396 \endcode
397 */
398 	VDKString& FormatDate(const char sep, int orig, int ret);
399 };
400 
401 #endif
402 
403 
404 
405 
406