diff --git a/src/aux/aux_format.cpp b/src/aux/aux_format.cpp index 0bab0f6..6cddf4f 100644 --- a/src/aux/aux_format.cpp +++ b/src/aux/aux_format.cpp @@ -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) diff --git a/src/ldpl.cpp b/src/ldpl.cpp index a187a98..3cb627d 100644 --- a/src/ldpl.cpp +++ b/src/ldpl.cpp @@ -121,7 +121,7 @@ void compile(vector &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; } diff --git a/src/ldpl.h b/src/ldpl.h index 13f701c..cc2b126 100644 --- a/src/ldpl.h +++ b/src/ldpl.h @@ -86,6 +86,7 @@ string get_c_number(compiler_state &state, string &expression); string get_c_condition(compiler_state &state, vector tokens); string get_c_condition(compiler_state &state, vector 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);