-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_stuff.cpp
More file actions
40 lines (35 loc) · 1.24 KB
/
string_stuff.cpp
File metadata and controls
40 lines (35 loc) · 1.24 KB
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
38
39
40
#include "config.h"
#include <string>
#include <vector>
std::string string_to_lower(const std::string &str) {
std::string new_str = "";
for (char ch : str) {
// ugh brother, ugh. ChatGPT doing some disgustring bug fixes
new_str += static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
}
return new_str;
}
std::vector<int> find_substrings(const Config &cfg, std::string larger_string) {
std::string substring = cfg.substring;
if (cfg.case_insensitive) {
larger_string = string_to_lower(larger_string);
substring = string_to_lower(cfg.substring);
}
std::vector<int> list;
int substring_length = cfg.substring.length();
for (size_t i = 0; i + substring_length <= larger_string.length(); i++) {
if (larger_string.compare(i, substring_length, substring) == 0) {
list.push_back((int)i);
}
}
return list;
}
std::string remove_dashes(const std::string &str) {
std::string new_str = "";
for (char ch : str) {
if (ch != '-') {
new_str += ch;
}
}
return new_str;
}