Ejemplo n.º 1
0
        private int c_lines;            // 行の数

        /// <summary>
        /// MultilineString の新しいインスタンスを生成します。
        /// </summary>
        /// <param name="text">何行何列目と何文字目の対応を付ける文字列を指定します。</param>
        public MultilineString(string text)
        {
            Gen::List <int> lines = new Gen::List <int>();

            lines.Add(0);
            bool lineend = false, cr = false;

            for (int i = 0, iM = text.Length; i < iM; i++)
            {
                if (text[i] == '\n')
                {
                    if (lineend && !cr)
                    {
                        lines.Add(i);                                  // 前の文字=='\n'
                    }
                    cr      = false;
                    lineend = true;
                }
                else if (lineend)
                {
                    // 前の文字== '\n' | '\r'
                    lines.Add(i);
                    cr = lineend = text[i] == '\r';
                }
            }
            this.c_lines = lines.Count;

            // 文字列の末尾
            lines.Add(text.Length);
            this.i_lines = lines.ToArray();

            this.str = text;
        }
Ejemplo n.º 2
0
            //========================================================
            /// <summary>
            /// '|' で区切られた候補達を読み取ります。
            /// </summary>
            /// <returns>読み取って出来たノードを返します。有効な正規表現指定が見つからなかった場合には null を返します。</returns>
            private INode Read()
            {
                Gen::List <INode> nodes = new Gen::List <INode>();

                while (true)
                {
                    switch (this.scanner.CurrentType.value)
                    {
                    case WordType.vInvalid:
                        goto ED_LOOP;

                    case WordType.vOperator:
                        if (scanner.CurrentWord == ")")
                        {
                            goto ED_LOOP;
                        }
                        else if (scanner.CurrentWord == "|")
                        {
                            this.scanner.ReadNext();
                            goto default;
                        }
                        else
                        {
                            goto default;
                        }

                    default:
                        INode node = this.ReadSequence();
                        if (node == null)
                        {
                            scanner.LetterReader.SetError("正規表現要素が一つもありません。", 0, null);
                            break;
                        }

                        nodes.Add(node);
                        break;
                    }
                }
ED_LOOP:
                if (nodes.Count == 0)
                {
                    return(null);
                }
                if (nodes.Count == 1)
                {
                    return(nodes[0]);
                }
                return(new OrNode(nodes.ToArray()));
            }
