MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / format_as_variable

Function format_as_variable

src/codegenerator.cpp:8546–8581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8544}
8545
8546std::string format_as_variable(std::string str){
8547 std::replace(str.begin(), str.end(), '.', '_');
8548 int first = str.substr(0, 1).c_str()[0];
8549 if (isdigit(first)) {
8550 std::string remaining = str.substr(1);
8551 switch (first) {
8552 case 48:
8553 return "zero" + remaining;
8554 case 49:
8555 return "one" + remaining;
8556 case 50:
8557 return "two" + remaining;
8558 case 51:
8559 return "three" + remaining;
8560 case 52:
8561 return "four" + remaining;
8562 case 53:
8563 return "five" + remaining;
8564 case 54:
8565 return "six" + remaining;
8566 case 55:
8567 return "seven" + remaining;
8568 case 56:
8569 return "eight" + remaining;
8570 case 57:
8571 return "nine" + remaining;
8572 default:
8573 throw std::runtime_error("Unrecognized digit");
8574 }
8575 }
8576 else {
8577 if (!isalpha(first) && first != 95 /* "_" */)
8578 throw std::runtime_error("Variable must begin with alphanumeric character or '_'.");
8579 }
8580 return str;
8581}
8582
8583bool CodeGen_pySAM::GenerateCode(const int& array_matrix_threshold)
8584{

Callers 1

InputMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected