Exemplo n.º 1
0
        //────────────────────────────────────────
        public Expression_Node_String Compile(
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();
            log_Method.BeginMethod(Info_Syntax.Name_Library, this, "Compile",log_Reports);
            //

            String sTxtTmpl = this.Text;

            Configurationtree_Node parent_Cnf = new Configurationtree_NodeImpl("!ハードコーディング_TextTemplateImpl#Compile", null);
            Expression_Node_StringImpl result = new Expression_Node_StringImpl(null,parent_Cnf);

            int nCur = 0;

            while (nCur < sTxtTmpl.Length)
            {
                int nPreCur = nCur;

                // 開き%記号(open percent)
                int nOp = sTxtTmpl.IndexOf('%', nCur);

                if (nOp != -1)
                {
                    // 開き%記号があった。

                    nCur = nOp + 1;//「開き%」の次へ。

                    // 閉じ%記号(close percent)
                    int cp = sTxtTmpl.IndexOf('%', nCur);

                    if (cp != -1)
                    {
                        // 閉じ%記号があれば。

                        nCur = cp + 1;//「閉じ%」の次へ。

                        // 「%」と「%」の間に数字があるはず。
                        // 「開き%」の次から、「閉じ% - 開き% - 1」文字分。(-1しないと、終了%を含んでしまう)
                        string sMarker = sTxtTmpl.Substring(nOp + 1, cp - nOp - 1);

                        // 「%1%」といった記号の数字部分。
                        int nParameterIndex;

                        try
                        {
                            nParameterIndex = Int32.Parse(sMarker);

                            // 開き「%」までを、まず文字列化。
                            int nPreLen = nOp - nPreCur;
                            string sPre = sTxtTmpl.Substring(nPreCur, nPreLen);
                            result.AppendTextNode(
                                sPre,
                                parent_Cnf,
                                log_Reports
                                );

                            // 引数から値を取得。

                            // %数字%を、Expression化して追加。
                            Expression_TexttemplateP1pImpl expr_P1p = new Expression_TexttemplateP1pImpl(null,parent_Cnf);
                            expr_P1p.NumberP1p = nParameterIndex;
                            expr_P1p.Dictionary_P1p = this.Dictionary_NumberAndValue_Parameter;

                            result.List_Expression_Child.Add(
                                expr_P1p,
                                log_Reports
                                );

                            // 続行。
                        }
                        catch (Exception)
                        {
                            // 数字でないようなら。

                            // 今回の判定は失敗したものとして、残りの長さ全て
                            int nRestLen = sTxtTmpl.Length - nPreCur;

                            result.AppendTextNode(
                                sTxtTmpl.Substring(nPreCur, nRestLen),
                                parent_Cnf,
                                log_Reports
                                );

                            nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                        }
                    }
                    else
                    {
                        // 閉じ%がなければ。

                        // 今回の判定は失敗したものとして、残りの長さ全て
                        int nRestLen = sTxtTmpl.Length - nPreCur;

                        result.AppendTextNode(
                            sTxtTmpl.Substring(nPreCur, nRestLen),
                            parent_Cnf,
                            log_Reports
                            );

                        nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                    }
                }
                else
                {
                    // 開き%がなければ。

                    // 残りの長さ全て
                    int nRestLen = sTxtTmpl.Length - nCur;

                    result.AppendTextNode(
                        sTxtTmpl.Substring(nCur, nRestLen),
                        parent_Cnf,
                        log_Reports
                        );

                    nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                }
            }

            //
            //
            log_Method.EndMethod(log_Reports);
            return result;
        }
Exemplo n.º 2
0
        //────────────────────────────────────────

        public Expression_Node_String Compile(
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

            log_Method.BeginMethod(Info_Syntax.Name_Library, this, "Compile", log_Reports);
            //

            String sTxtTmpl = this.Text;



            Configurationtree_Node     parent_Cnf = new Configurationtree_NodeImpl("!ハードコーディング_TextTemplateImpl#Compile", null);
            Expression_Node_StringImpl result     = new Expression_Node_StringImpl(null, parent_Cnf);

            int nCur = 0;

            while (nCur < sTxtTmpl.Length)
            {
                int nPreCur = nCur;

                // 開き%記号(open percent)
                int nOp = sTxtTmpl.IndexOf('%', nCur);

                if (nOp != -1)
                {
                    // 開き%記号があった。

                    nCur = nOp + 1;//「開き%」の次へ。

                    // 閉じ%記号(close percent)
                    int cp = sTxtTmpl.IndexOf('%', nCur);

                    if (cp != -1)
                    {
                        // 閉じ%記号があれば。

                        nCur = cp + 1;//「閉じ%」の次へ。

                        // 「%」と「%」の間に数字があるはず。
                        // 「開き%」の次から、「閉じ% - 開き% - 1」文字分。(-1しないと、終了%を含んでしまう)
                        string sMarker = sTxtTmpl.Substring(nOp + 1, cp - nOp - 1);


                        // 「%1%」といった記号の数字部分。
                        int nParameterIndex;


                        try
                        {
                            nParameterIndex = Int32.Parse(sMarker);


                            // 開き「%」までを、まず文字列化。
                            int    nPreLen = nOp - nPreCur;
                            string sPre    = sTxtTmpl.Substring(nPreCur, nPreLen);
                            result.AppendTextNode(
                                sPre,
                                parent_Cnf,
                                log_Reports
                                );



                            // 引数から値を取得。

                            // %数字%を、Expression化して追加。
                            Expression_TexttemplateP1pImpl expr_P1p = new Expression_TexttemplateP1pImpl(null, parent_Cnf);
                            expr_P1p.NumberP1p      = nParameterIndex;
                            expr_P1p.Dictionary_P1p = this.Dictionary_NumberAndValue_Parameter;

                            result.List_Expression_Child.Add(
                                expr_P1p,
                                log_Reports
                                );

                            // 続行。
                        }
                        catch (Exception)
                        {
                            // 数字でないようなら。

                            // 今回の判定は失敗したものとして、残りの長さ全て
                            int nRestLen = sTxtTmpl.Length - nPreCur;

                            result.AppendTextNode(
                                sTxtTmpl.Substring(nPreCur, nRestLen),
                                parent_Cnf,
                                log_Reports
                                );


                            nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                        }
                    }
                    else
                    {
                        // 閉じ%がなければ。

                        // 今回の判定は失敗したものとして、残りの長さ全て
                        int nRestLen = sTxtTmpl.Length - nPreCur;

                        result.AppendTextNode(
                            sTxtTmpl.Substring(nPreCur, nRestLen),
                            parent_Cnf,
                            log_Reports
                            );

                        nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                    }
                }
                else
                {
                    // 開き%がなければ。

                    // 残りの長さ全て
                    int nRestLen = sTxtTmpl.Length - nCur;

                    result.AppendTextNode(
                        sTxtTmpl.Substring(nCur, nRestLen),
                        parent_Cnf,
                        log_Reports
                        );

                    nCur = sTxtTmpl.Length;//終了(最後の文字の次へカーソルを出す)
                }
            }


            //
            //
            log_Method.EndMethod(log_Reports);
            return(result);
        }