Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 18 additions & 46 deletions Architecture/API_Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ API_Generator::API_Generator(){
APIs.clear();
}

string escape(string str) {
string s;
for(size_t i = 0; i != str.size(); i++) {
char c = str[i];
if (c == '\\') {
s += "\\\\";
} else if (c == '"') {
s += "\\\"";
} else {
s += c;
}
}
return s;
}

void API_Generator::Generate_ServicesBundles(){

IoTDDL_Parser DDLM;
Expand Down Expand Up @@ -257,7 +272,7 @@ void API_Generator::Generate_ServicesBundles(){
std::size_t foundy = line.find(")");
if (foundx!=std::string::npos){
std::string value = line.substr(foundx+1, foundy-foundx-1);
instruction = "std::cout << " + value + " << std::endl;";
instruction = "std::cout << " + escape(value) + " << std::endl;";
def << "source = \"" << instruction << "\";" << std::endl;
}
continue;
Expand All @@ -269,7 +284,7 @@ void API_Generator::Generate_ServicesBundles(){
std::size_t foundy = line.find(")");
if (foundx!=std::string::npos){
std::string value = line.substr(foundx+1, foundy-foundx-1);
instruction = "std::cout << " + value + " << std::endl;";
instruction = "std::cout << " + escape(value) + " << std::endl;";
def << "source = \"" << instruction << "\";" << std::endl;
}
continue;
Expand Down Expand Up @@ -334,50 +349,7 @@ void API_Generator::Generate_ServicesBundles(){



found = line.find("}");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("{");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("while(");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("for(");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("if(");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("else if(");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
found = line.find("else");
if (found!=std::string::npos){
instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what these codes are used for.


instruction = line;
instruction = escape(line);
def << "source = \"" << instruction << "\";" << std::endl;
}

Expand Down