Changeset 9406 in orxonox.OLD for trunk/src/lib/util/substring.h
- Timestamp:
- Jul 24, 2006, 11:09:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/substring.h
r8408 r9406 2 2 * @file substring.h 3 3 * @brief a small class to get the parts of a string separated by commas 4 * 5 * This class is also identified as a Tokenizer. It splits up one long 6 * String into multiple small ones by a designated Delimiter. 7 * 8 * Substring is Advanced, and it is possible, to split a string by ',' 9 * but also removing leading and trailing spaces around the comma. 10 * 11 * @example 12 * Split the String std::string st = "1345, The new empire , is , orxonox" 13 * is splitted with: 14 * SubString(st, ',', " \n\t") 15 * into 16 * "1345", "The new empire", "is", "orxonox" 17 * As you can see, the useless spaces around ',' were removed. 4 18 */ 5 19 6 #ifndef _ SUBSTRING_H7 #define _ SUBSTRING_H20 #ifndef __SUBSTRING_H__ 21 #define __SUBSTRING_H__ 8 22 9 23 #include <vector> … … 61 75 62 76 // retrieve a SubSet from the String 63 SubString getSubSet(unsigned int subSetBegin) const;64 SubString getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const;77 SubString subSet(unsigned int subSetBegin) const; 78 SubString subSet(unsigned int subSetBegin, unsigned int subSetEnd) const; 65 79 66 80 // retrieve Information from within … … 70 84 inline unsigned int size() const { return this->strings.size(); }; 71 85 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 72 inline const std::string& operator[](unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; };86 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 73 87 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 74 88 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 89 /** @returns the front of the StringList. */ 90 inline const std::string& front() const { return this->strings.front(); }; 91 /** @returns the back of the StringList. */ 92 inline const std::string& back() const { return this->strings.back(); }; 93 /** @brief removes the back of the strings list. */ 94 inline void pop_back() { this->strings.pop_back(); }; 75 95 76 96 // the almighty algorithm. … … 93 113 private: 94 114 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 95 96 static const std::string emptyString;97 115 }; 98 116 99 #endif /* _ SUBSTRING_H*/117 #endif /* __SUBSTRING_H__ */
Note: See TracChangeset
for help on using the changeset viewer.