string_tools.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_STRING_TOOLS_H
28 #define G2O_STRING_TOOLS_H
29 
30 #include <string>
31 #include <sstream>
32 #include <cstdlib>
33 #include <vector>
34 
35 #include "macros.h"
36 
37 namespace g2o {
38 
40 // @{
41 
49  std::string trim(const std::string& s);
50 
54  std::string trimLeft(const std::string& s);
55 
59  std::string trimRight(const std::string& s);
60 
64  std::string strToLower(const std::string& s);
65 
69  std::string strToUpper(const std::string& s);
70 
75 template <typename OutputIterator>
76 OutputIterator readInts(const char* str, OutputIterator out)
77 {
78  char* cl = (char*)str;
79  char* cle = cl;
80  while (1) {
81  int id = strtol(cl, &cle, 10);
82  if (cl == cle)
83  break;
84  *out++ = id;
85  cl = cle;
86  }
87  return out;
88 }
89 
94 template <typename OutputIterator>
95 OutputIterator readFloats(const char* str, OutputIterator out)
96 {
97  char* cl = (char*)str;
98  char* cle = cl;
99  while (1) {
100  double val = strtod(cl, &cle);
101  if (cl == cle)
102  break;
103  *out++ = val;
104  cl = cle;
105  }
106  return out;
107 }
108 
113  std::string formatString(const char* fmt, ...) G2O_ATTRIBUTE_FORMAT12;
114 
118  int strPrintf(std::string& str, const char* fmt, ...) G2O_ATTRIBUTE_FORMAT23;
119 
123 template<typename T>
124 bool convertString(const std::string& s, T& x, bool failIfLeftoverChars = true)
125 {
126  std::istringstream i(s);
127  char c;
128  if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
129  return false;
130  return true;
131 }
132 
137 template<typename T>
138 T stringToType(const std::string& s, bool failIfLeftoverChars = true)
139 {
140  T x;
141  convertString(s, x, failIfLeftoverChars);
142  return x;
143 }
144 
148  bool strStartsWith(const std::string & str, const std::string& substr);
149 
153  bool strEndsWith(const std::string & str, const std::string& substr);
154 
159  std::string strExpandFilename(const std::string& filename);
160 
164  std::vector<std::string> strSplit(const std::string& s, const std::string& delim);
165 
170  int readLine(std::istream& is, std::stringstream& currentLine);
171 
172 // @}
173 
174 } // end namespace
175 
176 #endif
OutputIterator readFloats(const char *str, OutputIterator out)
Definition: string_tools.h:95
filename
int readLine(std::istream &is, std::stringstream &currentLine)
T stringToType(const std::string &s, bool failIfLeftoverChars=true)
Definition: string_tools.h:138
XmlRpcServer s
#define G2O_ATTRIBUTE_FORMAT12
Definition: macros.h:99
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
std::string trim(const std::string &s)
std::string trimLeft(const std::string &s)
bool strStartsWith(const std::string &s, const std::string &start)
std::string strExpandFilename(const std::string &filename)
std::string trimRight(const std::string &s)
std::string strToLower(const std::string &s)
OutputIterator readInts(const char *str, OutputIterator out)
Definition: string_tools.h:76
int strPrintf(std::string &str, const char *fmt,...)
bool convertString(const std::string &s, T &x, bool failIfLeftoverChars=true)
Definition: string_tools.h:124
TFSIMD_FORCE_INLINE const tfScalar & x() const
#define G2O_ATTRIBUTE_FORMAT23
Definition: macros.h:100
std::string strToUpper(const std::string &s)
bool strEndsWith(const std::string &s, const std::string &end)
std::string formatString(const char *fmt,...)


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47