1 /******************************************************************************
3 * Copyright (C) 1997-2004 by Dimitri van Heesch.
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.
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
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
35 SCString() : m_data(0) {} // make null string
36 SCString( const SCString &s );
38 SCString( const char *str );
39 SCString( const char *str, uint maxlen );
42 SCString &operator=( const SCString &s );// deep copy
43 SCString &operator=( const char *str ); // deep copy
48 uint size() const { return m_data ? length()+1 : 0; }
49 char * data() const { return m_data; }
50 bool resize( uint newlen );
51 bool truncate( uint pos );
52 bool fill( char c, int len = -1 );
54 SCString copy() const;
56 SCString &sprintf( const char *format, ... );
58 int find( char c, int index=0, bool cs=TRUE ) const;
59 int find( const char *str, int index=0, bool cs=TRUE ) const;
60 int find( const QRegExp &, int index=0 ) const;
61 int find( const QCString &str, int index, bool cs ) const;
62 int findRev( char c, int index=-1, bool cs=TRUE) const;
63 int findRev( const char *str, int index=-1, bool cs=TRUE) const;
64 int findRev( const QRegExp &, int index=-1 ) const;
65 int contains( char c, bool cs=TRUE ) const;
66 int contains( const char *str, bool cs=TRUE ) const;
67 int contains( const QRegExp & ) const;
68 bool stripPrefix(const char *prefix);
70 SCString left( uint len ) const;
71 SCString right( uint len ) const;
72 SCString mid( uint index, uint len=0xffffffff) const;
74 SCString lower() const;
75 SCString upper() const;
77 SCString stripWhiteSpace() const;
78 SCString simplifyWhiteSpace() const;
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 * );
89 short toShort( bool *ok=0 ) const;
90 ushort toUShort( bool *ok=0 ) const;
91 int toInt( bool *ok=0 ) const;
92 uint toUInt( bool *ok=0 ) const;
93 long toLong( bool *ok=0 ) const;
94 ulong toULong( bool *ok=0 ) const;
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 );
105 operator 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); }
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);
120 inline char &SCString::at( uint index ) const
122 return m_data[index];
125 inline void SCString::duplicate( const SCString &s )
129 uint l = strlen(s.data());
130 m_data = (char *)malloc(l+1);
131 if (m_data) memcpy(m_data,s.data(),l+1);
136 inline void SCString::duplicate( const char *str)
138 if (str && str[0]!='\0')
140 uint l = strlen(str);
141 m_data = (char *)malloc(l+1);
142 if (m_data) memcpy(m_data,str,l+1);
147 inline SCString &SCString::duplicate( const char *str, int)
149 if (m_data) free(m_data);