Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 18, 2005, 3:49:21 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: aliases now can also take arguments

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

Legend:

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

    r5184 r5200  
    3434  {
    3535    this->strings = NULL;
     36    this->offsets = NULL;
    3637    return;
    3738  }
     
    4445
    4546  this->strings = new char*[this->splittersCount];
    46   assert (strings != NULL);
     47  this->offsets = new unsigned int[this->splittersCount];
     48  assert (this->strings != NULL && this->offsets != NULL);
    4749
    4850  int i = 0;
     
    6163      strncpy( strings[i], offset, l);
    6264      strings[i][l] = '\0';
     65      this->offsets[i] = offset - string;
    6366      i++;
    6467      end++;
     
    7174    strncpy( strings[i], offset, l);
    7275    strings[i][l] = '\0';
     76    this->offsets[i] = offset - string;
    7377  }
    7478  else
     
    7680    this->strings[0] = new char[strlen(string)+1];
    7781    strcpy(this->strings[0], string);
     82    this->offsets[0] = 0;
    7883  }
    7984}
     
    9297  {
    9398    this->strings = NULL;
     99    this->offsets = NULL;
    94100    return;
    95101  }
     
    114120  // allocate memory
    115121  this->strings = new char*[this->splittersCount];
    116   assert (strings != NULL);
     122  this->offsets = new unsigned int[this->splittersCount];
     123  assert (this->strings != NULL && this->offsets != NULL);
    117124
    118125  // split the String into substrings
     
    131138      strncpy( strings[i], offset, l);
    132139      strings[i][l] = '\0';
     140      this->offsets[i] = offset - string;
    133141      end += strspn(end, " \t\n");
    134142      offset = end;
     
    142150    strncpy(this->strings[0], string, length);
    143151    this->strings[0][length] = '\0';
     152    offsets[0] = 0;
    144153  }
    145154}
     
    156165    delete[] this->strings;
    157166  }
     167  delete[] this->offsets;
    158168}
    159169
     
    169179  else
    170180    return NULL;
     181}
     182
     183/**
     184 * get a particular substring's offset
     185 * @param i the ID of the substring to get the offset from
     186 * @returns the offset or NULL if an invalid ID was given
     187 */
     188unsigned int SubString::getOffset(unsigned int i)
     189{
     190  if( i < this->splittersCount && i >= 0)
     191    return this->offsets[i];
     192  else
     193    return 0;
    171194}
    172195
  • trunk/src/lib/util/substring.h

    r5183 r5200  
    1717  inline unsigned int getCount() { return this->splittersCount; };
    1818  const char* getString(unsigned int i);
     19  unsigned int getOffset(unsigned int i);
    1920
    2021  void debug() const;
     
    2223 private:
    2324  char**          strings;                      //!< strings produced from a single string splitted in multiple strings
     25  unsigned int*   offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
    2426  unsigned int    splittersCount;               //!< how many splitted parts
    2527};
Note: See TracChangeset for help on using the changeset viewer.