From fb80ada21f01c24f2d9d1ea8891e4dc81282d4dc Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 16 Aug 2010 11:47:50 +0000 Subject: [PATCH] r5163 | eht16 | 2010-08-15 14:33:32 +0100 (Sun, 15 Aug 2010) | 1 line Rewrite the logic to auto detect encodings a bit to make it more readable and fix a slightly wrong detection on Windows (closes #3019573). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/Geany-0_19_1@5166 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ NEWS | 1 + src/encodings.c | 32 ++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 185bcdd3a..d81b0682b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * wscript: Check for libsocket on OpenSolaris to fix build. + * src/encodings.c: + Rewrite the logic to auto detect encodings a bit to make it more + readable and fix a slightly wrong detection on Windows + (closes #3019573). 2010-08-13 Nick Treleaven diff --git a/NEWS b/NEWS index 99736198e..7abbf2ccd 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ Geany 0.19.1 (TBA) and switching document tabs). * Fix using filetype extension patterns with upper case letters on Windows (#3028856). + * Fix a slightly wrong encoding detection on Windows (#3019573). * Re-enable comment folding. * Fix not loading plugins built against a newer API when Geany doesn't provide the required version given in PLUGIN_VERSION_CHECK(). diff --git a/src/encodings.c b/src/encodings.c index 70c5d6cfd..29e800dd3 100644 --- a/src/encodings.c +++ b/src/encodings.c @@ -563,34 +563,38 @@ gchar *encodings_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_e if (G_UNLIKELY(i == encodings[GEANY_ENCODING_NONE].idx)) continue; - if (i == -1) - { - if (preferred_charset != -1) - { - charset = encodings[preferred_charset].charset; - geany_debug("Using preferred charset: %s", charset); - } - else - continue; - } - else if (check_regex) + if (check_regex) { check_regex = FALSE; charset = regex_charset; + i = -2; /* keep i below the start value to have it again at -1 on the next loop run */ } else if (check_locale) { check_locale = FALSE; charset = locale_charset; + i = -2; /* keep i below the start value to have it again at -1 on the next loop run */ } - else + else if (i == -1) + { + if (preferred_charset >= 0) + { + charset = encodings[preferred_charset].charset; + geany_debug("Using preferred charset: %s", charset); + } + else + continue; + } + else if (i >= 0) charset = encodings[i].charset; - + else /* in this case we have i == -2, continue to increase i and go ahead */ + continue; if (G_UNLIKELY(charset == NULL)) continue; - geany_debug("Trying to convert %" G_GSIZE_FORMAT " bytes of data from %s into UTF-8.", size, charset); + geany_debug("Trying to convert %" G_GSIZE_FORMAT " bytes of data from %s into UTF-8.", + size, charset); utf8_content = encodings_convert_to_utf8_from_charset(buffer, size, charset, FALSE); if (G_LIKELY(utf8_content != NULL)) -- 2.11.4.GIT