supereight
str_utils.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019-2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
3  * SPDX-FileCopyrightText: 2019-2021 Nils Funk
4  * SPDX-FileCopyrightText: 2019-2021 Sotiris Papatheodorou
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef SE_STR_UTILS_HPP
9 #define SE_STR_UTILS_HPP
10 
11 
12 
13 #include <Eigen/Dense>
14 #include <iomanip>
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 
19 
20 
21 namespace se {
22 namespace str_utils {
23 
24 
25 
34 bool begins_with(const std::string& s, const std::string& prefix);
35 
44 bool ends_with(const std::string& s, const std::string& suffix);
45 
54 bool is_int(const std::string& s, const bool accept_negative = true);
55 
64 bool is_float(const std::string& s, const bool accept_negative = true);
65 
72 void remove_prefix(std::string& s, const std::string& prefix);
73 
80 void remove_suffix(std::string& s, const std::string& suffix);
81 
91 std::vector<std::string>
92 split_str(const std::string& s, const char delim, const bool ignore_consec = false);
93 
99 void to_lower(std::string& s);
100 
106 void to_upper(std::string& s);
107 
108 static constexpr int default_width = 33;
109 
120 template<typename EigenMatrixT>
121 std::string eigen_matrix_to_pretty_str(const EigenMatrixT& M,
122  const std::string& M_name = "",
123  const int width = default_width);
124 
136 template<typename EigenVectorT>
137 std::string eigen_vector_to_pretty_str(const EigenVectorT& v,
138  const std::string& v_name = "",
139  const std::vector<std::string>& e_names = {},
140  const int width = default_width);
141 
152 template<typename T>
153 std::string vector_to_pretty_str(const std::vector<T>& v,
154  const std::string& v_name = "",
155  const int width = default_width);
156 
168 template<typename EigenVector3T>
169 std::string volume_to_pretty_str(const EigenVector3T& vol,
170  const std::string& vol_name = "",
171  const int width = default_width);
172 
182 std::string bool_to_pretty_str(const bool state,
183  const std::string& state_name = "",
184  const int width = default_width);
185 
195 std::string str_to_pretty_str(const std::string& string,
196  const std::string& string_name = "",
197  const int width = default_width);
198 
210 template<typename ValueT>
211 std::string value_to_pretty_str(const ValueT& val,
212  const std::string& val_name = "",
213  const std::string& val_unit = "",
214  const int width = default_width);
215 
224 std::string header_to_pretty_str(const std::string& header_name, const int width = default_width);
225 
230 std::string expand_user(const std::string& path);
231 
235 std::string resolve_relative_path(const std::string& relative_path, const std::string& base_dir);
236 
237 } // namespace str_utils
238 } // namespace se
239 
240 
241 
242 #include "impl/str_utils_impl.hpp"
243 
244 
245 
246 #endif // SE_STR_UTILS_HPP
bool is_int(const std::string &s, const bool accept_negative=true)
Verify if a string is a integer.
bool begins_with(const std::string &s, const std::string &prefix)
Verify if a string starts with a given prefix.
std::vector< std::string > split_str(const std::string &s, const char delim, const bool ignore_consec=false)
Split a string into a vector of substrings based on a delimiter.
void to_lower(std::string &s)
Convert a string to all lower case characters.
static constexpr int default_width
Definition: str_utils.hpp:108
std::string eigen_vector_to_pretty_str(const EigenVectorT &v, const std::string &v_name="", const std::vector< std::string > &e_names={}, const int width=default_width)
Convert a matrix name and Eigen::Vector value to a standardised string output.
std::string expand_user(const std::string &path)
Return the result of expanding a leading ~ in path.
std::string bool_to_pretty_str(const bool state, const std::string &state_name="", const int width=default_width)
Convert a bool name and value to a standardised string output.
bool ends_with(const std::string &s, const std::string &suffix)
Verify if a string starts with a given prefix.
void to_upper(std::string &s)
Convert a string to all upper case characters.
std::string eigen_matrix_to_pretty_str(const EigenMatrixT &M, const std::string &M_name="", const int width=default_width)
Convert a matrix name and Eigen::Matrix value to a standardised string output.
std::string value_to_pretty_str(const ValueT &val, const std::string &val_name="", const std::string &val_unit="", const int width=default_width)
Convert a matrix name, value and unit to a standardised string output.
std::string header_to_pretty_str(const std::string &header_name, const int width=default_width)
Convert header name to a standardised string output.
std::string volume_to_pretty_str(const EigenVector3T &vol, const std::string &vol_name="", const int width=default_width)
Convert a volume name and value to a standardised string output (values seperated by &#39;x&#39;)...
void remove_prefix(std::string &s, const std::string &prefix)
Remove a given prefix from a string.
std::string resolve_relative_path(const std::string &relative_path, const std::string &base_dir)
Return the path resulting by resolving relative_path relative to the directory base_dir.
std::string str_to_pretty_str(const std::string &string, const std::string &string_name="", const int width=default_width)
Convert a string name and value to a standardised string output.
void remove_suffix(std::string &s, const std::string &suffix)
Remove a given suffix from a string.
std::string vector_to_pretty_str(const std::vector< T > &v, const std::string &v_name="", const int width=default_width)
Convert a matrix name and Eigen::Vector value to a standardised string output.
bool is_float(const std::string &s, const bool accept_negative=true)
Verify if a string is a float.
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17