Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

string.cpp

00001 /*
00002  *                         Sun Public License Notice
00003  *
00004  * The contents of this file are subject to the Sun Public License
00005  * Version 1.0 (the "License"); you may not use this file except
00006  * in compliance with the License. A copy of the License is available
00007  * at http://www.sun.com/
00008  *
00009  * The Original Code is the Java Profiler module.  The Initial Developers
00010  * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00011  * Lukas Petru and Marek Przeczek.
00012  *
00013  * Portions created by Jan Stola are Copyright (C) 2000-2001.
00014  * All Rights Reserved.
00015  *
00016  * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
00017  * All Rights Reserved.
00018  *
00019  * Portions created by Michal Pise are Copyright (C) 2000-2001.
00020  * All Rights Reserved.
00021  *
00022  * Portions created by Petr Luner are Copyright (C) 2000-2001.
00023  * All Rights Reserved.
00024  *
00025  * Portions created by Lukas Petru are Copyright (C) 2000-2001.
00026  * All Rights Reserved.
00027  *
00028  * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
00029  * All Rights Reserved.
00030  *
00031  * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00032  *               Lukas Petru and Marek Przeczek.
00033  */
00034 
00035 #include "../string/string.h"
00036 
00037 String::String( const char* str) {
00038 
00039         if( !str) str = "";
00040         _str = new char[strlen( str)+1];
00041         strcpy( _str, str);
00042 }
00043 
00044 String::String( const String& s) {
00045         
00046         _str = new char[s.length()+1];
00047         strcpy( _str, s);
00048 }
00049 
00050 String::~String() {
00051         
00052         delete[] _str;
00053 }
00054 
00055 String String::operator=( const char* s) {
00056         
00057         if( s != _str) { // it is not me => you can do that
00058         
00059                 delete[] _str;
00060                 if( !s) s = "";
00061                 _str = new char[strlen( s)+1];
00062                 strcpy( _str, s);
00063         }
00064 
00065         return String( _str);
00066 }
00067 
00068 String String::operator+=( const char* s) {
00069         
00070         if( !s) s = "";
00071         
00072         char* old = _str;
00073         _str = new char[strlen( _str)+strlen( s)+1];
00074         strcpy( _str, old);
00075         strcat( _str, s);
00076         delete[] old;
00077 
00078         return String( _str);
00079 }
00080 
00081 String String::cutRight() {
00082         
00083         int len = strlen( _str);
00084         char* p = _str+len-1;
00085         
00086         while( len) {
00087         
00088                 if( *p == ' ' || *p == '\t') {
00089                 
00090                         *p = 0;
00091                         len--;
00092                         p--;
00093                 }
00094                 else break;
00095         }
00096 
00097         return (*this);
00098 }
00099 
00100 String String::cutLeft() {
00101 
00102         char* p = _str;
00103         while( *p) {
00104         
00105                 if( *p == ' ' || *p == '\t') p++;
00106                 else break;
00107         }
00108 
00109         memmove( _str, p, strlen( p)+1);
00110 
00111         return (*this);
00112 }

Generated on Mon Jan 28 14:53:27 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001