Changeset 4830 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Jul 11, 2005, 5:43:37 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/substring.cc
r4734 r4830 29 29 SubString::SubString( const char* string, char splitter) 30 30 { 31 n= 0;31 this->splittersCount = 0; 32 32 33 33 assert( string != NULL); 34 34 35 for( int i = 0; i < strlen(string); i++) if( string[i] == splitter) n++; 35 for( int i = 0; i < strlen(string); i++) if( string[i] == splitter) 36 splittersCount++; 36 37 37 n+= 1;38 this->splittersCount += 1; 38 39 39 strings = new char*[n]; 40 40 this->strings = new char*[this->splittersCount]; 41 41 assert (strings != NULL); 42 42 … … 48 48 while( end != NULL) 49 49 { 50 assert( i < n);50 assert( i < this->splittersCount); 51 51 l = end - offset; 52 strings[i] = new char[l + 1];52 this->strings[i] = new char[l + 1]; 53 53 assert( strings[i] != NULL); 54 54 strncpy( strings[i], offset, l); … … 71 71 SubString::~SubString() 72 72 { 73 for( int i = 0; i < n; i++)73 for( int i = 0; i < this->splittersCount; i++) 74 74 { 75 delete strings[i];75 delete this->strings[i]; 76 76 } 77 77 78 delete strings; 79 } 80 81 /** 82 \brief get the amount of substrings 83 \returns the amount of substrings 84 */ 85 int SubString::getCount() 86 { 87 return n; 78 delete this->strings; 88 79 } 89 80 … … 95 86 const char* SubString::getString( int i) 96 87 { 97 if( i < n && i >= 0) return strings[i]; 98 else return NULL; 88 if( i < this->splittersCount && i >= 0) 89 return this->strings[i]; 90 else 91 return NULL; 99 92 } -
orxonox/trunk/src/lib/util/substring.h
r4734 r4830 14 14 ~SubString(); 15 15 16 in t getCount();16 inline int getCount() { return this->splittersCount; }; 17 17 const char* getString( int i); 18 18 19 19 private: 20 char** strings; //!< strings produced from a single string splitted in multiple strings21 int n; //!< how many splitted parts20 char** strings; //!< strings produced from a single string splitted in multiple strings 21 int splittersCount; //!< how many splitted parts 22 22 }; 23 23
Note: See TracChangeset
for help on using the changeset viewer.