source: trunk/yat/split.cc @ 1556

Last change on this file since 1556 was 1556, checked in by Peter Johansson, 9 years ago

update to latest yat

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// $Id: split.cc 2881 2012-11-18 01:28:05Z peter $
2
3/*
4  Copyright (C) 2010, 2012 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "split.h"
25
26#include <string>
27#include <vector>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33namespace detail {
34
35  /*
36    implementation of split functions is declared in private namespace
37    and only available in this file.
38   */
39  template<typename T>
40  void split(std::vector<std::string>& vec, const std::string& str, T delim)
41  {
42    size_t pos=0;
43    while (true) {
44      size_t end = str.find_first_of(delim, pos);
45      vec.push_back(str.substr(pos, end-pos));
46      if (end == std::string::npos)
47        break;
48      pos = end+1;
49    }
50  }
51} // end of namespace detail
52
53
54  void split(std::vector<std::string>& vec, const std::string& str, char delim)
55  {
56    detail::split(vec, str, delim);
57  }
58
59
60  void split(std::vector<std::string>& vec, const std::string& str,
61             const std::string& delim)
62  {
63    detail::split(vec, str, delim);
64  }
65
66}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.