Ejemplo n.º 3
0
        public string[] splitModifiers(string mod)
        {
            Gen::List <string> list = new Gen::List <string>();

            string[] cands = mod.Split('.');
            string   cand;

            for (int i = 0; i < cands.Length; i++)
            {
                cand = cands[i].Trim();
                if (cand != "")
                {
                    list.Add(cand);
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 4
0
        //===========================================================
        //		乗除
        //===========================================================
        public static Member operator*(Member l, Member r)
        {
            Gen::List <Variable> vars = new Gen::List <Variable>();
            int il = 0, ilM = l.vars.Length;
            int ir = 0, irM = r.vars.Length;

            while (il < ilM && ir < irM)
            {
                int val = Variable.VariableOrderWithoutExp(l.vars[il], r.vars[ir]);
                if (val < 0)
                {
                    vars.Add(l.vars[il++]);
                }
                else if (val > 0)
                {
                    vars.Add(r.vars[ir++]);
                }
                else
                {
                    Variable v = l.vars[il++] * r.vars[ir++];
                    if (!v.IsConstant)
                    {
                        vars.Add(v);
                    }
                }
            }

            if (il < ilM)
            {
                do
                {
                    vars.Add(l.vars[il++]);
                }while(il < ilM);
            }
            else if (ir < irM)
            {
                do
                {
                    vars.Add(r.vars[ir++]);
                }while(ir < irM);
            }

            return(new Member(l.factor * r.factor, vars.ToArray()));
        }
Ejemplo n.º 5
0
        static ConnectionInfo CreateConnectionInfo(SshUserData data)
        {
            // create Authentication methods
            Gen::List <AuthenticationMethod> auth = new Gen::List <AuthenticationMethod>();

            if (data.pass != null && data.pass != "")
            {
                // Password based Authentication
                auth.Add(new PasswordAuthenticationMethod(data.user, data.pass));
            }
            if (data.useIdentityFile && data.idtt != "")
            {
                // Key Based Authentication (using keys in OpenSSH Format)
                auth.Add(new PrivateKeyAuthenticationMethod(data.user, new PrivateKeyFile[] {
                    new PrivateKeyFile(data.idtt, data.psph)
                }));
            }
            return(new ConnectionInfo(data.host, data.port, data.user, auth.ToArray()));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 指定したパスを結合し、.. や . 等の指定を含む場合にはそれらを解決します。
        /// </summary>
        /// <param name="path1">先に来るパスを指定します。</param>
        /// <param name="path2">後にくるパスを指定します。</param>
        /// <returns>結合した後のパスを返します。</returns>
        public static string Combine(string path1, string path2)
        {
            string path0 = System.IO.Path.Combine(path1, path2);

            if (path0.IndexOf("..") < 0)
            {
                return(path0);
            }

            //-- 正規化
            string[]           paths  = path0.TrimEnd('\\', '/').Split('\\', '/');
            Gen::List <string> paths2 = new Gen::List <string>();

            System.Text.StringBuilder r = new System.Text.StringBuilder();
            for (int i = 0; i < paths.Length; i++)
            {
                if (paths[i] == "..")
                {
                    if (paths2.Count == 0)
                    {
                        r.Append(@"..\");
                    }
                    else
                    {
                        paths2.RemoveAt(paths2.Count - 1);
                    }
                }
                else if (paths[i] != ".")
                {
                    paths2.Add(paths[i]);
                }
            }
            foreach (string x in paths2.ToArray())
            {
                r.Append(x); r.Append(@"\");
            }
            ;

            string r2 = r.ToString();

            return(r2 == ""?".":r2.TrimEnd('\\'));
        }
Ejemplo n.º 7
0
            /// <summary>
            /// 要素連続部分 ('|' '(' ')' などで区切られた部分) を読み取ります。
            /// </summary>
            /// <returns>読み取って出来たノードを返します。有効な正規表現指定が見つからなかった場合には null を返します。</returns>
            private INode ReadSequence()
            {
                Gen::List <INode> nodes = new Gen::List <INode>();

                while (true)
                {
                    switch (this.scanner.CurrentType.value)
                    {
                    case WordType.vInvalid:
                        goto ED_LOOP;

                    case WordType.vComment:                     // (?#)
                        this.scanner.ReadNext();
                        continue;

                    case RegexScannerA.WT_CHARCLASS:                     // [文字クラス]
                        nodes.Add(this.ProcessClass(this.scanner.CurrentWord));
                        this.scanner.ReadNext();
                        break;

                    case RegexScannerA.WT_COMMAND:                     // コマンド
                        parseCommand(ref nodes);
                        break;

                    case RegexScannerA.WT_COMMAND_C:                     // : コマンド
                        nodes.Add(this.ProcessCommandC(scanner.CurrentWord, scanner.Value));
                        this.scanner.ReadNext();
                        break;

                    case WordType.vSuffix:                     // ? + *
                        parseSuffix(ref nodes);
                        break;

                    case WordType.vOperator:                     // ( | )
                        if (scanner.CurrentWord == ")" || scanner.CurrentWord == "|")
                        {
                            goto ED_LOOP;
                        }
                        if (scanner.CurrentWord == "(?flags)")
                        {
                            // 括弧の始まる前に flags を覚えておく仕組み
                            __debug__.RegexParserToDo("未実装");
                        }
                        INode node = parseOperator();
                        if (node != null)
                        {
                            nodes.Add(node);
                        }
                        break;

                    case WordType.vText:                     // 通常の文字
                        switch (scanner.CurrentWord[0])
                        {
                        case '.': nodes.Add(AnyElemNode.Instance); break;

                        case '^': nodes.Add(StartOfStreamNode.instance); break;

                        case '$': nodes.Add(EndOfStreamNode.instance); break;

                        default:
                            nodes.Add(this.ProcessLetter(scanner.CurrentWord[0]));
                            break;
                        }
                        this.scanner.ReadNext();
                        break;
                    }
                }
ED_LOOP:
                if (nodes.Count == 0)
                {
                    return(null);
                }
                if (nodes.Count == 1)
                {
                    return(nodes[0]);
                }
                return(new SequenceNode(nodes.ToArray()));
            }
Ejemplo n.º 8
0
            private System.Predicate <char> CreateHandler(
                bool positive, IClassHandler[] handlers, bool[] issub,
                out IClassHandler[] child
                )
            {
                int[] borders;
                {
                    Gen::List <int> borders_l = new System.Collections.Generic.List <int>();
                    bool            current   = true;
                    for (int i = 0; i < issub.Length; i++)
                    {
                        if (issub[i] == current)
                        {
                            continue;
                        }
                        borders_l.Add(i);                         // *
                        current = issub[i];
                    }
                    // issub: [F T T T F F T T F T F F F T T T ]
                    // brdrs:    *     *   *   * * *     *     @

                    borders_l.Add(issub.Length);                     // @
                    borders = borders_l.ToArray();
                }

                afh.Reflection.DynamicMethodCreater <CompiledClassHandler, System.Predicate <char> > gh
                    = new afh.Reflection.DynamicMethodCreater <CompiledClassHandler, System.Predicate <char> >("<generated>", false);

                Gen::List <IClassHandler> child_l = new Gen::List <IClassHandler>();

                Emit::Label label = gh.CreateLabel();

                for (int k = 0, kM = borders.Length - 1; k < kM; k++)
                {
                    for (int i = borders[k]; i < borders[k + 1]; i++)
                    {
                        //-- それぞれのハンドラに応じた処理
                        // 判定陽性 → goto label;
                        // 判定陰性 → その儘次へ流れる
                        if (!handlers[i].Emit(gh, label))
                        {
                            // child リストから呼び出す場合
                            int iChild = child_l.Count;
                            child_l.Add(handlers[i]);

                            // (s1)= this.child[iChild]
                            gh.EmitLdarg(0);
                            gh.EmitLdfld(typeof(CompiledClassHandler), "child", false, true);
                            gh.EmitLdc(iChild);
                            gh.EmitLdelem(typeof(IClassHandler));

                            // if((s1).Judge(c))goto label;
                            gh.EmitLdarg(1);
                            gh.EmitCall(handlers[i].GetType(), false, false, "Judge", typeof(char));
                            gh.EmitBrtrue(label);
                        }
                    }

                    // もう終わる時
                    if (k + 1 == kM)
                    {
                        break;
                    }
                    else
                    {
                        Emit::Label newlabel = gh.CreateLabel();
                        gh.EmitBr(newlabel);
                        gh.MarkLabel(label);
                        label = newlabel;

                        positive = !positive;
                    }
                }
                gh.EmitLdc(!positive);
                gh.EmitRet();
                gh.MarkLabel(label);
                gh.EmitLdc(positive);
                gh.EmitRet();

                child = child_l.ToArray();

                return(gh.Instantiate(this));
            }
Ejemplo n.º 9
0
    byte[] ZipDeflate(byte[] str,int level)
    {
        int i,j;

        deflate_data=str;
        deflate_pos=0;
        deflate_start(level);

        byte[] buff=new byte[1024];
        Gen::List<byte> @out=new Gen::List<byte>();
        while((i=deflate_internal(buff,0,buff.Length))>0){
            for(j=0;j<i;j++)@out.Add(buff[j]);
        }
        deflate_data=null;// G.C.
        return @out.ToArray();
    }