DeSiGNAR  0.5a
Data Structures General Library
stringutilities.H
Go to the documentation of this file.
1 /*
2  This file is part of Designar.
3  Copyright (C) 2017 by Alejandro J. Mujica
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Any user request of this software, write to
19 
20  Alejandro Mujica
21 
22  aledrums@gmail.com
23 */
24 
25 # ifndef DSGSTRINGUTILITIES_H
26 # define DSGSTRINGUTILITIES_H
27 
28 # include <types.H>
29 
30 namespace Designar
31 {
32  template <typename T> class DynArray;
33 
34  template <typename ContainerType = DynArray<std::string>>
35  ContainerType split_string(const std::string &, const std::string &);
36 
37  template <typename ContainerType>
38  ContainerType split_string(const std::string & str, const std::string & sep)
39  {
40  ContainerType ss;
41 
42  size_t sep_sz = sep.size();
43 
44  size_t beg = 0;
45  size_t end = str.find(sep);
46 
47  while (end != std::string::npos)
48  {
49  ss.append(str.substr(beg, end - beg));
50  beg = end + sep_sz;
51  end = str.find(sep, beg);
52  }
53 
54  ss.append(str.substr(beg, str.size() - beg));
55 
56  return ss;
57  }
58 
59 } // end namespace Designar
60 
61 # endif // DSGSTRINGUTILITIES_H
ContainerType split_string(const std::string &, const std::string &)
Definition: stringutilities.H:38
Definition: array.H:32