consolidate all repos to one for archive

This commit is contained in:
2025-01-28 13:46:42 +01:00
commit a6610fbc7a
5350 changed files with 2705721 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
#include "TextUtility.h"
#include <string>
#include <cctype>
std::string TextUtility::capitalize(const std::string &str) {
std::string ret;
bool nex = false;
auto it = str.begin();
ret.push_back(std::toupper(*it));
it++;
while (it != str.end()) {
if (nex) {
ret.push_back(std::toupper(*it));
nex = false;
} else {
ret.push_back(*it);
}
if ('.' == *it || '!' == *it || '?' == *it) nex = true;
it++;
}
return ret;
}
std::string TextUtility::toUpperCase(const std::string &str) {
std::string ret;
auto it = str.begin();
while (it != str.end()) {
ret.push_back(std::toupper(*it));
it++;
}
return ret;
}
bool TextUtility::isNumeric(const std::string &str) {
auto it = str.begin();
while (it != str.end() && std::isdigit(*it)) ++it;
return !str.empty() && it == str.end();
}
int TextUtility::contains(const std::string &str, const std::string &substr) {
std::size_t found = str.find(substr);
if (found != std::string::npos) return found;
return -1;
}
std::string TextUtility::addSpaces(const std::string &str) {
std::string ret;
auto it = str.begin();
while (it != str.end()) {
ret.push_back(*it);
ret.push_back(' ');
it++;
}
return ret;
}
std::string TextUtility::removeDuplicatedSpaces(const std::string &str) {
std::string ret;
bool next = false;
auto it = str.begin();
while (it != str.end()) {
if (next) {
if(*it != ' ') {
ret.push_back(*it);
}
next = false;
} else {
ret.push_back(*it);
}
if (*it == ' ') next = true;
it++;
}
return ret;
}