I have some string which I need to manipulate to be lowercase and replace some characters to blanks using regex.
The Java equivalent is:
str.toLowerCase();
str.replaceAll("[^a-z]", "");
str.replaceAll("\\s", "");
Within a c++03
constraint, and without using Boost or another library, how can I achieve the same functionality in C++? The version of g++ the server I am running on is 4.8.5 20150623
.
Lowercasing is simple:
char asciiToLower(char c) {
if (c <= 'Z' && c >= 'A') {
return c - ('A' - 'a');
}
return c;
}
std::string manipulate(std::string str) {
for (std::string::iterator it = str.begin(); it != str.end(); ++it) {
it = asciiToLower(it);
}
}
But what about the other two?