From 053bf6e1ee6018d55d6fb462f871808522207df0 Mon Sep 17 00:00:00 2001 From: Lartu <11744462+Lartu@users.noreply.github.com> Date: Thu, 24 Oct 2024 02:39:29 -0300 Subject: [PATCH] Fix backslashes in STORE QUOTE --- src/aux/aux_format.cpp | 12 ++++++++++++ src/ldpl.cpp | 2 +- src/ldpl.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) 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);