Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7211 in orxonox.OLD for branches/std/src/lib/util/substring.h


Ignore:
Timestamp:
Mar 10, 2006, 4:52:21 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: new SubString class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/lib/util/substring.h

    r6648 r7211  
    77#define _SUBSTRING_H
    88
     9#include <vector>
     10#include <string>
     11
     12  typedef enum {
     13    SL_NORMAL,
     14    SL_ESCAPE,
     15    SL_SAFEMODE,
     16    SL_SAFEESCAPE,
     17    SL_COMMENT,
     18  } SPLIT_LINE_STATE;
     19
    920//! A class that can load one string and split it in multipe ones
    1021class SubString
    1122{
    1223 public:
    13   SubString(const char* string, char splitter = ',');
    14   SubString(const char* string, bool whiteSpaces);
    15   SubString(const char* string, const char* splitters, char escapeChar ='\\');
     24  SubString(const std::string& string, char splitter = ',');
     25  SubString(const std::string& string, bool whiteSpaces);
     26  SubString(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
    1627  ~SubString();
    1728
    18   const char* operator[](unsigned int i) { return this->getString(i); };
     29  SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets,
     30                             const std::string& line, const std::string& delimiters = " \t\r\n",
     31                             char escape_char = '\\', char safemode_char = '"', char comment_char = '\0',
     32                             SPLIT_LINE_STATE start_state = SL_NORMAL);
    1933
    20   inline unsigned int getCount() { return this->splittersCount; };
    21   const char* getString(unsigned int i);
     34  const std::string& operator[](unsigned int i) { return this->getString(i); };
     35
     36  inline unsigned int getCount() { return this->strings.size(); };
     37  const std::string& getString(unsigned int i) { return this->strings[i]; };
    2238  unsigned int getOffset(unsigned int i);
    2339
     
    2541
    2642 private:
    27   char**          strings;                      //!< strings produced from a single string splitted in multiple strings
    28   unsigned int*   offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
    29   unsigned int    splittersCount;               //!< how many splitted parts
     43   std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     44   std::vector<unsigned int> offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
    3045};
    3146
Note: See TracChangeset for help on using the changeset viewer.