Exemple #1
0
        public static void q2str(string[] g, qStringGroup qs, StringGroup sg)
        {
            int y = qs.substr.Count;

            if (y == 0)
            {
                return;
            }

            if (y > 1)
            {
                if (qs.substr[0].topstr == -1 && qs.substr[1].topstr != -1)
                {
                    fixqs(qs);
                    y = qs.substr.Count;
                }
            }


            sg.substr = new StringGroup[y];
            for (int i = 0; i < y; i++)
            {
                var nsg = new StringGroup(g, qs.substr[i].topstr);
                sg.substr[i] = nsg;
                q2str(g, qs.substr[i], nsg);
            }
        }
Exemple #2
0
        public static void fixqs(qStringGroup qs)
        {
            int y = qs.substr.Count;

            bool[] pos = new bool[y];
            List <qStringGroup> nyusub = new List <qStringGroup>();

            for (int i = 0; i < y; i++)
            {
                if (qs.substr[i].topstr == -1)
                {
                    pos[i] = true;
                    nyusub.Add(qs.substr[i]);
                }
            }

            for (int i = 0; i < y; i++)
            {
                var valu = qs.substr[i];
                if (valu.topstr != -1)
                {
                    qs.substr[findprev(pos, i)].substr.Add(valu);
                }
            }

            qs.substr = nyusub;
        }
Exemple #3
0
 public static void setmoth(qStringGroup moth, qStringGroup nxsg)
 {
     if (moth.isArrayHead)
     {
         nxsg.parent = moth.parent;
     }
     else
     {
         nxsg.parent = moth;
     }
 }
Exemple #4
0
        public static qStringGroup MakeZu(qStringGroup moth, qStringGroup nxsg)
        {
            var grphd = new qStringGroup(-1);

            grphd.isArrayHead = true;
            setmoth(moth, grphd);

            grphd.substr.Add(nxsg);
            setmoth(moth, nxsg);

            moth.substr.Add(grphd);
            return(grphd);
        }
Exemple #5
0
        public static qStringGroup GetNParent(qStringGroup sg, int n)
        {
            qStringGroup rt = sg;

            if (sg.isArrayHead)
            {
                rt = sg.parent;
            }



            for (int i = 0; i < n; i++)
            {
                rt = rt.parent;
            }
            return(rt);
        }
Exemple #6
0
        public static StringGroup Parse(string[] g, int start, int endpos)
        {
            if (endpos < 0)
            {
                endpos = g.Length;
            }

            qStringGroup root  = new qStringGroup(-2);
            qStringGroup moth  = root;
            qStringGroup lastt = root;

            int curind = qStringGroup.CountInd(g[start]).a;

            for (int i = start; i < endpos; i++)
            {
                bswap nxindbs = qStringGroup.CountInd(g[i]);
                int   nxind   = nxindbs.a;

                g[i] = g[i].Substring(nxind * 2);
                qStringGroup nxsg = new qStringGroup(i);

                if (nxind > curind)
                {
                    moth = lastt;
                }
                else if (nxind < curind)
                {
                    moth = qStringGroup.GetNParent(moth, curind - nxind);
                }


                if (nxindbs.b == 1)
                {
                    if (moth.isArrayHead)
                    {
                        moth = moth.parent;
                    }

                    moth = qStringGroup.MakeZu(moth, nxsg);
                }
                else
                {
                    moth.substr.Add(nxsg);
                    qStringGroup.setmoth(moth, nxsg);
                }



                lastt  = nxsg;
                curind = nxind;
            }

            if (root.substr.Count == 1)
            {
                var vroot = root.substr[0];
                root.substr = null;
                root        = vroot;
                root.parent = null;
            }

            StringGroup Realroot = new StringGroup(g, root.topstr);

            q2str(g, root, Realroot);

            return(Realroot);
        }