Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4220 in orxonox.OLD for orxonox/trunk/src/lib/util/substring.cc


Ignore:
Timestamp:
May 18, 2005, 11:01:59 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: TrackManager prepared for loading. added new overloaded functions that read in join and fork from one single string
thanks to chris, this was pretty easy… the hard part was finding the substring class :)

File:
1 edited

Legend:

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

    r4010 r4220  
    2222#include "substring.h"
    2323
     24#include <string.h>
     25#include <assert.h>
     26
    2427SubString::SubString( const char* string)
    2528{
    26         n = 0;
     29  n = 0;
    2730       
    28         assert( string != NULL);
     31  assert( string != NULL);
    2932       
    30         for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++;
     33  for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++;
    3134
    32         n += 1;
     35  n += 1;
    3336       
    34         strings = new char*[n];
     37  strings = new char*[n];
     38
     39  assert (strings != NULL);
    3540       
    36         assert( strings != NULL);
     41  int i = 0;
     42  int l = 0;
    3743       
    38         int i = 0;
    39         int l = 0;
     44  const char* offset = string;
     45  char* end = strchr( string, ',');
     46  while( end != NULL)
     47    {
     48      assert( i < n);
     49      l = end - offset;
     50      strings[i] = new char[l + 1];
     51      assert( strings[i] != NULL);
     52      strncpy( strings[i], offset, l);
     53      strings[i][l] = 0;
     54      i++;
     55      end++;
     56      offset = end;
     57      end = strchr( offset, ',');
     58    }
    4059       
    41         const char* offset = string;
    42         char* end = strchr( string, ',');
    43         while( end != NULL)
    44         {
    45                 assert( i < n);
    46                 l = end - offset;
    47                 strings[i] = new char[l + 1];
    48                 assert( strings[i] != NULL);
    49                 strncpy( strings[i], offset, l);
    50                 strings[i][l] = 0;
    51                 i++;
    52                 end++;
    53                 offset = end;
    54                 end = strchr( offset, ',');
    55         }
    56        
    57         strings[i] = new char[l + 1];
    58         l = strlen( offset);
    59         strncpy( strings[i], offset, l);
    60         strings[i][l] = 0;
     60  strings[i] = new char[l + 1];
     61  l = strlen( offset);
     62  strncpy( strings[i], offset, l);
     63  strings[i][l] = 0;
    6164}
    6265
     
    6669SubString::~SubString()
    6770{
    68         for( int i = 0; i < n; i++)
    69         {
    70                 delete strings[i];
    71         }
     71  for( int i = 0; i < n; i++)
     72    {
     73      delete strings[i];
     74    }
    7275       
    73         delete strings;
     76  delete strings;
    7477}
    7578
     
    7881   \returns the amount of substrings
    7982*/
    80 int SubString::getN()
     83int SubString::getCount()
    8184{
    82         return n;
     85  return n;
    8386}
    8487
     
    9093const char* SubString::getString( int i)
    9194{
    92         if( i < n && i >= 0) return strings[i];
    93         else return NULL;
     95  if( i < n && i >= 0) return strings[i];
     96  else return NULL;
    9497}
Note: See TracChangeset for help on using the changeset viewer.