~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Sharpen/Sharpen/CharsetDecoder.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace Sharpen
 
2
{
 
3
        using System;
 
4
        using System.Text;
 
5
 
 
6
        internal class CharsetDecoder
 
7
        {
 
8
                private Encoding enc;
 
9
                Decoder decoder;
 
10
 
 
11
                public CharsetDecoder (Encoding enc)
 
12
                {
 
13
                        this.enc = enc;
 
14
                        this.decoder = enc.GetDecoder ();
 
15
                }
 
16
 
 
17
                public string Decode (ByteBuffer b)
 
18
                {
 
19
                        string res = enc.Decode (b);
 
20
                        if (res.IndexOf ('\uFFFD') != -1 && decoder.Fallback == DecoderFallback.ExceptionFallback)
 
21
                                throw new CharacterCodingException ();
 
22
                        return res;
 
23
                }
 
24
 
 
25
                public void OnMalformedInput (CodingErrorAction action)
 
26
                {
 
27
                        if (action == CodingErrorAction.REPORT)
 
28
                                decoder.Fallback = DecoderFallback.ExceptionFallback;
 
29
                        else
 
30
                                decoder.Fallback = DecoderFallback.ReplacementFallback;
 
31
                }
 
32
 
 
33
                public void OnUnmappableCharacter (CodingErrorAction action)
 
34
                {
 
35
                        if (action == CodingErrorAction.REPORT)
 
36
                                decoder.Fallback = DecoderFallback.ExceptionFallback;
 
37
                        else
 
38
                                decoder.Fallback = DecoderFallback.ReplacementFallback;
 
39
                }
 
40
        }
 
41
}