Exemple #1
0
        //────────────────────────────────────────

        public Expr_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;



            Conf_String     parent_Cnf = new Conf_StringImpl("!ハードコーディング_TextTemplateImpl#Compile", null);
            Expr_StringImpl result     = new Expr_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化して追加。
                            Expr_TexttemplateP1pImpl expr_P1p = new Expr_TexttemplateP1pImpl(null, parent_Cnf);
                            expr_P1p.NumberP1p      = nParameterIndex;
                            expr_P1p.Dictionary_P1p = this.ParameterMap;

                            result.ChildNodes.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);
        }
Exemple #2
0
        //────────────────────────────────────────

        /// <summary>
        ///
        /// </summary>
        /// <param name="e_Result">検索結果。</param>
        /// <param name="name"></param>
        /// <param name="bRequired"></param>
        /// <param name="hits"></param>
        /// <param name="log_Reports"></param>
        /// <returns>検索結果が1件以上あれば真。</returns>
        public bool TrySelect(
            out Expr_String out_eResult,
            string name,
            EnumHitcount hits,
            Log_Reports log_Reports//bug:ヌルのことがある?
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

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

            bool isHit;

            if (this.map.ContainsKey(name))
            {
                // ヒット。
                out_eResult = this.map[name];
                isHit       = true;
            }
            else
            {
                // 一致なし。
                isHit = false;

                if (Utility_Hitcount.IsError_IfNoHit(hits, log_Reports))
                {
                    //エラーにする。
                    out_eResult = null;
                    goto gt_Error_NotFoundOne;
                }
                else
                {
                    // 該当しないキーを指定され、値を取得できなかったが、エラー報告しない。
                    Conf_String parent_Conf = new Conf_StringImpl("!ハードコーディング_NStringDictionaryImpl#Get", null);
                    out_eResult = new Expr_LeafStringImpl(null, parent_Conf);
                }
            }

            goto gt_EndMethod;
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_NotFoundOne:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー141!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append("指定された名前[");
                s.Append(name);
                s.Append("]は、“EDic(連想配列)”の中にありませんでした。");
                s.Newline();

                s.Append("┌────────┐キー一覧(個数=[");
                s.Append(this.map.Count);
                s.Append("])");
                s.Newline();
                foreach (string sKey in this.map.Keys)
                {
                    s.Append("[");
                    s.Append(sKey);
                    s.Append("]");
                    s.Newline();
                }
                s.Append("└────────┘");
                s.Newline();

                // ヒント

                if (null != this.Owner_Conf)
                {
                    s.Append("◆オーナー情報1");
                    s.Newline();
                    this.Owner_Conf.ToText_Content(s);
                }

                if (0 < this.map.Count)
                {
                    foreach (Expr_String eItem in this.map.Values)
                    {
                        Expr_String eParent = eItem.Parent;
                        if (null != eParent)//親要素が設定されていないことがある。
                        {
                            // 最初の1個。
                            s.Append("◆最初の要素の親の情報。");
                            s.Newline();
                            eParent.ToText_Snapshot(s);
                        }
                        break;
                    }
                }

                //
                // オーナーの情報。
                if (null != this.owner_Conf)//オーナー要素が設定されていないことがある。
                {
                    s.Newline();
                    s.Newline();
                    s.Append("◆オーナー情報2。");
                    s.Newline();
                    this.owner_Conf.ToText_Locationbreadcrumbs(s);
                }


                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(isHit);
        }