コード例 #1
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2      = ApplySubstitutions.makeRegexSafe(pattern);
                string valueP2 = dictionary.grabSetting(pattern).Trim();

                Regex regPattern = new Regex(p2, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                Match match      = regPattern.Match(result);
                if (match.Success)
                {
                    string match1 = p2.TrimEnd().TrimStart();
                    if (!String.IsNullOrEmpty(match1))
                    {
                        string replacement = marker + dictionary.grabSetting(pattern) + marker;
                        result = Regex.Replace(result, match1, replacement, RegexOptions.IgnoreCase);
                    }
                }
                //result = Regex.Replace(result, p2, valueP2, RegexOptions.IgnoreCase);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                //string match = p2.TrimEnd().TrimStart();
                //string replacement = marker+dictionary.grabSetting(pattern).Trim()+marker;
                //result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
            //return result;
        }
コード例 #2
0
        // Token: 0x06000043 RID: 67 RVA: 0x00003454 File Offset: 0x00002454
        public static string Substitute(Bot bot, SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string text   = target;

            foreach (string text2 in dictionary.SettingNames)
            {
                string text3       = ApplySubstitutions.makeRegexSafe(text2);
                string pattern     = "\\b" + text3.TrimEnd(new char[0]).TrimStart(new char[0]) + "\\b";
                string replacement = marker + dictionary.grabSetting(text2).Trim() + marker;
                text = Regex.Replace(text, pattern, replacement, RegexOptions.IgnoreCase);
            }
            return(text.Replace(marker, ""));
        }
コード例 #3
0
        /// <summary>
        /// Static helper that applies replacements from the passed dictionary object to the
        /// target string
        /// </summary>
        /// <param name="bot">The bot for whom this is being processed</param>
        /// <param name="dictionary">The dictionary containing the substitutions</param>
        /// <param name="target">the target string to which the substitutions are to be applied</param>
        /// <returns>The processed string</returns>
        public static string Substitute(AIMLbot.Bot bot, AIMLbot.Utils.SettingsDictionary dictionary, string target)
        {
            string marker = ApplySubstitutions.getMarker(5);
            string result = target;

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b"[email protected]().Replace(" ","\\s*")+"\\b";
                string match       = "\\b" + p2.TrimEnd().TrimStart() + "\\b";
                string replacement = marker + dictionary.grabSetting(pattern).Trim() + marker;
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace(marker, ""));
        }