コード例 #1
0
ファイル: ReplaceReference.cs プロジェクト: lqwangxg/newreg
        /// <summary>
        /// string Reference Dictionary<name, value>.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="pattern"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static string Reference(string input, string pattern, Dictionary <string, string> args)
        {
            MatchCollection matches          = Regex.Matches(input, pattern);
            Dictionary <Capture, string> map = new Dictionary <Capture, string>();

            foreach (Match mt in matches)
            {
                string key = mt.Groups[1].Value;
                if (!args.ContainsKey(key))
                {
                    continue;
                }

                map[mt] = args[key];
            }

            return(ReplaceUtils.GetReplaced(input, map));
        }
コード例 #2
0
ファイル: ReplaceReference.cs プロジェクト: lqwangxg/newreg
        /// <summary>
        /// Trim Reference to Const Strings.
        /// <remarks>
        /// e.g
        /// [$ABCD$] => ABCD
        /// </remarks>
        /// </summary>
        /// <param name="input">Trim Object</param>
        /// <returns>real string</returns>
        public static string Reference(string input)
        {
            // ==============================================
            string refconst = Parameters.Instance["refconst"];

            if (string.IsNullOrEmpty(refconst))
            {
                return(input);
            }

            Dictionary <Capture, string> map = new Dictionary <Capture, string>();
            MatchCollection matches          = Regex.Matches(input, refconst);

            foreach (Match mt in matches)
            {
                map[mt] = mt.Groups[1].Value;
            }
            return(ReplaceUtils.GetReplaced(input, map));
        }
コード例 #3
0
ファイル: ReplaceReference.cs プロジェクト: lqwangxg/newreg
        public static string Reference(string input, Match match)
        {
            // ==============================================
            // First: Reference Match Group, get groupindex \{\$(\d+)\$\}
            string pattern = Parameters.Instance["refmatch"];

            if (string.IsNullOrEmpty(pattern))
            {
                return(input);
            }

            Dictionary <Capture, string> map = new Dictionary <Capture, string>();

            MatchCollection matches = Regex.Matches(input, pattern);

            foreach (Match mt in matches)
            {
                int idx = int.Parse(mt.Groups[1].Value);
                map[mt] = match.Groups[idx].Value;
            }

            return(ReplaceUtils.GetReplaced(input, map));
        }