ADBaseLibrary.Subtitles.TTML.ProcessParagraph C# (CSharp) Method

ProcessParagraph() private method

private ProcessParagraph ( string>.Dictionary styles, string style, string p ) : List
styles string>.Dictionary
style string
p string
return List
        private List<string> ProcessParagraph(Dictionary<string,string> styles, string style, string p)
        {
            List<string> dta=new List<string>();
            if (string.IsNullOrEmpty(p))
                return dta;
            Match sp = SpanRegex.Match(p);
            if (sp.Success)
            {
                string span = sp.Groups["span"].Value;
                string data = sp.Groups["data"].Value;
                Match ss = StyleRegex.Match(span);
                if ((ss.Success) && (styles.ContainsKey(ss.Groups["style"].Value)))
                {
                    string nstyle = ss.Groups["style"].Value;
                    dta.AddRange(ProcessParagraph(styles, style, p.Substring(0,sp.Index)));
                    dta.Add("{\\r" + nstyle + "}");
                    dta.AddRange(ProcessParagraph(styles,nstyle,data));
                    dta.Add("{\\r" + style + "}");
                    dta.AddRange(ProcessParagraph(styles,style,p.Substring(sp.Index+sp.Length)));
                }
                else
                {
                    dta.AddRange(ProcessParagraph(styles, style, p.Substring(0, sp.Index)));
                    dta.AddRange(ProcessParagraph(styles, style, data));
                    dta.AddRange(ProcessParagraph(styles, style, p.Substring(sp.Index + sp.Length)));
                }
                return dta;
            }
            Match bld = (new Regex(string.Format(MatchRegex, "b"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (bld.Success)
            {
                string data = bld.Groups["data"].Value;
                dta.AddRange(ProcessParagraph(styles,style,p.Substring(0,bld.Index)));
                dta.Add("{\\b1}");
                dta.AddRange(ProcessParagraph(styles, style, data));
                dta.Add("{\\b0}");
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(bld.Index + bld.Length)));
                return dta;
            }
            bld = (new Regex(string.Format(MatchRegex, "i"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (bld.Success)
            {
                string data = bld.Groups["data"].Value;
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(0, bld.Index)));
                dta.Add("{\\i1}");
                dta.AddRange(ProcessParagraph(styles, style, data));
                dta.Add("{\\i0}");
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(bld.Index + bld.Length)));
                return dta;
            }
            bld = (new Regex(string.Format(MatchRegex, "u"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (bld.Success)
            {
                string data = bld.Groups["data"].Value;
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(0, bld.Index)));
                dta.Add("{\\u1}");
                dta.AddRange(ProcessParagraph(styles, style, data));
                dta.Add("{\\u0}");
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(bld.Index + bld.Length)));
                return dta;
            }
            bld = (new Regex(string.Format(MatchRegex, "del"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (!bld.Success)
                bld = (new Regex(string.Format(MatchRegex, "s"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (!bld.Success)
                bld = (new Regex(string.Format(MatchRegex, "strike"), RegexOptions.Singleline | RegexOptions.IgnoreCase)).Match(p);
            if (bld.Success)
            {
                string data = bld.Groups["data"].Value;
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(0, bld.Index)));
                dta.Add("{\\s1}");
                dta.AddRange(ProcessParagraph(styles, style, data));
                dta.Add("{\\s0}");
                dta.AddRange(ProcessParagraph(styles, style, p.Substring(sp.Index + sp.Length)));
                return dta;
            }
            p = p.Replace("\r", " ").Replace("\n", " ").Replace("\t"," ");
            p = p.Replace("  ", " ");
            p = p.Replace("  ", " ");
            p = BrRegex.Replace(p, "\\N");
            p = p.Replace("\\N ", "\\N");
            p = p.Replace(" \\N", "\\N");
            p = RemoveTags.Replace(p, string.Empty);
            p = WebUtility.HtmlDecode(p);
            p = p.Replace("{", string.Empty).Replace("}", string.Empty);
            dta.Add(p);
            return dta;
        }