From 21f7c930aea8070bb4eaecd12226a85e4f9c20ba Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Wed, 26 Feb 2014 10:02:27 +0100 Subject: [PATCH] src/system/helpers.cpp: Add str_replace() function --- src/system/helpers.cpp | 15 +++++++++++++++ src/system/helpers.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index c4a80b7f5..5b51e0601 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -402,6 +402,21 @@ time_t toEpoch(std::string &date) } +std::string& str_replace(const std::string &search, const std::string &replace, std::string &text) +{ + if (search.empty() || text.empty()) + return text; + + size_t searchLen = search.length(); + while (1) { + size_t pos = text.find(search); + if (pos == std::string::npos) + break; + text.replace(pos, searchLen, replace); + } + return text; +} + CFileHelpers::CFileHelpers() { FileBufSize = 0xFFFF; diff --git a/src/system/helpers.h b/src/system/helpers.h index 1a68cb316..74b9e0208 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -54,6 +54,7 @@ std::string getFileExt(std::string &file); std::string getNowTimeStr(const char* format); std::string trim(std::string &str, const std::string &trimChars = " \n\r\t"); time_t toEpoch(std::string &date); +std::string& str_replace(const std::string &search, const std::string &replace, std::string &text); class CFileHelpers {