Añadida función para pasar cadenas a mayúsculas

This commit is contained in:
2023-10-09 09:02:44 +02:00
parent a68ffa8e21
commit 20c63c7ef5
3 changed files with 22 additions and 3 deletions

View File

@@ -566,7 +566,23 @@ std::string toLower(std::string str)
lower[i] = (c >= 65 && c <= 90) ? c + 32 : c;
}
lower[str.size()] = 0;
std::string nova(lower);
std::string result(lower);
free(lower);
return nova;
return result;
}
// Convierte una cadena a mayúsculas
std::string toUpper(std::string str)
{
const char *original = str.c_str();
char *upper = (char *)malloc(str.size() + 1);
for (int i = 0; i < (int)str.size(); ++i)
{
char c = original[i];
upper[i] = (c >= 97 && c <= 122) ? c - 32 : c;
}
upper[str.size()] = 0;
std::string result(upper);
free(upper);
return result;
}