-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreStringFunctions.cpp
More file actions
71 lines (58 loc) · 1.65 KB
/
MoreStringFunctions.cpp
File metadata and controls
71 lines (58 loc) · 1.65 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Created by T Alpha 1 on 10/29/2019.
//
#include "MoreStringFunctions.h"
//
// Created by mfbut on 4/8/2019.
//
#include <algorithm>
#include <string>
#include "MoreStringFunctions.h"
#include "CharFunctions.h"
void lowerInPlace(std::string& string) {
for (auto& letter : string) {
letter = tolower(letter);
}
}
std::string lower(std::string string) {
lowerInPlace(string);
return string;
}
void stripInPlace(std::string& string, const std::string& charsToRemove) {
lstripInPlace(string, charsToRemove);
rstripInPlace(string, charsToRemove);
}
void lstripInPlace(std::string& string, const std::string& charsToRemove) {
auto itr = string.begin();
for (; itr != string.end(); ++itr) {
if (!contains(charsToRemove, *itr)) {
break;
}
}
string.erase(string.begin(), itr);
}
void rstripInPlace(std::string& string, const std::string& charsToRemove) {
auto itr = string.rbegin();
for (; itr != string.rend(); ++itr) {
if (!contains(charsToRemove, *itr)) {
break;
}
}
string.erase(itr.base(), string.end());
}
std::vector<std::string> split(const std::string& string, const std::string& delimiter) {
std::vector<std::string> strings;
std::size_t pos;
unsigned int substringStart = 0;
for (pos = string.find(delimiter);
pos != std::string::npos;
pos = string.find(delimiter, pos + delimiter.size())) {
//add the substring to our vector of strings
strings.emplace_back(string, substringStart, pos - substringStart);
substringStart = pos + 1;
}
if(substringStart < string.size()){
strings.emplace_back(string, substringStart, string.size() - substringStart);
}
return strings;
}