added functions strLen strCpy and strCat

This commit is contained in:
darkeye 2000-11-09 22:04:33 +00:00
parent d365bb7cf5
commit fef3c01532
2 changed files with 74 additions and 5 deletions

View File

@ -76,12 +76,61 @@ static const char fileid[] = "$Id$";
/* ============================================================= module code */ /* ============================================================= module code */
/*------------------------------------------------------------------------------
* Calculate the length of a zero-terminated C string,
* w/o the zero-termination
*----------------------------------------------------------------------------*/
unsigned int
Util :: strLen( const char * str ) throw ( Exception )
{
size_t len;
if ( !str ) {
throw Exception( __FILE__, __LINE__, "no str");
}
len = strlen( str);
return len;
}
/*------------------------------------------------------------------------------
* Copy the contents of a string into another
*----------------------------------------------------------------------------*/
void
Util :: strCpy ( char * dest,
const char * src ) throw ( Exception )
{
if ( !dest || !src ) {
throw Exception( __FILE__, __LINE__, "no src or dest");
}
strcpy( dest, src);
}
/*------------------------------------------------------------------------------
* Concatenate the contents of a string onto another
*----------------------------------------------------------------------------*/
void
Util :: strCat ( char * dest,
const char * src ) throw ( Exception )
{
if ( !dest || !src ) {
throw Exception( __FILE__, __LINE__, "no src or dest");
}
strcat( dest, src);
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Duplicate a string by allocating space with new[] * Duplicate a string by allocating space with new[]
* The returned string must be freed with delete[] * The returned string must be freed with delete[]
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
char * char *
Util :: strDup( const char * str ) throw ( Exception ) Util :: strDup( const char * str ) throw ( Exception )
{ {
size_t len; size_t len;
char * s; char * s;
@ -103,7 +152,7 @@ Util :: strDup( const char * str ) throw ( Exception )
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
bool bool
Util :: strEq( const char * str1, Util :: strEq( const char * str1,
const char * str2 ) throw ( Exception ) const char * str2 ) throw ( Exception )
{ {
if ( !str1 || !str2 ) { if ( !str1 || !str2 ) {
throw Exception( __FILE__, __LINE__, "no str1 or no str2"); throw Exception( __FILE__, __LINE__, "no str1 or no str2");
@ -142,6 +191,9 @@ Util :: strToL( const char * str,
$Source$ $Source$
$Log$ $Log$
Revision 1.4 2000/11/09 22:04:33 darkeye
added functions strLen strCpy and strCat
Revision 1.3 2000/11/09 06:44:21 darkeye Revision 1.3 2000/11/09 06:44:21 darkeye
added strEq and strToL functions added strEq and strToL functions

View File

@ -93,17 +93,31 @@ class Util
public: public:
static unsigned int
strLen ( const char * str ) throw ( Exception );
static void
strCpy ( char * dest,
const char * src ) throw ( Exception );
static void
strCat ( char * dest,
const char * src ) throw ( Exception );
static char * static char *
strDup( const char * str ) throw ( Exception ); strDup ( const char * str ) throw ( Exception );
static bool static bool
strEq( const char * str1, strEq ( const char * str1,
const char * str2 ) throw ( Exception ); const char * str2 ) throw ( Exception );
static long int static long int
strToL( const char * str, strToL ( const char * str,
int base = 10 ) throw ( Exception ); int base = 10 ) throw ( Exception );
}; };
@ -123,6 +137,9 @@ class Util
$Source$ $Source$
$Log$ $Log$
Revision 1.3 2000/11/09 22:04:33 darkeye
added functions strLen strCpy and strCat
Revision 1.2 2000/11/09 06:44:21 darkeye Revision 1.2 2000/11/09 06:44:21 darkeye
added strEq and strToL functions added strEq and strToL functions