#include <iostream>
#include <string>
#include <regex>
#include <cctype>
std::string getPascalCase(const std::string& input) {
std::string str = input;
if (str.find(" ") == std::string::npos) {
str = std::regex_replace(str, std::regex("([a-z])([A-Z])"), "$1 $2");
}
std::string result;
bool capitalizeNext = true;
for (char ch : str) {
if (ch == ' ' || ch == '_') {
capitalizeNext = true;
} else if (capitalizeNext) {
result += static_cast<char>(std::toupper(ch));
capitalizeNext = false;
} else {
result += static_cast<char>(std::tolower(ch));
}
}
return result;
}
int main() {
std::cout << getPascalCase("get file content") << std::endl;
std::cout << getPascalCase("get_file_content") << std::endl;
std::cout << getPascalCase("get______file___content") << std::endl;
std::cout << getPascalCase("get______file____ content") << std::endl;
std::cout << getPascalCase("GET FILE CONTENT") << std::endl;
std::cout << getPascalCase("get file content") << std::endl;
std::cout << getPascalCase("getFileContent") << std::endl;
}
/*
run:
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
*/