ocra-recipes
Doxygen documentation for the ocra-recipes repository
StringUtilities.h
Go to the documentation of this file.
1 #ifndef OCRA_UTIL_STRING_UTILITIES_H
2 #define OCRA_UTIL_STRING_UTILITIES_H
3 
4 #include <algorithm>
5 #include <string>
6 #include <vector>
7 #include <Eigen/Dense>
8 
9 namespace ocra {
10  namespace util {
11 
12 
13 inline std::string convertToLowerCase(const std::string& originalString)
14 {
15  std::string newString = originalString;
16  std::transform(newString.begin(), newString.end(), newString.begin(), ::tolower);
17  return newString;
18 }
19 
20 inline std::string convertToUpperCase(const std::string& originalString)
21 {
22  std::string newString = originalString;
23  std::transform(newString.begin(), newString.end(), newString.begin(), ::toupper);
24  return newString;
25 }
26 
27 inline Eigen::VectorXd stringToVectorXd(const char * valueString)
28 {
29  std::stringstream valueStream;
30  std::vector<double> doubleVector;
31 
32  valueStream << valueString;
33 
34  do
35  {
36  // read as many numbers as possible.
37  for (double number; valueStream >> number;) {
38  doubleVector.push_back(number);
39  }
40  // consume and discard token from stream.
41  if (valueStream.fail())
42  {
43  valueStream.clear();
44  std::string token;
45  valueStream >> token;
46  }
47  }
48  while (!valueStream.eof());
49 
50  int nRows = doubleVector.size();
51  Eigen::VectorXd eigenVector(nRows);
52  for (int i=0; i<nRows; i++)
53  {
54  eigenVector[i] = doubleVector[i];
55  }
56  return eigenVector;
57 }
58 
59 
60 inline Eigen::VectorXi stringToVectorXi(const char * valueString)
61 {
62  std::stringstream valueStream;
63  std::vector<int> doubleVector;
64 
65  valueStream << valueString;
66 
67  do
68  {
69  // read as many numbers as possible.
70  for (int number; valueStream >> number;) {
71  doubleVector.push_back(number);
72  }
73  // consume and discard token from stream.
74  if (valueStream.fail())
75  {
76  valueStream.clear();
77  std::string token;
78  valueStream >> token;
79  }
80  }
81  while (!valueStream.eof());
82 
83  int nRows = doubleVector.size();
84  Eigen::VectorXi eigenVector(nRows);
85  for (int i=0; i<nRows; i++)
86  {
87  eigenVector[i] = doubleVector[i];
88  }
89  return eigenVector;
90 }
91 
92 
93 
94 
95  } // namespace ocra
96 } // namespace util
97 #endif // OCRA_UTIL_STRING_UTILITIES_H
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Eigen::VectorXd stringToVectorXd(const char *valueString)
Eigen::VectorXi stringToVectorXi(const char *valueString)
std::string convertToLowerCase(const std::string &originalString)
std::string convertToUpperCase(const std::string &originalString)