blob: 7016ebb80cb40f52827b63fbcbb1244b8ad4ce4d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
}
|