mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
string utils: add string_replace
Change-Id: I86a2b1564be127f70dd991b86fe0b14440cee299
This commit is contained in:
@ -121,4 +121,13 @@ split_string_to_unsigned(const std::string &s, char delim)
|
||||
return result;
|
||||
}
|
||||
|
||||
void string_replace(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
size_t start_pos = 0;
|
||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jami
|
||||
|
@ -19,8 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -67,6 +66,6 @@ split_string(const std::string& s, char sep);
|
||||
std::vector<unsigned>
|
||||
split_string_to_unsigned(const std::string& s, char sep);
|
||||
|
||||
} // namespace jami
|
||||
void string_replace(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
#endif
|
||||
} // namespace jami
|
||||
|
Reference in New Issue
Block a user