split.hh
/* split.hh - split a line into words
* Copyright 2007 Bas Wijnen <wijnen@debian.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHEVEK_SPLIT_HH
#define SHEVEK_SPLIT_HH
#include <string>
#include <vector>
namespace shevek
{
class split : public std::vector <std::string>
{
public:
split (std::string const &str = std::string ())
{
load (str);
}
void load (std::string const &str, bool allow_empty = false, std::string const &delimiters = std::string (" \t\v\f\a\n\r\0", 8));
std::string operator[] (unsigned idx) const
{
if (idx >= size ())
return std::string ();
return std::vector <std::string>::operator[] (idx);
}
split sub (unsigned from) const;
};
}
#endif // defined (SHEVEK_SPLIT_HH)
shevek::split::operator[]
std::string operator[](unsigned idx) const
Get a word from the split object.
Definition: split.hh:40
shevek
Definition: args.hh:52
shevek::split
Split a string into words and retrieve them individually.
Definition: split.hh:27
shevek::split::split
split(std::string const &str=std::string())
Create a new split object, and optionally load it with data.
Definition: split.hh:31
shevek::split::load
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.
shevek::split::sub
split sub(unsigned from) const
Get a new split object containing only the last part of this one.