GRINS-0.8.0
string_utils.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This 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 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include "grins/string_utils.h"
26 
27 namespace GRINS
28 {
29  namespace StringUtilities
30  {
31  void split_string( const std::string& input,
32  const std::string& delimiter,
33  std::vector<std::string>& results )
34  {
35  // Skip delimiters at beginning.
36  std::string::size_type first_pos = input.find_first_not_of(delimiter, 0);
37 
38  std::string::size_type pos = input.find(delimiter, first_pos);
39 
40  while (std::string::npos != pos || std::string::npos != first_pos)
41  {
42  // Found a token, add it to the vector.
43  results.push_back(input.substr(first_pos, pos - first_pos));
44 
45  // Skip delimiters. Note the "not_of"
46  first_pos = input.find_first_not_of(delimiter, pos);
47 
48  // Find next delimiter
49  pos = input.find(delimiter, first_pos);
50  }
51  }
52 
53  void split_string_real( const std::string& input,
54  const std::string& delimiter,
55  std::vector<libMesh::Real>& results )
56  {
57  std::vector<std::string> string_vec;
58 
59  split_string(input,delimiter,string_vec);
60 
61  results.resize(string_vec.size());
62 
63  for (unsigned int i=0; i<string_vec.size(); i++)
64  results[i] = string_to_T<libMesh::Real>(string_vec[i]);
65  }
66  } // end namespace StringUtilities
67 } // end namespace GRINS
GRINS namespace.
void split_string_real(const std::string &input, const std::string &delimiter, std::vector< libMesh::Real > &results)
Definition: string_utils.C:53
void split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
Definition: string_utils.C:31

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1