2
// Copyright ļæ½ 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Implements an extended string class, CqString, derived from std::string
23
\author Paul C. Gregory (pgregory@aqsis.com)
33
START_NAMESPACE( Aqsis )
35
//---------------------------------------------------------------------
36
/** Expands characters which require escape sequences.
37
* \return A string in which escape characters are expanded.
40
CqString CqString::ExpandEscapes() const
43
const TqChar* str = c_str();
55
case '\\': strResult += '\\' + '\\'; break;
56
case '\'': strResult += '\\' + '\''; break;
57
case '\"': strResult += '\\' + '\"'; break;
58
default: strResult += c; break;
67
case '\a': strResult += 'a'; break;
68
case '\b': strResult += 'b'; break;
69
case '\n': strResult += 'n'; break;
70
case '\r': strResult += 'r'; break;
71
case '\t': strResult += 't'; break;
72
case '\0': strResult += '0'; break;
78
for ( i = 0;i < 4;i++ )
80
TqInt Value = ( ( c >> 12 ) & 0x0F ); // Get high nibble;
84
strResult += '0' + Value;
86
strResult += 'a' + Value;
99
//---------------------------------------------------------------------
100
/** Translates escape sequences into their actual characters.
101
* \return A string in which escape characters are translated.
104
CqString CqString::TranslateEscapes() const
107
const TqChar* str = c_str();
121
case 'a': strResult += '\a'; break;
122
case 'b': strResult += '\b'; break;
123
case 'n': strResult += '\n'; break;
124
case 'r': strResult += '\r'; break;
125
case 't': strResult += '\t'; break;
131
while ( ( c >= '0' && c <= '7' ) )
133
Value = Value * 8 + c - '0';
147
while ( ( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'F' ) || ( c >= 'a' && c <= 'f' ) )
150
if ( c >= '0' && c <= '9' )
153
if ( c >= 'A' && c <= 'F' )
154
Value += c - 'A' + 10;
156
if ( c >= 'a' && c <= 'f' )
157
Value += c - 'a' + 10;
178
return ( strResult );
182
//---------------------------------------------------------------------
183
/** Format a string printf style
186
CqString& CqString::Format( const TqChar* strFmt, ... )
189
va_start( marker, strFmt );
194
while ( strFmt[ i ] != '\0' )
196
switch ( strFmt[ i ] )
201
switch ( strFmt[ i ] )
205
TqFloat val = static_cast<TqFloat>( va_arg( marker, double ) );
206
*this += ToString(val);
213
TqInt val = va_arg( marker, TqInt );
214
*this += ToString(val);
220
TqInt val = va_arg( marker, TqInt );
221
*this += ToString(val);
226
*this += va_arg( marker, TqChar* );
233
*this += strFmt[ i ];
244
CqString& CqString::operator+=( const CqString& str )
246
CqStringBase::operator+=( str );
250
CqString& CqString::operator+=( const TqChar* str )
252
CqStringBase::operator+=( str );
256
CqString& CqString::operator+=( TqChar c )
258
CqStringBase::operator+=( c );
262
CqString& CqString::operator+=( TqInt i )
264
*this += ToString(i);
268
CqString& CqString::operator+=( TqFloat f )
270
*this += ToString(f);
275
//---------------------------------------------------------------------
276
/** Concatenate two strings
279
CqString operator+( const CqString& strAdd1, const CqString& strAdd2 )
281
CqString strRes( strAdd1 );
287
//---------------------------------------------------------------------
288
/** Concatenate two strings
291
CqString operator+( const TqChar* strAdd1, const CqString& strAdd2 )
293
CqString strRes( strAdd1 );
299
//---------------------------------------------------------------------
300
/** Concatenate two strings
303
CqString operator+( const CqString& strAdd1, const TqChar* strAdd2 )
305
CqString strRes( strAdd1 );
311
//---------------------------------------------------------------------
312
/** Append charater to end of string
315
CqString operator+( const CqString& strAdd1, TqChar ch )
317
CqString strRes( strAdd1 );
323
//---------------------------------------------------------------------
324
/** Prepend character to string
327
CqString operator+( TqChar ch, const CqString& strAdd2 )
329
CqString strRes( ch );
335
//---------------------------------------------------------------------
336
/** Not really useful but needed for the templatised operation of the render engine.
339
CqString operator-( const CqString& strAdd1, const CqString& strAdd2 )
345
//---------------------------------------------------------------------
346
/** Not really useful but needed for the templatised operation of the render engine.
349
CqString operator/( const CqString&strAdd1, const CqString&strAdd2 )
355
//---------------------------------------------------------------------
356
/** Not really useful but needed for the templatised operation of the render engine.
359
CqString operator*( const CqString& strAdd1, const CqString& strAdd2 )
365
//---------------------------------------------------------------------
366
/** Not really useful but needed for the templatised operation of the render engine.
369
CqString operator*( const CqString& strAdd1, TqFloat f )
375
std::ostream& operator<<( std::ostream & stmOutput, const CqString& strString )
377
stmOutput << strString.c_str();
378
return ( stmOutput );
383
//---------------------------------------------------------------------
385
END_NAMESPACE( Aqsis )