blob: adfd34d392844319aa9bbceb49466fe8986b3473 (
plain)
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
72
73
|
#include <iostream>
#include <vector>
std::string input, type;
std::vector<std::string> parts;
std::string tempString;
int i;
int isUppercase(char character) {
return character >= 'A' && character <= 'Z';
}
void getPartsByDelim(std::string delim) {
while (input.find(delim) != std::string::npos) {
parts.push_back(input.substr(0, input.find(delim)));
input = input.substr(input.find(delim)+1);
}
parts.push_back(input);
}
int main() {
while (std::cin >> input && !std::cin.eof()) {
// Separar variable en componentes
parts.clear();
// Entrada CamelCase
if (isUppercase(input[0])) {
tempString.clear();
for (char character : input) {
if (isUppercase(character)) {
parts.push_back(tempString);
tempString.clear();
}
tempString.push_back(tolower(character));
}
parts.push_back(tempString);
parts.erase(parts.begin());
}
// Entrada snake_case
else if (input.find("_") != std::string::npos) {
getPartsByDelim("_");
}
// Entrada kebab-case
else if (input.find("-") != std::string::npos) {
getPartsByDelim("-");
}
else {
parts.push_back(input);
}
// Escribir variable como se pida
std::cin >> type;
if (type == "CamelCase") {
for (std::string word : parts) {
std::cout << (char)toupper(word[0]) << word.substr(1);
}
std::cout << std::endl;
}
else if (type == "snake_case") {
for (i = 0; i < (int)parts.size()-1; i++) {
std::cout << parts[i] << "_";
}
std::cout << parts[i] << std::endl;
}
else if (type == "kebab-case") {
for (i = 0; i < (int)parts.size()-1; i++) {
std::cout << parts[i] << "-";
}
std::cout << parts[i] << std::endl;
}
}
}
|