libshevek
src/split.hh
00001 /* split.hh - split a line into words
00002  * Copyright 2007 Bas Wijnen <wijnen@debian.org>
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef SHEVEK_SPLIT_HH
00019 #define SHEVEK_SPLIT_HH
00020 
00021 #include <string>
00022 #include <vector>
00023 
00024 namespace shevek
00025 {
00027         class split : public std::vector <std::string>
00028         {
00029         public:
00031                 split (std::string const &str = std::string ())
00032                 {
00033                         load (str);
00034                 }
00036                 void load (std::string const &str, bool allow_empty = false, std::string const &delimiters = std::string (" \t\v\f\a\n\r\0", 8));
00038 
00040                 std::string operator[] (unsigned idx) const
00041                 {
00042                         if (idx >= size ())
00043                                 return std::string ();
00044                         return std::vector <std::string>::operator[] (idx);
00045                 }
00047                 split sub (unsigned from) const;
00048         };
00049 }
00050 
00051 #endif // defined (SHEVEK_SPLIT_HH)