diff options
| author | Matthias Melcher <git@matthiasm.com> | 2021-12-15 19:29:12 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2021-12-15 19:38:09 +0100 |
| commit | 7161cad2c75c323fe8c9316ab7ac14e84411b37f (patch) | |
| tree | 747a1ec72f30e00d9b5999bb5a32f6bbcb16897d /fluid/code.cxx | |
| parent | f57b074378d69d19eb5a70e6335054bada06919a (diff) | |
#329 #318: Fixed Fluid indenting and trailing whitespace
Diffstat (limited to 'fluid/code.cxx')
| -rw-r--r-- | fluid/code.cxx | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx index 11d8d2d4e..ec61902f1 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -410,18 +410,35 @@ void write_hc(const char *indent, int n, const char* c, const char *com) { Write one or more lines of code, indenting each one of them. \param[in] textlines one or more lines of text, seperated by \\n */ -void write_c_indented(const char *textlines) { +void write_c_indented(const char *textlines, int inIndent, char inTrailwWith) { if (textlines) { - indentation++; + indentation += inIndent; for (;;) { + int line_len; const char *newline = strchr(textlines, '\n'); - if (!newline) break; - write_c("%s%.*s\n", indent(), (int)(newline-textlines), textlines); + if (newline) + line_len = (int)(newline-textlines); + else + line_len = strlen(textlines); + if (textlines[0]=='\n') { + // avoid trailing spaces + } else if (textlines[0]=='#') { + // don't indent preprocessor statments starting with '#' + write_c("%.*s", (int)(newline-textlines), textlines); + } else { + // indent all other text lines + write_c("%s%.*s", indent(), (int)(newline-textlines), textlines); + } + if (newline) { + write_c("\n"); + } else { + if (inTrailwWith) + write_c("%c", inTrailwWith); + break; + } textlines = newline+1; } - if (*textlines) - write_c("%s%s", indent(), textlines); - indentation--; + indentation -= inIndent; } } |
