using System;
using System.Collections;
using System.Text;
using System.Text.RegularExpressions;
namespace HtmlHelp.ChmDecoding
{
///
/// The class HHCParser implements a parser for HHC contents files.
///
// internal sealed class HHCParser : IHHCParser
public class HHCParser2
{
static private string m_text1="";
static private string m_text2="";
static private int m_CurrentPos=0;
///
/// Parses a HHC file and returns an ArrayList with the table of contents (TOC) tree
///
/// string content of the hhc file
/// CHMFile instance
/// Returns an ArrayList with the table of contents (TOC) tree
public static ArrayList ParseHHC(string hhcFile, CHMFile chmFile)
{
DateTime StartTime=DateTime.Now;
ArrayList tocList = new ArrayList();
m_text2=hhcFile;
m_text1=hhcFile.ToLower();
int idx=m_text1.IndexOf("
");
if (idx==-1)
return null;
m_CurrentPos=idx+4;
ParamRE = new Regex(RE_ParamBoundaries, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
AttributesRE = new Regex(RE_QuoteAttributes, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
ParseTree(tocList,chmFile);
DateTime EndTime=DateTime.Now;
TimeSpan Diff=EndTime-StartTime;
string x=Diff.ToString();
return tocList;
}
///
/// Recursively parses a sitemap tree
///
/// content text
/// arraylist which receives the extracted nodes
/// CHMFile instance
static private void ParseTree( ArrayList arrNodes, CHMFile chmFile )
{
bool bProcessing=true;
do
{
bProcessing=false;
// Indent
int idxa=m_text1.IndexOf("
",m_CurrentPos);
int idxb=m_text1.IndexOf("
",m_CurrentPos);
int idxc=m_text1.IndexOf("
",m_CurrentPos);
if ((idxa-1))
{
bProcessing=true;
m_CurrentPos=idxa+4;
if (arrNodes.Count<1)
{
ParseTree(arrNodes,chmFile);
}
else
{
ParseTree(((TOCItem)(arrNodes[arrNodes.Count-1])).Children,chmFile);
}
continue;
}
// new item
if ((idxb-1))
{
bProcessing=true;
m_CurrentPos=idxb+4;
int idx2=m_text1.IndexOf("