Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4830 in orxonox.OLD for orxonox/trunk/src/lib/util


Ignore:
Timestamp:
Jul 11, 2005, 5:43:37 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented aim

Location:
orxonox/trunk/src/lib/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/substring.cc

    r4734 r4830  
    2929SubString::SubString( const char* string, char splitter)
    3030{
    31   n = 0;
     31  this->splittersCount = 0;
    3232
    3333  assert( string != NULL);
    3434
    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++;
    3637
    37   n += 1;
     38  this->splittersCount += 1;
    3839
    39   strings = new char*[n];
    40 
     40  this->strings = new char*[this->splittersCount];
    4141  assert (strings != NULL);
    4242
     
    4848  while( end != NULL)
    4949    {
    50       assert( i < n);
     50      assert( i < this->splittersCount);
    5151      l = end - offset;
    52       strings[i] = new char[l + 1];
     52      this->strings[i] = new char[l + 1];
    5353      assert( strings[i] != NULL);
    5454      strncpy( strings[i], offset, l);
     
    7171SubString::~SubString()
    7272{
    73   for( int i = 0; i < n; i++)
     73  for( int i = 0; i < this->splittersCount; i++)
    7474    {
    75       delete strings[i];
     75      delete this->strings[i];
    7676    }
    7777
    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;
    8879}
    8980
     
    9586const char* SubString::getString( int i)
    9687{
    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;
    9992}
  • orxonox/trunk/src/lib/util/substring.h

    r4734 r4830  
    1414  ~SubString();
    1515
    16   int getCount();
     16  inline int getCount() { return this->splittersCount; };
    1717  const char* getString( int i);
    1818
    1919 private:
    20   char**     strings;         //!< strings produced from a single string splitted in multiple strings
    21   int        n;               //!< how many splitted parts
     20  char**     strings;                      //!< strings produced from a single string splitted in multiple strings
     21  int        splittersCount;               //!< how many splitted parts
    2222};
    2323
Note: See TracChangeset for help on using the changeset viewer.