Computational Embodied Neuroscience Simulator  1.1
3D simulation library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
cens_utils.cpp
Go to the documentation of this file.
1 // Computational Embodied Neuroscience Simulator (CENS) Library
2 // Copyright (c) 2010 Francesco Mannella
3 //
4 // cens_utils.cpp
5 // Copyright (c) 2010 Francesco Mannella
6 //
7 // This file is part of CENS library.
8 //
9 // CENS library is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // CENS library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with CENS library. If not, see <http://www.gnu.org/licenses/>.
21 
22 #include "cens_utils.h"
23 #include <cassert>
24 
25 namespace cens {
26 
30 
31  float scalarFromString(std::string str) {
32  return std::strtod( str.c_str(), 0 );
33  }
34 
35 
36  std::string str_replace(std::string str,
37  const std::string &searchString,
38  const std::string &replaceString )
39  {
40 
41  assert ( searchString != replaceString );
42 
43  std::string::size_type pos = 0;
44  while ( (pos = str.find(searchString, pos)) != std::string::npos ) {
45  str.replace( pos, searchString.size(), replaceString );
46  pos++;
47  }
48 
49  return str;
50  }
51 
52 
53 
54 
55  std::vector<std::string> str_split(std::string str,
56  const std::string &sep) {
57 
58  std::vector<std::string> res;
59  std::string mod_sep(sep);
60  std::string tmp;
61 
62  mod_sep=str_replace(mod_sep," ","_SPACE_");
63  str=str_replace(str," ","_SPACE_");
64 
65  str=str_replace(str,mod_sep," ");
66  std::stringstream stream(str);
67  while(!stream.eof()) {
68  stream >> tmp;
69  res.push_back(str_replace(tmp,"_SPACE_"," "));
70  }
71 
72 
73  return res;
74  }
75 
76 
77  bool str_match(const std::string &str,
78  const std::string &comp) {
79 
80  size_t found = str.find(comp);
81  return (found != std::string::npos)?true:false;
82 
83  }
84 
85 }
Computational Embodied Neuroscience Simulator library.
Definition: cens_engine.cpp:29
std::string str_replace(std::string str, const std::string &searchString, const std::string &replaceString)
Definition: cens_utils.cpp:36
std::vector< std::string > str_split(std::string str, const std::string &sep)
Definition: cens_utils.cpp:55
float scalarFromString(std::string str)
Definition: cens_utils.cpp:31
bool str_match(const std::string &str, const std::string &comp)
Definition: cens_utils.cpp:77