zoukankan      html  css  js  c++  java
  • [Mime] QuotedPrintableEncoding帮助类 (转载)

    点击下载 QuotedPrintableEncoding.rar

    这个类是关于QuotedPrintableEncoding的帮助类
    看下面代码吧

    /// <summary>
    /// 类说明:Assistant
    /// 编 码 人:苏飞
    /// 联系方式:361983679  
    /// 更新网站:[url=http://www.cckan.net/thread-655-1-1.html]http://www.cckan.net/thread-655-1-1.html[/url]
    /// </summary>
    using System;
    using System.IO;
    using System.Text.RegularExpressions;
     
    namespace DotNet.Utilities
    {
        /// <summary>
        /// This class is based on the QuotedPrintable class written by Bill Gearhart
        /// </summary>
        public static class QuotedPrintableEncoding
        {
            private const string Equal = "=";
     
            private const string HexPattern = "(\=([0-9A-F][0-9A-F]))";
     
            public static string Decode(string contents)
            {
                if (contents == null)
                {
                    throw new ArgumentNullException("contents");
                }
     
                using (StringWriter writer = new StringWriter())
                {
                    using (StringReader reader = new StringReader(contents))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            /*remove trailing line whitespace that may have
                             been added by a mail transfer agent per rule
                             #3 of the Quoted Printable section of RFC 1521.*/
                            line.TrimEnd();
     
                            if (line.EndsWith(Equal))
                            {
                                writer.Write(DecodeLine(line));
                            } //handle soft line breaks for lines that end with an "="
                            else
                            {
                                writer.WriteLine(DecodeLine(line));
                            }
                        }
                    }
                    writer.Flush();
     
                    return writer.ToString();
                }
            }
     
            private static string DecodeLine(string line)
            {
                if (line == null)
                {
                    throw new ArgumentNullException("line");
                }
     
                Regex hexRegex = new Regex(HexPattern, RegexOptions.IgnoreCase);
     
                return hexRegex.Replace(line, new MatchEvaluator(HexMatchEvaluator));
            }
     
            private static string HexMatchEvaluator(Match m)
            {
                int dec = Convert.ToInt32(m.Groups[2].Value, 16);
                char character = Convert.ToChar(dec);
                return character.ToString();
            }
        }
    }
  • 相关阅读:
    树的计数 + prufer序列与Cayley公式 学习笔记
    链表
    密码学摘要
    查找与排序
    匿名内部类 调用方法内局部变量
    <c:url>标签相关知识点
    Oracle 导入导出数据库
    oracle cursor
    Oracle 删除用户和表空间------创建表空间和用户
    iOS延迟执行方法
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3628720.html
Copyright © 2011-2022 走看看