From fef3c01532d5520adaa6d8b15643cbd5db89f058 Mon Sep 17 00:00:00 2001 From: darkeye Date: Thu, 9 Nov 2000 22:04:33 +0000 Subject: [PATCH] added functions strLen strCpy and strCat --- darkice/trunk/src/Util.cpp | 56 ++++++++++++++++++++++++++++++++++++-- darkice/trunk/src/Util.h | 23 ++++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/darkice/trunk/src/Util.cpp b/darkice/trunk/src/Util.cpp index 6e623bb..54d486e 100644 --- a/darkice/trunk/src/Util.cpp +++ b/darkice/trunk/src/Util.cpp @@ -76,12 +76,61 @@ static const char fileid[] = "$Id$"; /* ============================================================= 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[] * The returned string must be freed with delete[] *----------------------------------------------------------------------------*/ char * -Util :: strDup( const char * str ) throw ( Exception ) +Util :: strDup( const char * str ) throw ( Exception ) { size_t len; char * s; @@ -103,7 +152,7 @@ Util :: strDup( const char * str ) throw ( Exception ) *----------------------------------------------------------------------------*/ bool Util :: strEq( const char * str1, - const char * str2 ) throw ( Exception ) + const char * str2 ) throw ( Exception ) { if ( !str1 || !str2 ) { throw Exception( __FILE__, __LINE__, "no str1 or no str2"); @@ -142,6 +191,9 @@ Util :: strToL( const char * str, $Source$ $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 added strEq and strToL functions diff --git a/darkice/trunk/src/Util.h b/darkice/trunk/src/Util.h index db3ecf7..d5f7e3a 100644 --- a/darkice/trunk/src/Util.h +++ b/darkice/trunk/src/Util.h @@ -93,17 +93,31 @@ class Util 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 * - strDup( const char * str ) throw ( Exception ); + strDup ( const char * str ) throw ( Exception ); static bool - strEq( const char * str1, + strEq ( const char * str1, const char * str2 ) throw ( Exception ); static long int - strToL( const char * str, + strToL ( const char * str, int base = 10 ) throw ( Exception ); }; @@ -123,6 +137,9 @@ class Util $Source$ $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 added strEq and strToL functions