Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 20, 2005, 9:45:28 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new Version of the String-splitter (without Escape-sequence for the time being)

Location:
trunk/src/lib/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/executor/executor.h

    r5652 r5656  
    3838    virtual Executor* clone () const = 0;
    3939
     40    Executor* defaultValues(unsigned int count, va_list values);
    4041    Executor* defaultValues(unsigned int count, ...);
    41     Executor* defaultValues(unsigned int count, va_list values);
    4242
    4343    /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
     
    5656
    5757    void cloning(Executor* executor) const;
     58
     59//    const SubString& getSubString(const char* string) const { return SubString(string); };
    5860
    5961  protected:
     
    261263    virtual void execute (BaseObject* object, const char* parameters)
    262264    {
    263       SubString sub(parameters, ',');  /// FIXME ///
     265      SubString sub(parameters, " \n\t,", '\\');
    264266//! FUNCTOR_LIST is the List of Executive Functions
    265267#define FUNCTOR_LIST(x) ExecutorExecute ## x
     
    323325    virtual void execute (BaseObject* object, const char* parameters)
    324326    {
    325   SubString sub(parameters, true);
     327  SubString sub(parameters, " \n\t,");
    326328//! FUNCTOR_LIST is the List of Executive Functions
    327329#define FUNCTOR_LIST(x) ExecutorExecute ## x
  • trunk/src/lib/util/substring.cc

    r5209 r5656  
    123123  assert (this->strings != NULL && this->offsets != NULL);
    124124
     125
    125126  // split the String into substrings
    126127  int l = 0;
     
    154155}
    155156
     157SubString::SubString(const char* string, const char* splitters, char escapeChar)
     158{
     159  this->splittersCount = 0;
     160  if (string == NULL || splitters == NULL)
     161  {
     162    this->strings = NULL;
     163    this->offsets = NULL;
     164    return;
     165  }
     166
     167  // chop the input to the beginning of something usefull
     168  if (strlen(string) > 0)
     169    string = string + strspn(string, splitters);
     170
     171  // count the Splitters
     172  bool lastWasSplitter = false;
     173  for(unsigned int i = 0; i < strlen(string); i++)
     174  {
     175
     176    if( strchr(splitters, string[i] ))
     177      lastWasSplitter = true;
     178    else
     179    {
     180      if (lastWasSplitter)
     181      {
     182        this->splittersCount ++;
     183        lastWasSplitter = false;
     184      }
     185    }
     186  }
     187  this->splittersCount += 1;
     188
     189  // allocate memory
     190  this->strings = new char*[this->splittersCount];
     191  this->offsets = new unsigned int[this->splittersCount];
     192  assert (this->strings != NULL && this->offsets != NULL);
     193
     194
     195  // split the String into substrings
     196  int l = 0;
     197  unsigned int i = 0;
     198  if( this->splittersCount > 1)
     199  {
     200    const char* offset = string;
     201    const char* end = offset + strcspn(offset, splitters);
     202    for (i = 0; i < this->splittersCount; i++)
     203    {
     204      assert( i < this->splittersCount);
     205      l = end - offset;
     206      this->strings[i] = new char[l + 1];
     207      assert( strings[i] != NULL);
     208      strncpy( strings[i], offset, l);
     209      strings[i][l] = '\0';
     210      this->offsets[i] = offset - string;
     211      end += strspn(end, splitters);
     212      offset = end;
     213      end = offset + strcspn(offset, splitters);
     214    }
     215  }
     216  else
     217  {
     218    unsigned int length = strcspn(string, splitters);
     219    this->strings[0] = new char[length+1];
     220    strncpy(this->strings[0], string, length);
     221    this->strings[0][length] = '\0';
     222    offsets[0] = 0;
     223  }
     224}
     225
     226
    156227/**
    157228 *  removes the object from memory
  • trunk/src/lib/util/substring.h

    r5200 r5656  
    1313  SubString(const char* string, char splitter = ',');
    1414  SubString(const char* string, bool whiteSpaces);
     15  SubString(const char* string, const char* splitters, char escapeChar ='\\');
    1516  ~SubString();
    1617
Note: See TracChangeset for help on using the changeset viewer.