summaryrefslogtreecommitdiff
path: root/Bus/Ivy/DataTypes.h
diff options
context:
space:
mode:
authorfcolin2007-02-01 12:54:30 +0000
committerfcolin2007-02-01 12:54:30 +0000
commit7b426973cfd6485fbcc4049922d126daabb0cf00 (patch)
tree7053850be43b91f2d9970a74968b20ca6a45e236 /Bus/Ivy/DataTypes.h
parent28a4e33c3a88f0ed85e24fcf4dc3c4380605d68e (diff)
downloadivy-cplusplus-7b426973cfd6485fbcc4049922d126daabb0cf00.zip
ivy-cplusplus-7b426973cfd6485fbcc4049922d126daabb0cf00.tar.gz
ivy-cplusplus-7b426973cfd6485fbcc4049922d126daabb0cf00.tar.bz2
ivy-cplusplus-7b426973cfd6485fbcc4049922d126daabb0cf00.tar.xz
Utilisateur : Fcolin Date : 23/09/05 Heure : 15:27 Archivé dans $/Bus/Ivy Commentaire: (vss 10)
Diffstat (limited to 'Bus/Ivy/DataTypes.h')
-rw-r--r--Bus/Ivy/DataTypes.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/Bus/Ivy/DataTypes.h b/Bus/Ivy/DataTypes.h
index ea17c37..190a7a6 100644
--- a/Bus/Ivy/DataTypes.h
+++ b/Bus/Ivy/DataTypes.h
@@ -16,14 +16,15 @@ namespace ivy
class string {
public:
+ static const size_t npos = size_t(-1);
string(size_t len = 0)
{ ptr = allocBuffer( len ); };
string ( const string& s )
{ ptr = 0; copy( s.ptr, s.size ); }
- string( const char * s, int len = -1 )
+ string( const char * s, size_t len = npos )
{
ptr = 0;
- if ( len < 0 )
+ if ( len == npos )
len = strlen(s) ;
copy( s, len );
}
@@ -34,17 +35,17 @@ public:
{ return size; }
bool empty() const
{ return size==0; }
- void copy( const char * s, int len )
+ void copy( const char * s, size_t len )
{
if ( ptr ) delete [] ptr;
ptr = allocBuffer( len );
strncpy( ptr, s, len );
}
- void erase(int start=0, int len = -1)
+ void erase(size_t start=0, size_t len = npos)
{
char *newptr;
size_t real_len;
- real_len = len < 0 ? size - start : len;
+ real_len = len == npos ? size - start : len;
if ( real_len > size ) real_len = size;
newptr = allocBuffer( size - real_len );
strncpy( newptr, ptr , start );
@@ -52,14 +53,14 @@ public:
delete ptr;
ptr = newptr;
}
- void append( const char *s , int len = -1 )
+ void append( const char *s , size_t len = npos )
{
insert ( size, s , len );
}
- void insert(int index, const char * s, int len = -1)
+ void insert(size_t index, const char * s, size_t len = npos)
{
char *newptr;
- if ( len < 0 ) len = strlen(s) ;
+ if ( len == npos ) len = strlen(s) ;
newptr = allocBuffer( size + len );
strncpy( newptr , ptr, index );
strncpy( newptr+index , s, len ) ;
@@ -67,12 +68,12 @@ public:
delete ptr;
ptr = newptr;
}
- string substr( int start, int len = -1 )
+ string substr( size_t start, size_t len = npos )
{ return string ( &ptr[start], len ); }
- int find_first_of( const char* strCharSet )
- { char *fnd = strpbrk( ptr, strCharSet ); if ( fnd ) return fnd - ptr; else return -1; }
- int rfind( char c )
- { char *fnd = strrchr( ptr, c); if ( fnd ) return fnd - ptr; else return -1; }
+ size_t find_first_of( const char* strCharSet )
+ { char *fnd = strpbrk( ptr, strCharSet ); if ( fnd ) return (size_t)(fnd - ptr); else return npos; }
+ size_t rfind( char c )
+ { char *fnd = strrchr( ptr, c); if ( fnd ) return (size_t)(fnd - ptr); else return npos; }
// friend string operator + (const string& left, const char* right);
// friend string operator + (const char* left, const string& right);
friend string operator + (const string& left, const string& right)
@@ -114,7 +115,7 @@ private:
char *ptr;
size_t size;
// always allocate one extra character for '\0' termination
- char *allocBuffer(int len)
+ char *allocBuffer(size_t len)
{
char *newptr;
size = len;
@@ -295,7 +296,7 @@ public:
void push_back( const T& value )
{
T* newdata = new T[len+1];
- for ( unsigned int i = 0; i < len ; i ++ )
+ for ( size_t i = 0; i < len ; i ++ )
newdata[i] = data[i];
newdata[len++] = value;
if ( data ) delete [] data;