예제 #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
        /// <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 result = target;//MakeCaseInsensitive.TransformInput(target);

            foreach (string pattern in dictionary.SettingNames)
            {
                string p2 = ApplySubstitutions.makeRegexSafe(pattern);
                //string match = "\\b" + @p2.Trim() + "\\b";
                string match       = @p2;
                string replacement = dictionary.grabSetting(pattern);
                if (replacement.StartsWith(" "))
                {
                    replacement = " ||" + replacement.TrimStart();
                }
                else
                {
                    replacement = "||" + replacement;
                }
                if (replacement.EndsWith(" "))
                {
                    replacement = replacement.TrimEnd() + "|| ";
                }
                else
                {
                    replacement = replacement + "||";
                }
                result = Regex.Replace(result, match, replacement, RegexOptions.IgnoreCase);
            }

            return(result.Replace("||", ""));
        }
        /// <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, ""));
        }