diff options
author | Cara Salter <cara@devcara.com> | 2023-03-30 12:52:19 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-03-30 12:52:19 -0400 |
commit | 527b7ab2df126bb2f480999049ed05b057a6ef83 (patch) | |
tree | 8edb7c72d7fae0e7d2c768f5f5dd65c2268c75a0 /src/util.cpp | |
parent | c8befe7c95b18869f995c4f2cbc2f4cf9c91924f (diff) | |
download | 142bot-527b7ab2df126bb2f480999049ed05b057a6ef83.tar.gz 142bot-527b7ab2df126bb2f480999049ed05b057a6ef83.zip |
modules!
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..7016ebb --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,37 @@ +/* + * ===================================================================================== + * + * Filename: util.cpp + * + * Description: + * + * Version: 1.0 + * Created: 03/30/2023 11:44:11 AM + * Revision: none + * Compiler: gcc + * + * Author: Cara Salter (muirrum), cara@devcara.com + * Organization: Worcester Polytechnic Institute + * + * ===================================================================================== + */ +#include <stdlib.h> +#include <string> +#include <142bot/util.hpp> + +std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace) { + size_t pos = 0; + + std::string subject_lc = lowercase(subject); + std::string search_lc = lowercase(search); + std::string replace_lc = lowercase(replace); + + while((pos = subject_lc.find(search_lc, pos)) != std::string::npos) { + + subject.replace(pos, search.length(), replace); + subject_lc.replace(pos, search_lc.length(), replace_lc); + + pos += replace.length(); + } + return subject; +} |