public void GetEncodingTest7(int codePage)
    {
        Encoding enc = TextEncodingConverter.GetEncoding(codePage);

        Assert.AreEqual(65001, enc.CodePage);
        Assert.IsNotInstanceOfType(enc.EncoderFallback, EncoderFallback.ExceptionFallback.GetType());
        Assert.IsNotInstanceOfType(enc.DecoderFallback.GetType(), DecoderFallback.ExceptionFallback.GetType());
    }
    public void GetEncodingTest5()
    {
        const int defaultCodePage = 1252;
        Encoding  enc             = TextEncodingConverter.GetEncoding(0);

        Assert.AreEqual(defaultCodePage, enc.CodePage);
        Assert.IsNotInstanceOfType(enc.EncoderFallback, EncoderFallback.ExceptionFallback.GetType());
        Assert.IsNotInstanceOfType(enc.DecoderFallback.GetType(), DecoderFallback.ExceptionFallback.GetType());
    }
示例#3
0
    /// <summary>
    /// Dekodiert Quoted-Printable kodierten Text, der sich in <see cref="Value"/> befindet, wenn
    /// <see cref="VCards.Models.PropertyParts.ParameterSection.Encoding"/>
    /// gleich <see cref="VCdEncoding.QuotedPrintable"/> ist.
    /// </summary>
    internal void DecodeQuotedPrintable()
    {
        if (this.Parameters.Encoding == VCdEncoding.QuotedPrintable && !_quotedPrintableDecoded)
        {
            this.Value = QuotedPrintableConverter.Decode(this.Value,                                                  // null-Prüfung nicht erforderlich
                                                         TextEncodingConverter.GetEncoding(this.Parameters.Charset)); // null-Prüfung nicht erforderlich

            _quotedPrintableDecoded = true;                                                                           // Encoding nicht 2x durchführen
        }
    }
示例#4
0
    /// <summary>
    /// Gibt den im <see cref="DataUrl"/> eingebetteten Text zurück oder <c>null</c>,
    /// wenn der <see cref="DataUrl"/> eingebettete binäre Daten enthält.
    /// </summary>
    /// <returns>Der eingebettete Text oder <c>null</c>.</returns>
    public string?GetEmbeddedText()
    {
        if (!ContainsText)
        {
            return(null);
        }

        if (Encoding == DataEncoding.Base64)
        {
            // als Base64 codierter Text:
            byte[] data;
            try
            {
                data = Base64Parser.ParseBase64(EncodedData);
            }
            catch
            {
                return(null);
            }

            string?charsetValue = MimeType.Parameters?.FirstOrDefault(x => x.Key == "charset").Value;

            int codePage = TextEncodingConverter.GetCodePage(data, out int bomLength);

            Encoding enc = bomLength != 0
                            ? TextEncodingConverter.GetEncoding(codePage)
                            : StringComparer.OrdinalIgnoreCase.Equals(charsetValue, "US-ASCII")
                                ? System.Text.Encoding.UTF8
                                : TextEncodingConverter.GetEncoding(charsetValue);

            try
            {
                return(enc.GetString(data, bomLength, data.Length - bomLength));
            }
            catch
            {
                return(null);
            }
        }
        else
        {
            // Url-Codierter UTF-8-String:
            return(Uri.UnescapeDataString(EncodedData ?? ""));
        }
    }
    public void ParseTest2()
    {
        Encoding enc = TextEncodingConverter.GetEncoding("ISO-8859-1");

        Assert.AreEqual(28591, enc.CodePage);
    }
    public void ParseTest1()
    {
        Encoding enc = TextEncodingConverter.GetEncoding("blödelidödel");

        Assert.AreEqual(UTF8, enc.CodePage);
    }