added strEq and strToL functions

This commit is contained in:
darkeye 2000-11-09 06:44:21 +00:00
parent d63b1eacc4
commit d365bb7cf5
2 changed files with 68 additions and 2 deletions

View File

@ -44,6 +44,18 @@
#error need string.h
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error need stdlib.h
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#error need limits.h
#endif
#include "Util.h"
@ -86,12 +98,53 @@ Util :: strDup( const char * str ) throw ( Exception )
}
/*------------------------------------------------------------------------------
* Check wether two strings are equal
*----------------------------------------------------------------------------*/
bool
Util :: strEq( const char * str1,
const char * str2 ) throw ( Exception )
{
if ( !str1 || !str2 ) {
throw Exception( __FILE__, __LINE__, "no str1 or no str2");
}
return !strcmp( str1, str2);
}
/*------------------------------------------------------------------------------
* Convert a string to a long integer
*----------------------------------------------------------------------------*/
long int
Util :: strToL( const char * str,
int base ) throw ( Exception )
{
long int val;
char * s;
if ( !str ) {
throw Exception( __FILE__, __LINE__, "no str");
}
val = strtol( str, &s, base);
if ( s == str || val == LONG_MIN || val == LONG_MAX ) {
throw Exception( __FILE__, __LINE__, "number conversion error");
}
return val;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.3 2000/11/09 06:44:21 darkeye
added strEq and strToL functions
Revision 1.2 2000/11/05 14:08:28 darkeye
changed builting to an automake / autoconf environment

View File

@ -95,6 +95,16 @@ class Util
static char *
strDup( const char * str ) throw ( Exception );
static bool
strEq( const char * str1,
const char * str2 ) throw ( Exception );
static long int
strToL( const char * str,
int base = 10 ) throw ( Exception );
};
@ -113,8 +123,11 @@ class Util
$Source$
$Log$
Revision 1.1 2000/11/05 10:05:55 darkeye
Initial revision
Revision 1.2 2000/11/09 06:44:21 darkeye
added strEq and strToL functions
Revision 1.1.1.1 2000/11/05 10:05:55 darkeye
initial version
------------------------------------------------------------------------------*/