예제 #1
0
            private static IList <FreeUtil.VarText> ToVarText(string text)
            {
                if (!splitCache.ContainsKey(text))
                {
                    IList <FreeUtil.VarText>  vars = new List <FreeUtil.VarText>();
                    IList <FreeUtil.PosIndex> list = GetPos(text, '{', '}');
                    if (list.Count == 0)
                    {
                        vars.Add(new FreeUtil.VarText(text, false));
                        return(vars);
                    }
                    FreeUtil.PosIndex lastEnd = null;
                    for (int i = 0; i < list.Count - 1; i = i + 2)
                    {
                        FreeUtil.PosIndex spi = list[i];
                        FreeUtil.PosIndex epi = list[i + 1];
                        if (lastEnd != null)
                        {
                            vars.Add(new FreeUtil.VarText(Sharpen.Runtime.Substring(text, lastEnd.index + 1, spi.index), false));
                        }
                        else
                        {
                            if (i == 0 && spi.index > 0)
                            {
                                vars.Add(new FreeUtil.VarText(Sharpen.Runtime.Substring(text, 0, spi.index), false));
                            }
                        }
                        vars.Add(new FreeUtil.VarText(Sharpen.Runtime.Substring(text, spi.index + 1, epi.index), true));
                        if (i + 1 == list.Count - 1)
                        {
                            if (epi.index < text.Length - 1)
                            {
                                vars.Add(new FreeUtil.VarText(Sharpen.Runtime.Substring(text, epi.index + 1, text.Length), false));
                            }
                        }
                        lastEnd = epi;
                    }

                    splitCache.Add(text, vars);
                }

                return(splitCache[text]);
            }
예제 #2
0
        public static IList <FreeUtil.PosIndex> GetPos(string text, char start, char end)
        {
            IList <FreeUtil.PosIndex> list = new List <FreeUtil.PosIndex>();

            char[] cs = text.ToCharArray();
            for (int i = 0; i < cs.Length; i++)
            {
                if (start == cs[i])
                {
                    FreeUtil.PosIndex pi = new FreeUtil.PosIndex(i, 0, true);
                    list.Add(pi);
                }
                else
                {
                    if (end == cs[i])
                    {
                        FreeUtil.PosIndex pi = new FreeUtil.PosIndex(i, 0, false);
                        list.Add(pi);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(list);
            }
            int max   = 0;
            int count = 0;

            foreach (FreeUtil.PosIndex pi_1 in list)
            {
                if (pi_1.start)
                {
                    count++;
                }
                pi_1.deep = count;
                if (count > max)
                {
                    max = count;
                }
                if (!pi_1.start)
                {
                    count--;
                }
            }
            if (max == 0 && list.Count > 0)
            {
                throw new GameConfigExpception("错误格式‘" + text + "’");
            }
            int status = 0;
            IList <FreeUtil.PosIndex> deepList = new List <FreeUtil.PosIndex>();

            for (int j = 0; j < list.Count; j++)
            {
                FreeUtil.PosIndex pi = list[j];
                if (pi.deep == 1)
                {
                    if (status == 0)
                    {
                        if (pi.start)
                        {
                            deepList.Add(pi);
                            status = 1;
                        }
                        else
                        {
                            throw new GameConfigExpception("错误格式‘" + text + "’");
                        }
                    }
                    else
                    {
                        if (status == 1)
                        {
                            if (!pi.start)
                            {
                                deepList.Add(pi);
                                status = 0;
                            }
                            else
                            {
                                throw new GameConfigExpception("错误格式‘" + text + "’");
                            }
                        }
                    }
                }
            }
            if (deepList.Count < 2 || deepList.Count % 2 != 0)
            {
                throw new GameConfigExpception("错误格式‘" + text + "’");
            }
            return(deepList);
        }