Ejemplo n.º 1
0
        /// <summary>
        /// Parses nodes from the text
        /// </summary>
        /// <param name="itemstext">text containing the items</param>
        /// <param name="parentItem">parent index item</param>
        /// <param name="arrNodes">arraylist where the nodes should be added</param>
        /// <param name="chmFile">CHMFile instance</param>
        private static void ParseItems(string itemstext, HtmlHelpIndexItem parentItem,
                                       List <HtmlHelpIndexItem> arrNodes, CHMFile chmFile)
        {
            int innerTextIdx  = ObjectRE.GroupNumberFromName("innerText");
            int innerPTextIdx = ParamRE.GroupNumberFromName("innerText");

            // get group-name indexes
            int nameIndex  = AttributesRE.GroupNumberFromName("attributeName");
            int valueIndex = AttributesRE.GroupNumberFromName("attributeValue");
            int tdIndex    = AttributesRE.GroupNumberFromName("attributeTD");

            int    nObjStartIndex     = 0;
            int    nLastObjStartIndex = 0;
            string sKeyword           = "";

            while (ObjectRE.IsMatch(itemstext, nObjStartIndex))
            {
                Match m = ObjectRE.Match(itemstext, nObjStartIndex);

                string innerText = m.Groups[innerTextIdx].Value;

                HtmlHelpIndexItem idxItem = new HtmlHelpIndexItem();

                // read parameters
                int nParamIndex = 0;
                int nNameCnt    = 0;

                string paramTitle = "";
                string paramLocal = "";
                bool   bAdded     = false;

                while (ParamRE.IsMatch(innerText, nParamIndex))
                {
                    Match mP = ParamRE.Match(innerText, nParamIndex);

                    string innerP = mP.Groups[innerPTextIdx].Value;

                    string paramName  = "";
                    string paramValue = "";

                    int nAttrIdx = 0;
                    //sKeyword = "";

                    while (AttributesRE.IsMatch(innerP, nAttrIdx))
                    {
                        Match mA = AttributesRE.Match(innerP, nAttrIdx);

                        string attributeName  = mA.Groups[nameIndex].Value;
                        string attributeValue = mA.Groups[valueIndex].Value;
                        string attributeTD    = mA.Groups[tdIndex].Value;

                        if (attributeTD.Length > 0)
                        {
                            // delete the trailing textqualifier
                            if (attributeValue.Length > 0)
                            {
                                int ltqi = attributeValue.LastIndexOf(attributeTD);

                                if (ltqi >= 0)
                                {
                                    attributeValue = attributeValue.Substring(0, ltqi);
                                }
                            }
                        }

                        if (attributeName.ToLower() == "name")
                        {
                            paramName = HttpUtility.HtmlDecode(attributeValue);                             // for unicode encoded values
                            nNameCnt++;
                        }

                        if (attributeName.ToLower() == "value")
                        {
                            paramValue = HttpUtility.HtmlDecode(attributeValue);                             // for unicode encoded values
                            // delete trailing /
                            while ((paramValue.Length > 0) && (paramValue[paramValue.Length - 1] == '/'))
                            {
                                paramValue = paramValue.Substring(0, paramValue.Length - 1);
                            }
                        }

                        nAttrIdx = mA.Index + mA.Length;
                    }

                    if (nNameCnt == 1)                     // first "Name" param = keyword
                    {
                        sKeyword = "";

                        if (parentItem != null)
                        {
                            sKeyword = parentItem.KeyWordPath + ",";
                        }

                        string sOldKW = sKeyword;

                        sKeyword += paramValue;

                        HtmlHelpIndexItem idxFind = FindByKeyword(arrNodes, sKeyword);

                        if (idxFind != null)
                        {
                            idxItem = idxFind;
                        }
                        else
                        {
                            if (sKeyword.Split(new char[] { ',' }).Length > 1)
                            {
                                idxItem.CharIndex = sKeyword.Length - paramValue.Length;
                            }
                            else
                            {
                                sKeyword          = paramValue;
                                sOldKW            = sKeyword;
                                idxItem.CharIndex = 0;
                            }

                            idxItem.KeyWordPath = sKeyword;
                            idxItem.Indent      = sKeyword.Split(new char[] { ',' }).Length - 1;
                            idxItem.IsSeeAlso   = false;

                            sKeyword = sOldKW;
                        }
                    }
                    else
                    {
                        if ((nNameCnt > 2) && (paramName.ToLower() == "name"))
                        {
                            bAdded = true;
                            HtmlHelpIndexTopic idxTopic = new HtmlHelpIndexTopic(paramTitle, paramLocal, chmFile.CompileFile, chmFile.ChmFilePath);

                            idxItem.Topics.Add(idxTopic);

                            paramTitle = "";
                            paramLocal = "";
                        }

                        switch (paramName.ToLower())
                        {
                        case "name":
                            //case "keyword":
                        {
                            paramTitle = paramValue;
                        }; break;

                        case "local":
                        {
                            paramLocal = paramValue.Replace("../", "").Replace("./", "");
                        }; break;

                        case "type":                                    // information type assignment for item
                        {
                            idxItem.InfoTypeStrings.Add(paramValue);
                        }; break;

                        case "see also":
                        {
                            idxItem.AddSeeAlso(paramValue);
                            idxItem.IsSeeAlso = true;
                            bAdded            = true;
                        }; break;
                        }
                    }

                    nParamIndex = mP.Index + mP.Length;
                }

                if (!bAdded)
                {
                    bAdded = false;
                    HtmlHelpIndexTopic idxTopic = new HtmlHelpIndexTopic(paramTitle, paramLocal, chmFile.CompileFile, chmFile.ChmFilePath);

                    idxItem.Topics.Add(idxTopic);

                    paramTitle = "";
                    paramLocal = "";
                }

                idxItem.ChmFile = chmFile;
                arrNodes.Add(idxItem);

                nLastObjStartIndex = nObjStartIndex;
                nObjStartIndex     = m.Index + m.Length;
            }
        }