1 /****************************************************************************
2 PROJECT: FlowerSoft C++ library
5 Rehacked by HWN 3/nov/95
7 introduced Class String_handle
15 //#include "globals.hh"
18 char* strlwr( char* s )
24 *p = tolower( *p ); /* a macro on some compilers */
30 char* strupr( char* s )
36 *p = toupper( *p ); /* a macro on some compilers */
42 // return array, alloced with new.
44 String::copy_array() const
46 const char *src = data;
47 char *dest = new char[data.len() + 1];
53 String::printOn(ostream& os) const
55 os << (const char*) data;
58 String::String (bool b)
60 *this = (const char *) (b ? "true" : "false");
62 String::String( const char* source )
69 String::operator +=(String s)
71 *this += (const char *) s;
80 String::String(char c, int n)
83 assert(n >= 0 && n <= 80); // what the fuck is 80?
84 //min(max( n, 0 ), 80);
93 char digits[ 81 ]; // who the FUCK is 80???
95 sprintf(digits, "%d", i ); // assume radix 10
99 String::String( const int i, const int n, const char c )
107 data = String( fillChar, n - v.len() ) + String( v );
108 // String convd to const char *
119 #ifdef CENTRAL_OBJECT // everything derived from Sortable object
122 String::operator ==( const Sortable& test ) const
124 const String *s = (const String *) &test;
129 String::operator &&(const Object& test) const
131 const String *s = (const String *) &test;
133 int i = min( len(), s->len() );
135 ( !strncmp( data, s->data, i ) ) : 0;
139 String::operator >( const Sortable& test ) const
141 const String *s = (const String *) &test;
142 return strcmp( data, s->data ) > 0;
146 // signed comparison, analogous to strcmp;
148 String::compare( const char* test ) const
150 if (test == (const char *) data)
153 return strcmp(data, test);
158 String::lastPos( const char c ) const
160 const char *me = data;
164 const char* p = strrchr(me, c );
172 String::lastPos( const char* string ) const
175 int length = strlen( string );
176 if ( len() && length )
178 int nextpos = this->pos( string );
182 nextpos = right( len() - pos - length + 1 ).pos( string );
189 // return 0 if not found.
191 // ? should return len()?, as in string.left(pos(delimiter))
193 String::pos(char c ) const
195 const char *me = data;
199 const char* p = strchr( me, c );
206 // find searchfor. (what if this == "" && searchfor == "") ???
208 String::pos( const char* searchfor ) const
210 const char *me = data;
212 if ( len() && searchfor)
214 const char* p = strstr(me, searchfor);
221 // find chars of a set.
223 String::posAny( const char* string ) const
226 const char *s = (const char *)data;
227 if ( len() && string )
229 const char* p = strpbrk( s, string );
237 String::left( int n ) const
247 retval.data.trunc(n);
254 String::right( int n ) const
263 const char *src = (const char *)data + len() - n;
271 String::nomid( const int pos, const int n ) const
280 return String( String( left( pos - 1 ) ) + right( len() - pos - n + 1 ));
285 String::mid( int pos, int n ) const
290 // pos 1 == data->string[ 0 ];
291 // pos 0 allowed for convenience
292 if ( !len() || ( pos < 0 ) || ( pos > len() ) && ( n < 1 ) )
295 retval = ((const char *) data) + pos -1;
296 if (n > retval.len())
298 retval.data.trunc(n);
307 char *s = data.array_for_modify();
314 String String::lower()
316 char *s = data.array_for_modify();
321 String::String (double f, const char *fmt)
323 char buf[100]; // ugly
325 sprintf(buf, "%f", f);
332 String::value() const
336 int conv = sscanf(data, "%ld", &l);
343 String::fvalue() const
347 int conv = sscanf(data, "%lf", &d);
354 String quoteString( String msg, String quote)
356 return msg + " `" + quote + "' ";
360 char *strrev(char *s)
364 char *q = s + strlen(s) - 1;
376 String::reversed() const
379 char *s = retval.data.array_for_modify();
384 String::to_bool() const