Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5656 in orxonox.OLD for trunk


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
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/command_chain.cc

    r5461 r5656  
    430430  unsigned int fktPos = 1;                //< the position of the function (needed for finding it)
    431431//  long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
    432   SubString inputSplits(executionString, true);
     432  SubString inputSplits(executionString, " \n\t,");
    433433
    434434  if (inputSplits.getCount() == 0)
  • trunk/src/lib/event/command_chain.h

    r5461 r5656  
    360360    virtual void executeCommand (BaseObject* object, const char* parameters)
    361361    {
    362       SubString sub(parameters, true);
     362      SubString sub(parameters, " \n\t,");
    363363//! FUNCTOR_LIST is the List of Executive Functions
    364364#define FUNCTOR_LIST(x) CommandChainExecute ## x
  • trunk/src/lib/graphics/graphics_engine.cc

    r5509 r5656  
    259259
    260260  if (this->hwExtensions == NULL && extensions != NULL)
    261     this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), true);
     261    this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,");
    262262
    263263  PRINT(4)("Running on : %s %s %s\n", vendor, renderer, version);
  • trunk/src/lib/shell/shell_command.cc

    r5652 r5656  
    170170  unsigned int fktPos = 1;                //< the position of the function (needed for finding it)
    171171//  long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
    172   SubString inputSplits(executionString, true);
     172  SubString inputSplits(executionString, " \t\n,");
    173173
    174174  if (inputSplits.getCount() == 0)
  • trunk/src/lib/shell/shell_completion.cc

    r5639 r5656  
    9595  else
    9696    completionLine = this->input->getInput() + strspn(this->input->getInput(), " \t\n");
    97   SubString inputSplits(completionLine, true);
     97  SubString inputSplits(completionLine, " \t\n,");
    9898
    9999  // What String will be completed
  • 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
  • trunk/src/util/track/track_manager.cc

    r5654 r5656  
    737737void TrackManager::forkS(const char* forkString)
    738738{
    739   SubString strings(forkString);
     739  SubString strings(forkString, ',');
    740740
    741741  int* trackIDs = new int[strings.getCount()];
     
    878878void TrackManager::joinS(const char* joinString)
    879879{
    880   SubString strings(joinString);
     880  SubString strings(joinString, ',');
    881881
    882882  int* trackIDs = new int[strings.getCount()];
Note: See TracChangeset for help on using the changeset viewer.