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


C# StringReader.ReadToBeforeChar方法代码示例

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


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

示例1: ParseStyle

        private static void ParseStyle(string styleContent, Dictionary<string, Dictionary<string, string>> styles)
        {
            StringReader reader = new StringReader(styleContent);
            while (reader.Peek() != -1)
            {
                string names = reader.ReadToBeforeChar(CurlyBraceOpen).Trim();
                // Consume {
                reader.Read();

                string block = reader.ReadToBeforeChar(CurlyBraceClose);
                Dictionary<string, string> styleValues = new Dictionary<string, string>(strComp);
                foreach (var keyValue in block.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var idxColumn = keyValue.IndexOf(':');
                    if (idxColumn == -1)
                        continue;

                    var name = keyValue.Substring(0, idxColumn).Trim();
                    var value = idxColumn + 1 < keyValue.Length ? keyValue.Substring(idxColumn + 1).Trim() : string.Empty;
                    styleValues[name] = value;
                }
                // Consume }
                reader.Read();

                foreach (var n in names.Split(','))
                {
                    var name = n.Trim();
                    Dictionary<string, string> currentValues;
                    if (styles.TryGetValue(n, out currentValues))
                    {
                        foreach (var item in styleValues)
                        {
                            currentValues[item.Key] = item.Value;
                        }
                    }
                    else
                    {
                        styles[n] = styleValues;
                    }
                }
            }
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:42,代码来源:SmiParser.cs

示例2: ReadMarkup

        public static MarkupType ReadMarkup(this StringReader reader, out MarkupContent content, StringComparer comparer)
        {
            content = null;

            if (!reader.PeekIsMarkup())
            {
                if (content != null)
                    content.Type = MarkupType.Raw;
                return MarkupType.Raw;
            }

            //Skip Markup
            reader.Read();
            int intChar = reader.Peek();
            if (intChar == -1)
            {
                if (content != null)
                    content.Type = MarkupType.Raw;
                return MarkupType.Raw;
            }

            var isClosingMarkup = intChar == slash;
            if (isClosingMarkup)
            {
                // Consume /
                reader.Read();

                var name = reader.ReadToBeforeChar(gt);
                content = new MarkupContent { Name = name };
                // Consume >
                reader.Read();
                content.Type = MarkupType.ClosingNode;
                return content.Type;
            }
            else
            {
                bool isComment = false;

                StringBuilder data = new StringBuilder();
                data.Append(reader.ReadToBeforeChar(gt));
                if (data.Length > 3 && data.ToString(0, 3) == "!--")
                {
                    isComment = true;

                    while (data.ToString(data.Length - 2, 2) != "--")
                    {
                        char[] cBuffer = new char[1];
                        if (reader.Read(cBuffer, 0, 1) == 0)
                            break;

                        data.Append(cBuffer[0]);
                        if (reader.Peek() != -1)
                            data.Append(reader.ReadToBeforeChar(gt));
                    }
                }
                // Consume >
                reader.Read();
                if (isComment)
                {
                    content = new MarkupContent { Content = data.ToString(3, data.Length - 5).Trim(), Name = "!--" };
                    content.Type = MarkupType.Comment;
                    return content.Type;
                }
                else
                {
                    bool isClosed = false;
                    if(data[data.Length - 1] == slash)
                    {
                        data.Remove(data.Length - 1, 1);
                        isClosed = true;
                    }

                    content = new MarkupContent { Content = data.ToString() };
                    StringReader elementReader = new StringReader(content.Content);
                    string elementName = elementReader.ReadToBeforeChar(space);
                    content.Name = elementName;

                    content.Parameters = attributesRegex.Matches(elementReader.ReadToEnd()).OfType<Match>().ToDictionary(
                        (e) => e.Groups["key"].Value,
                        (e) => e.Groups["value"].Value,
                        comparer);
                    content.Type = isClosed ? MarkupType.Node : MarkupType.StartNode;
                    return content.Type;
                }
            }
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:86,代码来源:StringReaderExtensions.cs


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