Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/substring.h @ 7227

Last change on this file since 7227 was 7221, checked in by bensch, 19 years ago

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File size: 2.0 KB
RevLine 
[4597]1/*!
[4220]2  \file substring.h
3  \brief a small class to get the parts of a string separated by commas
4*/
[3941]5
6#ifndef _SUBSTRING_H
7#define _SUBSTRING_H
[4220]8
[7221]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
[4482]20//! A class that can load one string and split it in multipe ones
[3941]21class SubString
22{
[4220]23 public:
[7221]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');
[4220]27  ~SubString();
[4597]28
[7221]29  unsigned int split(const std::string& string = "", char splitter = ',');
30  unsigned int split(const std::string& string, bool whiteSpaces);
31  unsigned int split(const std::string& string, const std::string& splitters, char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
[6648]32
[7221]33
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 (i < this->strings.size()) ? this->strings[i] : emptyString; };
[5200]38  unsigned int getOffset(unsigned int i);
[4597]39
[7221]40  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,std::vector<unsigned int>& offsets,
41                                    const std::string& line, const std::string& delimiters = " \t\r\n",
42                                    char escape_char = '\\', char safemode_char = '"', char comment_char = '\0',
43                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
44
[4833]45  void debug() const;
46
[4220]47 private:
[7221]48   std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
49   std::vector<unsigned int> offsets;                      //!< offsets of the beginning of the input-string to the beginning of each substring.
50
51   static const std::string emptyString;
[3941]52};
53
54#endif /* _SUBSTRING_H */
Note: See TracBrowser for help on using the repository browser.