Changeset 36c665a68f197cfe5edceffa0807e2b4e5275845


Ignore:
Timestamp:
03/07/10 20:46:35 (3 years ago)
Author:
Matias De la Puente <mfpuente.ar@…>
Children:
52f513bb146e410efbdc3bc58f0ab3001d9ba77f
Parents:
4beb0f8a3d942274015a4c700d470cf64bdc0c98
git-committer:
Matias De la Puente <mfpuente.ar@…> (03/07/10 20:46:35)
Message:

Documents: Add basic support for encodings

Fixes Ticket #1

Location:
libi4uc
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • libi4uc/Makefile.am

    r4beb0f8 r36c665a  
    4242        i4ucdocumentsview.vala \ 
    4343        i4ucdocumentsviewiface.vala \ 
     44        i4ucencodings.vala \ 
    4445        i4ucfileslist.vala \ 
    4546        i4ucitemscombo.vala \ 
  • libi4uc/i4ucdocument.vala

    rc94fa49 r36c665a  
    7070        } 
    7171         
     72        public string encoding { set; get; default = "UTF-8"; } 
     73         
    7274        public string load_contents (string uri) throws GLib.Error 
    7375        { 
     
    7981                        _file = file; 
    8082                this.etag = new_etag; 
    81                 return contents; 
     83                string utf8_contents; 
     84                to_utf8 (contents, out utf8_contents); 
     85                return utf8_contents; 
    8286        } 
    8387         
     
    8993                else 
    9094                        file = _file; 
    91                 var buffer = contents + "\n"; 
     95                var buffer = from_utf8 (contents + "\n"); 
    9296                string new_etag; 
    9397                string? etag = force_save ? null: _etag; 
     
    97101                this.etag = new_etag; 
    98102        } 
     103         
     104        private void to_utf8 (string encoded_string, out string utf8_string) throws GLib.ConvertError 
     105        { 
     106                foreach (var charset in Encodings.CHARSETS) 
     107                { 
     108                        try 
     109                        { 
     110                                utf8_string = convert (encoded_string, (ssize_t)encoded_string.size (), "UTF-8", charset); 
     111                                this.encoding = charset; 
     112                                return; 
     113                        } 
     114                        catch (ConvertError e) 
     115                        { 
     116                                continue; 
     117                        } 
     118                } 
     119                throw new GLib.ConvertError.FAILED (_("Error trying to convert the document to UTF-8")); 
     120        } 
     121         
     122        private string from_utf8 (string utf8_string) throws GLib.ConvertError 
     123        { 
     124                return convert (utf8_string, (ssize_t)utf8_string.size (), _encoding, "UTF-8"); 
     125        } 
    99126} 
Note: See TracChangeset for help on using the changeset viewer.