~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/encodings.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *      along with this program; if not, write to the Free Software
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 *  $Id: encodings.c 4630 2010-01-31 21:54:47Z eht16 $
 
21
 *  $Id: encodings.c 4862 2010-04-25 17:43:39Z eht16 $
22
22
 */
23
23
 
24
24
/*
232
232
        return enc->charset;
233
233
}
234
234
 
 
235
 
235
236
static GtkWidget *radio_items[GEANY_ENCODINGS_MAX];
236
237
 
237
238
 
522
523
{
523
524
        gchar *locale_charset = NULL;
524
525
        gchar *regex_charset = NULL;
525
 
        gchar *charset;
 
526
        const gchar *charset;
526
527
        gchar *utf8_content;
527
528
        gboolean check_regex = FALSE;
528
529
        gboolean check_locale = FALSE;
529
 
        gint i, len;
 
530
        gint i, len, preferred_charset;
530
531
 
531
532
        if ((gint)size == -1)
532
533
        {
546
547
        /* current locale is not UTF-8, we have to check this charset */
547
548
        check_locale = ! g_get_charset((const gchar**) &charset);
548
549
 
549
 
        for (i = 0; i < GEANY_ENCODINGS_MAX; i++)
550
 
        {
551
 
                if (G_UNLIKELY(i == encodings[GEANY_ENCODING_NONE].idx) || G_UNLIKELY(i == -1))
 
550
        /* First check for preferred charset, if specified */
 
551
        preferred_charset = file_prefs.default_open_encoding;
 
552
 
 
553
        if (preferred_charset == encodings[GEANY_ENCODING_NONE].idx ||
 
554
                preferred_charset < 0 ||
 
555
                preferred_charset >= GEANY_ENCODINGS_MAX)
 
556
        {
 
557
                preferred_charset = -1;
 
558
        }
 
559
 
 
560
        /* -1 means "Preferred charset" */
 
561
        for (i = -1; i < GEANY_ENCODINGS_MAX; i++)
 
562
        {
 
563
                if (G_UNLIKELY(i == encodings[GEANY_ENCODING_NONE].idx))
552
564
                        continue;
553
565
 
554
 
                if (check_regex)
 
566
                if (i == -1)
 
567
                {
 
568
                        if (preferred_charset != -1)
 
569
                        {
 
570
                                charset = encodings[preferred_charset].charset;
 
571
                                geany_debug("Preferred charset: %s", charset);
 
572
                        }
 
573
                        else
 
574
                                continue;
 
575
                }
 
576
                else if (check_regex)
555
577
                {
556
578
                        check_regex = FALSE;
557
579
                        charset = regex_charset;
558
 
                        i = -1;
559
580
                }
560
581
                else if (check_locale)
561
582
                {
562
583
                        check_locale = FALSE;
563
584
                        charset = locale_charset;
564
 
                        i = -1;
565
585
                }
566
586
                else
567
587
                        charset = encodings[i].charset;
636
656
                if (bom_len)
637
657
                        *bom_len = 2;
638
658
 
639
 
                if ((guchar)string[0]==0xfe && (guchar)string[1] == 0xff)
 
659
                if ((guchar)string[0] == 0xfe && (guchar)string[1] == 0xff)
640
660
                {
641
661
                        return GEANY_ENCODING_UTF_16BE; /* Big endian */
642
662
                }