Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/qtools/qcstring.h

Source at commit 1406 created 12 years 10 months ago.
By meklort, Revert drivers.c so that kexts are only loaded when OSBundleRequired is set and that value is not safe mode. Added some comments about it too.
1/****************************************************************************
2**
3**
4** Definition of the extended char array operations,
5** and QByteArray and QCString classes
6**
7** Created : 920609
8**
9** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
10**
11** This file is part of the tools module of the Qt GUI Toolkit.
12**
13** This file may be distributed under the terms of the Q Public License
14** as defined by Trolltech AS of Norway and appearing in the file
15** LICENSE.QPL included in the packaging of this file.
16**
17** This file may be distributed and/or modified under the terms of the
18** GNU General Public License version 2 as published by the Free Software
19** Foundation and appearing in the file LICENSE.GPL included in the
20** packaging of this file.
21**
22** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
23** licenses may use this file in accordance with the Qt Commercial License
24** Agreement provided with the Software.
25**
26** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
27** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28**
29** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
30** information about Qt Commercial License Agreements.
31** See http://www.trolltech.com/qpl/ for QPL licensing information.
32** See http://www.trolltech.com/gpl/ for GPL licensing information.
33**
34** Contact info@trolltech.com if any conditions of this licensing are
35** not clear to you.
36**
37**********************************************************************/
38
39#ifndef QCSTRING_H
40#define QCSTRING_H
41
42#ifndef QT_H
43#include "qarray.h"
44#endif // QT_H
45
46#include <stdlib.h>
47#include <string.h>
48
49#if defined(_OS_SUN_) && defined(_CC_GNU_)
50#include <strings.h>
51#endif
52
53
54class QGString;
55
56/*****************************************************************************
57 Fixes and workarounds for some platforms
58 *****************************************************************************/
59
60#if defined(_OS_HPUX_)
61// HP-UX has badly defined strstr() etc.
62// ### fix in 3.0: change hack_* to qt_hack_*
63// by the way HP-UX is probably right, the standard has evolved and
64// we'll have to adapt to it
65inline char *hack_strstr( const char *s1, const char *s2 )
66{ return (char *)strstr(s1, s2); }
67inline char *hack_strchr( const char *s, int c )
68{ return (char *)strchr(s, c); }
69inline char *hack_strrchr( const char *s, int c )
70{ return (char *)strrchr(s, c); }
71#define strstr(s1,s2)hack_strstr((s1),(s2))
72#define strchr(s,c)hack_strchr((s),(c))
73#define strrchr(s,c)hack_strrchr((s),(c))
74#endif
75
76
77/*****************************************************************************
78 Safe and portable C string functions; extensions to standard string.h
79 *****************************************************************************/
80
81Q_EXPORT void *qmemmove( void *dst, const void *src, uint len );
82
83#if defined(_OS_SUN_) || defined(_CC_OC_)
84#define memmove(s1,s2,n) qmemmove((s1),(s2),(n))
85#endif
86
87Q_EXPORT char *qstrdup( const char * );
88
89Q_EXPORT inline uint cstrlen( const char *str )
90{ return strlen(str); }
91
92Q_EXPORT inline uint qstrlen( const char *str )
93{ return str ? strlen(str) : 0; }
94
95Q_EXPORT inline char *cstrcpy( char *dst, const char *src )
96{ return strcpy(dst,src); }
97
98Q_EXPORT inline char *qstrcpy( char *dst, const char *src )
99{ return src ? strcpy(dst, src) : 0; }
100
101Q_EXPORT char *qstrncpy( char *dst, const char *src, uint len );
102
103Q_EXPORT inline int cstrcmp( const char *str1, const char *str2 )
104{ return strcmp(str1,str2); }
105
106Q_EXPORT inline int qstrcmp( const char *str1, const char *str2 )
107{ return (str1 && str2) ? strcmp(str1,str2) : (int)((long)str2 - (long)str1); }
108
109Q_EXPORT inline int cstrncmp( const char *str1, const char *str2, uint len )
110{ return strncmp(str1,str2,len); }
111
112Q_EXPORT inline int qstrncmp( const char *str1, const char *str2, uint len )
113{ return (str1 && str2) ? strncmp(str1,str2,len) :
114 (int)((long)str2 - (long)str1); }
115
116Q_EXPORT int qstricmp( const char *, const char * );
117
118Q_EXPORT int qstrnicmp( const char *, const char *, uint len );
119
120// ### TODO for 3.0: these and the cstr* functions should be used if
121// !defined(QT_CLEAN_NAMESPACE)
122// We want to keep source compatibility for 2.x
123// ### TODO for 4.0: completely remove these and the cstr* functions
124
125#if !defined(QT_GENUINE_STR)
126
127#undefstrlen
128#define strlen qstrlen
129
130#undefstrcpy
131#define strcpy qstrcpy
132
133#undefstrcmp
134#define strcmp qstrcmp
135
136#undefstrncmp
137#define strncmp qstrncmp
138
139#undefstricmp
140#define stricmp qstricmp
141
142#undefstrnicmp
143#define strnicmp qstrnicmp
144
145#endif
146
147// qChecksum: Internet checksum
148
149Q_EXPORT Q_UINT16 qChecksum( const char *s, uint len );
150
151/*****************************************************************************
152 QByteArray class
153 *****************************************************************************/
154
155#if defined(Q_TEMPLATEDLL)
156template class Q_EXPORT QArray<char>;
157#endif
158typedef QArray<char> QByteArray;
159
160
161/*****************************************************************************
162 QByteArray stream functions
163 *****************************************************************************/
164#ifndef QT_NO_DATASTREAM
165Q_EXPORT QDataStream &operator<<( QDataStream &, const QByteArray & );
166Q_EXPORT QDataStream &operator>>( QDataStream &, QByteArray & );
167#endif
168
169class QRegExp;
170
171/** This is an alternative implementation of QCString. It provides basically
172 * the same functions but uses less memory for administration. This class
173 * is just a wrapper around a plain C string requiring only 4 bytes "overhead".
174 * QCString features sharing of data and stores the string length, but
175 * requires 4 + 12 bytes for this (even for the empty string). As doxygen
176 * uses a LOT of string during a run it saves a lot of memory to use a
177 * more memory efficient implementation at the cost of relatively low
178 * runtime overhead.
179 */
180class QCString
181{
182public:
183 QCString() : m_data(0) {}// make null string
184 QCString( const QCString &s );
185 QCString( int size );
186 QCString( const char *str );
187 QCString( const char *str, uint maxlen );
188 ~QCString();
189
190 QCString &operator=( const QCString &s );// deep copy
191 QCString &operator=( const char *str );// deep copy
192
193 bool isNull() const;
194 boolisEmpty()const;
195 uintlength()const;
196 uint size() const { return m_data ? length()+1 : 0; }
197 char * data() const { return m_data; }
198 boolresize( uint newlen );
199 booltruncate( uint pos );
200 boolfill( char c, int len = -1 );
201
202 QCStringcopy()const;
203
204 QCString &sprintf( const char *format, ... );
205
206 intfind( char c, int index=0, bool cs=TRUE ) const;
207 intfind( const char *str, int index=0, bool cs=TRUE ) const;
208 intfind( const QCString &str, int index=0, bool cs=TRUE ) const;
209 intfind( const QRegExp &, int index=0 ) const;
210 intfindRev( char c, int index=-1, bool cs=TRUE) const;
211 intfindRev( const char *str, int index=-1, bool cs=TRUE) const;
212 intfindRev( const QRegExp &, int index=-1 ) const;
213 intcontains( char c, bool cs=TRUE ) const;
214 intcontains( const char *str, bool cs=TRUE ) const;
215 intcontains( const QRegExp & ) const;
216 bool stripPrefix(const char *prefix);
217
218 QCStringleft( uint len ) const;
219 QCStringright( uint len ) const;
220 QCStringmid( uint index, uint len=0xffffffff) const;
221
222 QCStringlower() const;
223 QCStringupper() const;
224
225 QCStringstripWhiteSpace()const;
226 QCStringsimplifyWhiteSpace()const;
227
228 QCString &assign( const char *str );
229 QCString &insert( uint index, const char * );
230 QCString &insert( uint index, char );
231 QCString &append( const char *s );
232 QCString &prepend( const char *s );
233 QCString &remove( uint index, uint len );
234 QCString &replace( uint index, uint len, const char * );
235 QCString &replace( const QRegExp &, const char * );
236
237 shorttoShort( bool *ok=0 )const;
238 ushorttoUShort( bool *ok=0 )const;
239 inttoInt( bool *ok=0 )const;
240 uinttoUInt( bool *ok=0 )const;
241 longtoLong( bool *ok=0 )const;
242 ulongtoULong( bool *ok=0 )const;
243
244 QCString &setNum( short );
245 QCString &setNum( ushort );
246 QCString &setNum( int );
247 QCString &setNum( uint );
248 QCString &setNum( long );
249 QCString &setNum( ulong );
250 QCString &setNum( float, char f='g', int prec=6 );
251 QCString &setNum( double, char f='g', int prec=6 );
252
253operator const char *() const;
254 QCString &operator+=( const char *str );
255 QCString &operator+=( char c );
256 char &at( uint index ) const;
257 char &operator[]( int i ) const { return at(i); }
258
259 private:
260 static void msg_index( uint );
261 void duplicate( const QCString &s );
262 void duplicate( const char *str);
263 QCString &duplicate( const char *str, int);
264
265 char * m_data;
266};
267
268inline char &QCString::at( uint index ) const
269{
270 return m_data[index];
271}
272
273inline void QCString::duplicate( const QCString &s )
274{
275 if (!s.isEmpty())
276 {
277 uint l = strlen(s.data());
278 m_data = (char *)malloc(l+1);
279 if (m_data) memcpy(m_data,s.data(),l+1);
280 }
281 else
282 m_data=0;
283}
284
285inline void QCString::duplicate( const char *str)
286{
287 if (str && str[0]!='\0')
288 {
289 uint l = strlen(str);
290 m_data = (char *)malloc(l+1);
291 if (m_data) memcpy(m_data,str,l+1);
292 }
293 else
294 m_data=0;
295}
296
297inline QCString &QCString::duplicate( const char *str, int)
298{
299 if (m_data==str) return *this;
300 if (m_data) free(m_data);
301 duplicate(str);
302 return *this;
303}
304
305/*****************************************************************************
306 QCString stream functions
307 *****************************************************************************/
308#ifndef QT_NO_DATASTREAM
309Q_EXPORT QDataStream &operator<<( QDataStream &, const QCString & );
310Q_EXPORT QDataStream &operator>>( QDataStream &, QCString & );
311#endif
312
313/*****************************************************************************
314 QCString inline functions
315 *****************************************************************************/
316
317inline QCString &QCString::operator=( const QCString &s )
318{ return (QCString&)assign( s ); }
319
320inline QCString &QCString::operator=( const char *str )
321{ return (QCString&)duplicate( str, qstrlen(str)+1 ); }
322
323inline bool QCString::isNull() const
324{ return data() == 0; }
325
326inline bool QCString::isEmpty() const
327{ return data() == 0 || *data() == '\0'; }
328
329inline uint QCString::length() const
330{ return qstrlen( data() ); }
331
332inline bool QCString::truncate( uint pos )
333{ return resize(pos+1); }
334
335inline QCString QCString::copy() const
336{ return QCString( data() ); }
337
338inline QCString &QCString::prepend( const char *s )
339{ return insert(0,s); }
340
341inline QCString &QCString::append( const char *s )
342{ return operator+=(s); }
343
344inline QCString &QCString::setNum( short n )
345{ return setNum((long)n); }
346
347inline QCString &QCString::setNum( ushort n )
348{ return setNum((ulong)n); }
349
350inline QCString &QCString::setNum( int n )
351{ return setNum((long)n); }
352
353inline QCString &QCString::setNum( uint n )
354{ return setNum((ulong)n); }
355
356inline QCString &QCString::setNum( float n, char f, int prec )
357{ return setNum((double)n,f,prec); }
358
359inline QCString::operator const char *() const
360{ return (const char *)data(); }
361
362
363/*****************************************************************************
364 QCString non-member operators
365 *****************************************************************************/
366
367Q_EXPORT inline bool operator==( const QCString &s1, const QCString &s2 )
368{ return qstrcmp(s1.data(),s2.data()) == 0; }
369
370Q_EXPORT inline bool operator==( const QCString &s1, const char *s2 )
371{ return qstrcmp(s1.data(),s2) == 0; }
372
373Q_EXPORT inline bool operator==( const char *s1, const QCString &s2 )
374{ return qstrcmp(s1,s2.data()) == 0; }
375
376Q_EXPORT inline bool operator!=( const QCString &s1, const QCString &s2 )
377{ return qstrcmp(s1.data(),s2.data()) != 0; }
378
379Q_EXPORT inline bool operator!=( const QCString &s1, const char *s2 )
380{ return qstrcmp(s1.data(),s2) != 0; }
381
382Q_EXPORT inline bool operator!=( const char *s1, const QCString &s2 )
383{ return qstrcmp(s1,s2.data()) != 0; }
384
385Q_EXPORT inline bool operator<( const QCString &s1, const QCString& s2 )
386{ return qstrcmp(s1.data(),s2.data()) < 0; }
387
388Q_EXPORT inline bool operator<( const QCString &s1, const char *s2 )
389{ return qstrcmp(s1.data(),s2) < 0; }
390
391Q_EXPORT inline bool operator<( const char *s1, const QCString &s2 )
392{ return qstrcmp(s1,s2.data()) < 0; }
393
394Q_EXPORT inline bool operator<=( const QCString &s1, const char *s2 )
395{ return qstrcmp(s1.data(),s2) <= 0; }
396
397Q_EXPORT inline bool operator<=( const char *s1, const QCString &s2 )
398{ return qstrcmp(s1,s2.data()) <= 0; }
399
400Q_EXPORT inline bool operator>( const QCString &s1, const char *s2 )
401{ return qstrcmp(s1.data(),s2) > 0; }
402
403Q_EXPORT inline bool operator>( const char *s1, const QCString &s2 )
404{ return qstrcmp(s1,s2.data()) > 0; }
405
406Q_EXPORT inline bool operator>=( const QCString &s1, const char *s2 )
407{ return qstrcmp(s1.data(),s2) >= 0; }
408
409Q_EXPORT inline bool operator>=( const char *s1, const QCString &s2 )
410{ return qstrcmp(s1,s2.data()) >= 0; }
411
412Q_EXPORT inline QCString operator+( const QCString &s1, const QCString &s2 )
413{
414 QCString tmp(s1);
415 tmp += s2;
416 return tmp;
417}
418
419
420inline QCString operator+( const QCString &s1, const QGString &s2 );
421inline QCString operator+( const QGString &s1, const QCString &s2 );
422
423
424Q_EXPORT inline QCString operator+( const QCString &s1, const char *s2 )
425{
426 QCString tmp(s1);
427 tmp += s2;
428 return tmp;
429}
430
431Q_EXPORT inline QCString operator+( const char *s1, const QCString &s2 )
432{
433 QCString tmp(s1);
434 tmp += s2;
435 return tmp;
436}
437
438Q_EXPORT inline QCString operator+( const QCString &s1, char c2 )
439{
440 QCString tmp( s1.data() );
441 tmp += c2;
442 return tmp;
443}
444
445Q_EXPORT inline QCString operator+( char c1, const QCString &s2 )
446{
447 QCString tmp;
448 tmp += c1;
449 tmp += s2;
450 return tmp;
451}
452
453inline const char *qPrint(const char *s)
454{
455 if (s) return s; else return "";
456}
457
458inline const char *qPrint(const QCString &s)
459{
460 if (!s.isEmpty()) return s.data(); else return "";
461}
462
463
464#endif // QCSTRING_H
465

Archive Download this file

Revision: 1406