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


C# StringReader.ReadToMarkup方法代码示例

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


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

示例1: ParseSmiFile

        public static IDictionary<string, SmiMarker[]> ParseSmiFile(string content)
        {
            content = Regex.Replace(content, @"[\s\r\n]{2,}", " ", RegexOptions.Multiline);
            Dictionary<string, SmiMarker[]> smiContent = new Dictionary<string, SmiMarker[]>(strComp);
            StringReader reader = new StringReader(content);
            reader.ReadToMarkup();

            if (!reader.PeekIsMarkup())
                return smiContent;

            if (strComp.Compare(reader.ReadMarkup(), SamiMarkup) != 0)
                return smiContent;

            Dictionary<string, Dictionary<string, string>> styles = new Dictionary<string, Dictionary<string, string>>(strComp);
            ReadHead(reader, styles);

            return ReadBody(reader, styles);
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:18,代码来源:SmiParser.cs

示例2: ReadBody

        internal static Dictionary<string, SmiMarker[]> ReadBody(StringReader reader, Dictionary<string, Dictionary<string, string>> styles)
        {
            // Be sure to be at the start of a markup tag
            string data = reader.ReadToMarkup();
            if (reader.Peek() == -1
                || !reader.PeekIsMarkup())
                return null;

            // Check if the next tag is Head
            MarkupContent markupContent = null;
            var markupType = reader.ReadMarkup(out markupContent, strComp);
            if (!(markupType == MarkupType.StartNode && strComp.Compare(markupContent.Name, BodyMarkup) == 0))
                return null;

            Dictionary<string, List<SmiMarker>> markersByLanguage = new Dictionary<string, List<SmiMarker>>(strComp);

            while (reader.Peek() != -1)
            {
                if (!reader.PeekIsMarkup())
                    reader.ReadToMarkup();

                if (!reader.PeekIsMarkup())
                    break;

                markupType = reader.ReadMarkup(out markupContent, strComp);
                MarkupContent invalidSamiNextMarkupContent = null;
                do
                {
                    if (invalidSamiNextMarkupContent != null)
                    {
                        markupType = invalidSamiNextMarkupContent.Type;
                        markupContent = invalidSamiNextMarkupContent;
                    }

                    if (markupType == MarkupType.ClosingNode && strComp.Compare(markupContent.Name, BodyMarkup) == 0)
                        break;

                    if (markupType == MarkupType.StartNode
                        && strComp.Compare(markupContent.Name, SyncMarkup) == 0)
                    {
                        invalidSamiNextMarkupContent = readSyncNode(reader, markupContent, styles, markersByLanguage);
                    }
                } while (invalidSamiNextMarkupContent != null);
            }

            var result = new Dictionary<string, SmiMarker[]>(strComp);
            foreach (var item in markersByLanguage)
            {
                var markers = item.Value.OrderBy(m => m.Position).ToList();
                for (int i = markers.Count - 1; i >= 0; i--)
                {
                    SmiMarker mrk = markers[i];
                    if (mrk.Content == null)
                    {
                        markers.RemoveAt(i);
                        if (i > 0)
                        {
                            SmiMarker prevMarker = markers[i - 1];
                            prevMarker.Duration = mrk.Position - prevMarker.Position;
                        }
                    }
                }
                result[item.Key] = markers.ToArray();
            }

            return result;
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:67,代码来源:SmiParser.cs

示例3: readSyncNode

        private static MarkupContent readSyncNode(StringReader reader, MarkupContent markupContent, Dictionary<string, Dictionary<string, string>> styles, Dictionary<string, List<SmiMarker>> markersByLanguage)
        {
            MarkupType markupType;

            TimeSpan position = TimeSpan.Zero;
            var start = markupContent.Parameters.TryGetValue("start");
            var startInt = 0;
            if (!int.TryParse(start, out startInt))
                return null;

            position = TimeSpan.FromMilliseconds(startInt);

            while (reader.Peek() != -1)
            {
                reader.ReadToMarkup();
                if (!reader.PeekIsMarkup())
                    return null;

                markupType = reader.ReadMarkup(out markupContent, strComp);

                if (markupType == MarkupType.ClosingNode
                    && strComp.Compare(markupContent.Name, SyncMarkup) == 0)
                    break;

                if (markupType == MarkupType.StartNode
                    && strComp.Compare(markupContent.Name, PMarkup) == 0)
                {
                    var invalidSamiNextMarkupContent = ReadSyncPNode(reader, styles,
                                                markupContent,
                                                position, markersByLanguage);
                    if (invalidSamiNextMarkupContent != null)
                    {
                        // malformed sami
                        return invalidSamiNextMarkupContent;
                    }
                }
            }

            return null;
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:40,代码来源:SmiParser.cs

示例4: ReadSyncPNode

        private static MarkupContent ReadSyncPNode(StringReader reader, Dictionary<string, Dictionary<string, string>> styles,
            MarkupContent markupContent,
            TimeSpan position, Dictionary<string, List<SmiMarker>> markersByLanguage)
        {
            MarkupContent malformedContent = null;
            MarkupType markupType;
            var cssList = new List<string>();
            cssList.Add("p");
            var cssClass = markupContent.Parameters.TryGetValue("class");
            if (!string.IsNullOrEmpty(cssClass))
            {
                cssList.AddRange(from css in cssClass.Split(' ')
                                 select String.Concat("." + css));
            }
            SmiMarker marker = new SmiMarker();
            marker.Position = position;
            StringBuilder markerContent = new StringBuilder();

            foreach (var styleRules in cssList)
            {
                AssignPropertiesFromStyle(marker, styles.TryGetValue(styleRules));
            }

            GetMarkerList(markersByLanguage, marker.Language ?? string.Empty).Add(marker);

            while (reader.Peek() != -1)
            {
                var newContent = reader.ReadToMarkup().Trim();
                if (!string.IsNullOrEmpty(newContent))
                {
                    if (markerContent.Length > 0
                        && markerContent[markerContent.Length - 1] != '\n')
                    {
                        markerContent.Append(' ');
                    }

                    markerContent.Append(newContent);
                }

                if (reader.PeekIsMarkup())
                {
                    markupType = reader.ReadMarkup(out markupContent, strComp);
                    if ((markupType == MarkupType.Node || markupType == MarkupType.StartNode)
                        && strComp.Compare(markupContent.Name, "br") == 0)
                    {
                        markerContent.Append('\n');
                    }

                    if ((markupType == MarkupType.ClosingNode
                            && strComp.Compare(markupContent.Name, PMarkup) == 0))
                    {
                        break;
                    }

                    if((markupType == MarkupType.StartNode
                            && strComp.Compare(markupContent.Name, SyncMarkup) == 0))
                    {
                        // Malformed Sami file.
                        malformedContent = markupContent;
                        break;
                    }
                }
            }

            if (markerContent.ToString() != "&nbsp;")
                marker.Content = HttpUtility.HtmlDecode(markerContent.ToString()).Trim();
            else
            {
                marker.Content = null;
            }

            return malformedContent;
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:73,代码来源:SmiParser.cs

示例5: ReadHead

        internal static void ReadHead(StringReader reader,
            Dictionary<string, Dictionary<string, string>> styles)
        {
            // Be sure to be at the start of a markup tag
            string data = reader.ReadToMarkup();
            if (reader.Peek() == -1
                || !reader.PeekIsMarkup())
                return;

            // Check if the next tag is Head
            MarkupContent markupContent;
            var markupType = reader.ReadMarkup(out markupContent, strComp);
            if (!(markupType == MarkupType.StartNode && strComp.Compare(markupContent.Name, HeadMarkup) == 0))
                return;

            while (reader.Peek() != -1)
            {
                if (!reader.PeekIsMarkup())
                    reader.ReadToMarkup();

                if (!reader.PeekIsMarkup())
                    return;

                markupType = reader.ReadMarkup(out markupContent, strComp);
                if (markupType == MarkupType.ClosingNode && strComp.Compare(markupContent.Name, HeadMarkup) == 0)
                    return;

                if (markupType == MarkupType.StartNode
                    && strComp.Compare(markupContent.Name, StyleMarkup) == 0)
                {
                    var styleContent = reader.ReadToMarkup() ?? string.Empty;
                    if (!reader.PeekIsMarkup())
                        return;

                    while (reader.Peek() != -1)
                    {
                        markupType = reader.ReadMarkup(out markupContent, strComp);
                        if (markupType == MarkupType.Comment)
                            styleContent += markupContent.Content;
                        else if (markupType == MarkupType.ClosingNode)
                            break;

                        reader.ReadToMarkup();
                        //if(!isClosingMarkup && strComp.Compare(markup, StyleMarkup))
                        //    sty
                    }

                    ParseStyle(styleContent, styles);
                }
                //if (reader.PeekIsMarkup())
                //{

                //    if ((isClosingMarkup && strComp.Compare(markup, HeadMarkup) == 0)
                //        || )
                //        return;
                //}
            }
        }
开发者ID:Titaye,项目名称:SLExtensions,代码行数:58,代码来源:SmiParser.cs


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