libshevek
split.hh
1 /* split.hh - split a line into words
2  * Copyright 2007 Bas Wijnen <wijnen@debian.org>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SHEVEK_SPLIT_HH
19 #define SHEVEK_SPLIT_HH
20 
21 #include <string>
22 #include <vector>
23 
24 namespace shevek
25 {
27  class split : public std::vector <std::string>
28  {
29  public:
31  split (std::string const &str = std::string ())
32  {
33  load (str);
34  }
36  void load (std::string const &str, bool allow_empty = false, std::string const &delimiters = std::string (" \t\v\f\a\n\r\0", 8));
38 
40  std::string operator[] (unsigned idx) const
41  {
42  if (idx >= size ())
43  return std::string ();
44  return std::vector <std::string>::operator[] (idx);
45  }
47  split sub (unsigned from) const;
48  };
49 }
50 
51 #endif // defined (SHEVEK_SPLIT_HH)
std::string operator[](unsigned idx) const
Get a word from the split object.
Definition: split.hh:40
Definition: args.hh:52
Split a string into words and retrieve them individually.
Definition: split.hh:27
split(std::string const &str=std::string())
Create a new split object, and optionally load it with data.
Definition: split.hh:31
void load(std::string const &str, bool allow_empty=false, std::string const &delimiters=std::string(" \t\v\f\a\n\r\0", 8))
Load new data into an existing split object.
split sub(unsigned from) const
Get a new split object containing only the last part of this one.