SF.net SVN: geany:[5163] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Aug 15 13:33:32 UTC 2010


Revision: 5163
          http://geany.svn.sourceforge.net/geany/?rev=5163&view=rev
Author:   eht16
Date:     2010-08-15 13:33:32 +0000 (Sun, 15 Aug 2010)

Log Message:
-----------
Rewrite the logic to auto detect encodings a bit to make it more readable and fix a slightly wrong detection on Windows (closes #3019573).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/encodings.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-08-15 12:53:09 UTC (rev 5162)
+++ trunk/ChangeLog	2010-08-15 13:33:32 UTC (rev 5163)
@@ -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  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/encodings.c
===================================================================
--- trunk/src/encodings.c	2010-08-15 12:53:09 UTC (rev 5162)
+++ trunk/src/encodings.c	2010-08-15 13:33:32 UTC (rev 5163)
@@ -563,34 +563,38 @@
 		if (G_UNLIKELY(i == encodings[GEANY_ENCODING_NONE].idx))
 			continue;
 
-		if (i == -1)
+		if (check_regex)
 		{
-			if (preferred_charset != -1)
-			{
-				charset = encodings[preferred_charset].charset;
-				geany_debug("Using preferred charset: %s", charset);
-			}
-			else
-				continue;
-		}
-		else 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))


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list