GCC Code Coverage Report


Directory: ./
File: include/pinocchio/utils/string.hpp
Date: 2024-08-27 18:20:05
Exec Total Coverage
Lines: 0 8 0.0%
Branches: 0 2 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 INRIA
3 //
4
5 #ifndef __pinocchio_utils_string_hpp__
6 #define __pinocchio_utils_string_hpp__
7
8 #include <string>
9
10 namespace pinocchio
11 {
12
13 ///
14 /// \brief Replace string from with to in input_str.
15 ///
16 /// \param[in] input_str string on which replace operates.
17 /// \param[in] from The string to replace.
18 /// \param[in] to The string to replace the old value with.
19 ///
20 /// \returns true if from has been found within input_str
21 ///
22 inline bool replace(std::string & input_str, const std::string & from, const std::string & to)
23 {
24 bool has_from = false;
25 size_t start_pos = input_str.find(from);
26
27 while (start_pos != std::string::npos)
28 {
29 has_from = true;
30 input_str.replace(start_pos, from.length(), to);
31 start_pos = input_str.find(from);
32 }
33
34 return has_from;
35 }
36 } // namespace pinocchio
37
38 #endif // __pinocchio_utils_string_hpp__
39