当前位置: 首页>>代码示例>>C#>>正文


C# StringBuilder.AppendTail方法代码示例

本文整理汇总了C#中StringBuilder.AppendTail方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendTail方法的具体用法?C# StringBuilder.AppendTail怎么用?C# StringBuilder.AppendTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringBuilder的用法示例。


在下文中一共展示了StringBuilder.AppendTail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShortenRgbColors

        private string ShortenRgbColors(string css)
        {
            StringBuilder stringBuilder = new StringBuilder();
            Regex pattern = new Regex("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
            Match match = pattern.Match(css);

            int index = 0;
            while (match.Success)
            {
                int value;
                string[] colors = match.Groups[1].Value.Split(',');
                StringBuilder hexcolor = new StringBuilder("#");

                foreach (string color in colors)
                {
                    if (!Int32.TryParse(color,
                        out value))
                    {
                        value = 0;
                    }

                    if (value < 16)
                    {
                        hexcolor.Append("0");
                    }

                    hexcolor.Append(value.ToHexString());
                }

                index = match.AppendReplacement(stringBuilder,
                    css,
                    hexcolor.ToString(),
                    index);
                match = match.NextMatch();
            }

            stringBuilder.AppendTail(css, index);

            return stringBuilder.ToString();
        }
开发者ID:cairey,项目名称:Commmand-Line-Compressor,代码行数:40,代码来源:StylesheetMinifier.cs

示例2: ShortenHexColors

        private string ShortenHexColors(string css)
        {
            StringBuilder stringBuilder = new StringBuilder();
            Regex pattern = new Regex("([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
            Match match = pattern.Match(css);

            int index = 0;
            while (match.Success)
            {
                if (match.Groups[3].Value.EqualsIgnoreCase(match.Groups[4].Value) &&
                    match.Groups[5].Value.EqualsIgnoreCase(match.Groups[6].Value) &&
                    match.Groups[7].Value.EqualsIgnoreCase(match.Groups[8].Value))
                {
                    var replacement = String.Concat(match.Groups[1].Value,
                        match.Groups[2].Value,
                        "#", match.Groups[3].Value,
                        match.Groups[5].Value,
                        match.Groups[7].Value);
                    index = match.AppendReplacement(stringBuilder,
                        css,
                        replacement,
                        index);
                }
                else
                {
                    index = match.AppendReplacement(stringBuilder,
                        css,
                        match.Value,
                        index);
                }

                match = match.NextMatch();
            }

            stringBuilder.AppendTail(css,
                index);

            return stringBuilder.ToString();
        }
开发者ID:cairey,项目名称:Commmand-Line-Compressor,代码行数:39,代码来源:StylesheetMinifier.cs

示例3: Compress

        public static string Compress(string css, int columnWidth, bool removeComments)
        {
            if (string.IsNullOrEmpty(css))
            {
                throw new ArgumentNullException("css");
            }

            int totalLen = css.Length;
            int startIndex = 0;
            var comments = new ArrayList();
            var preservedTokens = new ArrayList();
            int max;


            if (removeComments)
            {
                while ((startIndex = css.IndexOf(@"/*", startIndex, StringComparison.OrdinalIgnoreCase)) >= 0)
                {
                    int endIndex = css.IndexOf(@"*/", startIndex + 2, StringComparison.OrdinalIgnoreCase);
                    if (endIndex < 0)
                    {
                        endIndex = totalLen;
                    }

                    // Note: java substring-length param = end index - 2 (which is end index - (startindex + 2))
                    string token = css.Substring(startIndex + 2, endIndex - (startIndex + 2));

                    comments.Add(token);

                    string newResult = css.Replace(startIndex + 2, endIndex,
                                                   "___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + (comments.Count - 1) +
                                                   "___");

                    //var newResult = css.Substring(startIndex + 2, endIndex - (startIndex + 2)) + "___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" +
                    //                (comments.Count - 1) + "___" + css.Substring(endIndex + 1);

                    startIndex += 2;
                    css = newResult;
                }
            }

            // Preserve strings so their content doesn't get accidently minified
            var stringBuilder = new StringBuilder();
            var pattern = new Regex("(\"([^\\\\\"]|\\\\.|\\\\)*\")|(\'([^\\\\\']|\\\\.|\\\\)*\')");
            Match match = pattern.Match(css);
            int index = 0;
            while (match.Success)
            {
                string text = match.Groups[0].Value;
                if (!string.IsNullOrEmpty(text))
                {
                    string token = match.Value;
                    char quote = token[0];

                    // Java code: token.substring(1, token.length() -1) .. but that's ...
                    //            token.substring(start index, end index) .. while .NET it's length for the 2nd arg.
                    token = token.Substring(1, token.Length - 2);

                    // Maybe the string contains a comment-like substring?
                    // one, maybe more? put'em back then.
                    if (token.IndexOf("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_") >= 0)
                    {
                        max = comments.Count;
                        for (int i = 0; i < max; i += 1)
                        {
                            token = token.Replace("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___",
                                                  comments[i].ToString());
                        }
                    }

                    // Minify alpha opacity in filter strings.
                    token = token.RegexReplace("(?i)progid:DXImageTransform.Microsoft.Alpha\\(Opacity=",
                                               "alpha(opacity=");

                    preservedTokens.Add(token);
                    string preserver = quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.Count - 1) + "___" +
                                       quote;

                    index = match.AppendReplacement(stringBuilder, css, preserver, index);
                    match = match.NextMatch();
                }
            }
            stringBuilder.AppendTail(css, index);
            css = stringBuilder.ToString();

            // Strings are safe, now wrestle the comments.
            max = comments.Count;
            for (int i = 0; i < max; i += 1)
            {
                string token = comments[i].ToString();
                string placeholder = "___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___";

                // ! in the first position of the comment means preserve
                // so push to the preserved tokens while stripping the !
                if (token.StartsWith("!"))
                {
                    preservedTokens.Add(token);
                    css = css.Replace(placeholder, "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.Count - 1) + "___");
                    continue;
                }
//.........这里部分代码省略.........
开发者ID:benbon,项目名称:SharpKit,代码行数:101,代码来源:CssCompressor.cs

示例4: RemovePrecedingSpaces

        private string RemovePrecedingSpaces(string css)
        {
            StringBuilder stringBuilder = new StringBuilder();
            Regex pattern = new Regex("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
            Match match = pattern.Match(css);

            int index = 0;
            while (match.Success)
            {
                string s = match.Value;
                s = s.RegexReplace(":", "___PSEUDOCLASSCOLON___");

                index = match.AppendReplacement(stringBuilder,
                    css,
                    s,
                    index);
                match = match.NextMatch();
            }
            stringBuilder.AppendTail(css,
                index);

            string result = stringBuilder.ToString();
            result = result.RegexReplace("\\s+([!{};:>+\\(\\)\\],])", "$1");
            result = result.RegexReplace("___PSEUDOCLASSCOLON___", ":");

            return result;
        }
开发者ID:cairey,项目名称:Commmand-Line-Compressor,代码行数:27,代码来源:StylesheetMinifier.cs

示例5: RemovePrecedingSpaces

        private static string RemovePrecedingSpaces(this string css)
        {
            StringBuilder stringBuilder = new StringBuilder();
            Regex pattern = new Regex("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
            Match match = pattern.Match(css);

            int index = 0;
            while (match.Success)
            {
                string s = match.Value;
                s = s.RegexReplace(":", "___PSEUDOCLASSCOLON___");

                index = match.AppendReplacement(stringBuilder,
                    css,
                    s,
                    index);
                match = match.NextMatch();
            }
            stringBuilder.AppendTail(css,
                index);

            string result = stringBuilder.ToString();
            result = result.RegexReplace("\\s+([!{};:>+\\(\\)\\],])", "$1");
            // Put the space back in some cases, to support stuff like
            // @media screen and (-webkit-min-device-pixel-ratio:0){
            // https://github.com/isaacs/yuicompressor/commit/0e290b8e05392f19bccc2f7d524725a87739e6d6
            result = result.RegexReplace("(@media[^{]*[^\\s])\\(", "$1 (");
            result = result.RegexReplace("___PSEUDOCLASSCOLON___", ":");

            return result;
        }
开发者ID:robrich,项目名称:NAntTasks,代码行数:31,代码来源:YUICompressor.cs


注:本文中的StringBuilder.AppendTail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。