Skip to content

Commit

Permalink
Fix backslashes in STORE QUOTE
Browse files Browse the repository at this point in the history
  • Loading branch information
Lartu committed Oct 24, 2024
1 parent e216876 commit 053bf6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/aux/aux_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ string &escape_c_quotes(string &str) {
return str;
}

string &escape_c_backslashes(string &str) {
// -- Replaces all " in the passed string for \" --
for (unsigned int i = 0; i < str.size(); ++i) {
if (str[i] == '\\') {
str.erase(i, 1);
str.insert(i, "\\\\");
++i;
}
}
return str;
}

string expandHomeDirectory(string &filename) {
// -- Expands a home directory (normaly when the character ~ is used) --
#if defined(_WIN32)
Expand Down
2 changes: 1 addition & 1 deletion src/ldpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void compile(vector<string> &lines, compiler_state &state)
}

// No END QUOTE, emit the line as C++
state.add_code("\"\" \"" + escape_c_quotes(line) + "\\n\"", state.where);
state.add_code("\"\" \"" + escape_c_quotes(escape_c_backslashes(line)) + "\\n\"", state.where);
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/ldpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ string get_c_number(compiler_state &state, string &expression);
string get_c_condition(compiler_state &state, vector<string> tokens);
string get_c_condition(compiler_state &state, vector<string> tokens, unsigned int &ct);
string &escape_c_quotes(string &str);
string &escape_c_backslashes(string &str);
void load_and_compile(string &filename, compiler_state &state);
void accept_and_compile(compiler_state &state);
void replace_whitespace(string &code);
Expand Down

0 comments on commit 053bf6e

Please sign in to comment.