From f3c199807d178c696b05b54e52363061a80fcbb2 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 9 Nov 2010 18:14:33 +0000 Subject: [PATCH] Convert line endings for file templates. Fix line endings when using file header template in a file template (oops). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5388 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ src/templates.c | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 743dc3c2..12c001be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ Save build commands for filetype None (patch by Lex, thanks). Make filetypes_get_conf_extension() return "common" for filetype None. + * src/templates.c: + Convert line endings for file templates. + Fix line endings when using file header template in a file template + (oops). 2010-11-08 Nick Treleaven diff --git a/src/templates.c b/src/templates.c index ab2a3595..e631cf2d 100644 --- a/src/templates.c +++ b/src/templates.c @@ -84,16 +84,12 @@ static void read_template(const gchar *name, gint id) TEMPLATES_READ_FILE(fname, &templates[id]); - /* FIXME: we should replace the line ends on insertion with doc pref, not on loading */ { GString *tmp = g_string_new(templates[id]); - const gchar *eol_str = (file_prefs.default_eol_character == SC_EOL_CR) ? "\r" : "\r\n"; - /* first convert data to LF only */ - utils_string_replace_all(tmp, "\r\n", "\n"); - utils_string_replace_all(tmp, "\r", "\n"); - /* now convert to desired line endings */ - utils_string_replace_all(tmp, "\n", eol_str); + /* Convert to default line endings e.g. for file header use in a file template. + * When inserting separately we replace line endings with the document setting. */ + utils_ensure_same_eol_characters(tmp, file_prefs.default_eol_character); setptr(templates[id], tmp->str); g_string_free(tmp, FALSE); } @@ -264,6 +260,7 @@ static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc gchar *file_header; template = g_string_new(content); + utils_ensure_same_eol_characters(template, file_prefs.default_eol_character); file_header = get_template_fileheader(ft); templates_replace_valist(template,