I found some useful snippets in "playground", however, some of them make me a bit confused, such as "stringToBool" and "stringToString" in Python3
the definitions are:
stringToString : Parses string to quoted string
stringToBool : Converts string to bool
Are the original codes doing what they are supported to do?
The original codes in Python3 are as follows:
def stringToBool(input):
return json.dumps(input)
def stringToString(input):
import json
return json.loads(input)additionally, here are the C++ codes, which make sense
bool stringToBool(string input) {
transform(input.begin(), input.end(), input.begin(), ::tolower);
return input == "true";
}
string stringToString(string input) {
assert(input.length() >= 2);
string result;
for (int i = 1; i < input.length() -1; i++) {
char currentChar = input[i];
if (input[i] == '\\') {
char nextChar = input[i+1];
switch (nextChar) {
case '\"': result.push_back('\"'); break;
case '/' : result.push_back('/'); break;
case '\\': result.push_back('\\'); break;
case 'b' : result.push_back('\b'); break;
case 'f' : result.push_back('\f'); break;
case 'r' : result.push_back('\r'); break;
case 'n' : result.push_back('\n'); break;
case 't' : result.push_back('\t'); break;
default: break;
}
i++;
} else {
result.push_back(currentChar);
}
}
return result;
}