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();
            }
        }
    }
  • 相关阅读:
    深度优先和广度优先
    水管工游戏(深度优先)
    炸弹人
    广度优先(迷宫找人)
    System.Data.Entity.Core.MetadataException: 无法加载指定的无数据资源
    Element Cascader 级联选择器 单选操作优化
    Windows服务 ProjectInstaller 获取 路径
    Quartz.NET ScheduledFireTimeUtc 当超过1分钟时出现的问题。
    记录:一个SQL SERVER奇怪的问题。
    log4.net 配置
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3628720.html
Copyright © 2011-2022 走看看