Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/qtools/scstring.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 * Copyright (C) 1997-2004 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef SCSTRING_H
17#define SCSTRING_H
18
19#include <stdlib.h>
20
21class QRegExp;
22
23/** This is an alternative implementation of QCString. It provides basically
24 * the same functions but uses less memory for administration. This class
25 * is just a wrapper around a plain C string requiring only 4 bytes "overhead".
26 * QCString features sharing of data and stores the string length, but
27 * requires 4 + 12 bytes for this (even for the empty string). As doxygen
28 * uses a LOT of string during a run it saves a lot of memory to use a
29 * more memory efficient implementation at the cost of relatively low
30 * runtime overhead.
31 */
32class SCString
33{
34public:
35 SCString() : m_data(0) {}// make null string
36 SCString( const SCString &s );
37 SCString( int size );
38 SCString( const char *str );
39 SCString( const char *str, uint maxlen );
40 ~SCString();
41
42 SCString &operator=( const SCString &s );// deep copy
43 SCString &operator=( const char *str );// deep copy
44
45 bool isNull() const;
46 boolisEmpty()const;
47 uintlength()const;
48 uint size() const { return m_data ? length()+1 : 0; }
49 char * data() const { return m_data; }
50 boolresize( uint newlen );
51 booltruncate( uint pos );
52 boolfill( char c, int len = -1 );
53
54 SCStringcopy()const;
55
56 SCString &sprintf( const char *format, ... );
57
58 intfind( char c, int index=0, bool cs=TRUE ) const;
59 intfind( const char *str, int index=0, bool cs=TRUE ) const;
60 intfind( const QRegExp &, int index=0 ) const;
61 int find( const QCString &str, int index, bool cs ) const;
62 intfindRev( char c, int index=-1, bool cs=TRUE) const;
63 intfindRev( const char *str, int index=-1, bool cs=TRUE) const;
64 intfindRev( const QRegExp &, int index=-1 ) const;
65 intcontains( char c, bool cs=TRUE ) const;
66 intcontains( const char *str, bool cs=TRUE ) const;
67 intcontains( const QRegExp & ) const;
68 bool stripPrefix(const char *prefix);
69
70 SCStringleft( uint len ) const;
71 SCStringright( uint len ) const;
72 SCStringmid( uint index, uint len=0xffffffff) const;
73
74 SCStringlower() const;
75 SCStringupper() const;
76
77 SCStringstripWhiteSpace()const;
78 SCStringsimplifyWhiteSpace()const;
79
80 SCString &assign( const char *str );
81 SCString &insert( uint index, const char * );
82 SCString &insert( uint index, char );
83 SCString &append( const char *s );
84 SCString &prepend( const char *s );
85 SCString &remove( uint index, uint len );
86 SCString &replace( uint index, uint len, const char * );
87 SCString &replace( const QRegExp &, const char * );
88
89 shorttoShort( bool *ok=0 )const;
90 ushorttoUShort( bool *ok=0 )const;
91 inttoInt( bool *ok=0 )const;
92 uinttoUInt( bool *ok=0 )const;
93 longtoLong( bool *ok=0 )const;
94 ulongtoULong( bool *ok=0 )const;
95
96 SCString &setNum( short );
97 SCString &setNum( ushort );
98 SCString &setNum( int );
99 SCString &setNum( uint );
100 SCString &setNum( long );
101 SCString &setNum( ulong );
102 QCString &setNum( float, char f='g', int prec=6 );
103 QCString &setNum( double, char f='g', int prec=6 );
104
105operator const char *() const;
106 SCString &operator+=( const char *str );
107 SCString &operator+=( char c );
108 char &at( uint index ) const;
109 char &operator[]( int i ) const { return at(i); }
110
111 private:
112 static void msg_index( uint );
113 void duplicate( const SCString &s );
114 void duplicate( const char *str);
115 SCString &duplicate( const char *str, int);
116
117 char * m_data;
118};
119
120inline char &SCString::at( uint index ) const
121{
122 return m_data[index];
123}
124
125inline void SCString::duplicate( const SCString &s )
126{
127 if (!s.isEmpty())
128 {
129 uint l = strlen(s.data());
130 m_data = (char *)malloc(l+1);
131 if (m_data) memcpy(m_data,s.data(),l+1);
132 }
133 else
134 m_data=0;
135}
136inline void SCString::duplicate( const char *str)
137{
138 if (str && str[0]!='\0')
139 {
140 uint l = strlen(str);
141 m_data = (char *)malloc(l+1);
142 if (m_data) memcpy(m_data,str,l+1);
143 }
144 else
145 m_data=0;
146}
147inline SCString &SCString::duplicate( const char *str, int)
148{
149 if (m_data) free(m_data);
150 duplicate(str);
151 return *this;
152}
153
154#endif
155
156

Archive Download this file

Revision: 1406