} // class GSubLuaTableMatchEvaluator #endregion #endregion /// <summary>Implementation of http://www.lua.org/manual/5.3/manual.html#pdf-string.gsub </summary> /// <param name="s"></param> /// <param name="pattern"></param> /// <param name="repl"></param> /// <param name="n"></param> /// <returns></returns> public static LuaResult gsub(this string s, string pattern, object repl, int n) { Regex regex = new Regex(TranslateRegularExpression(pattern)); if (n <= 0) { n = Int32.MaxValue; } GSubMatchEvaluator matchEvaluator; if (repl is LuaTable) { matchEvaluator = new GSubLuaTableMatchEvaluator((LuaTable)repl); } else if (repl is Delegate || repl is ILuaMethod) { matchEvaluator = new GSubFunctionMatchEvaluator(repl); } else { matchEvaluator = new GSubStringMatchEvaluator((string)Lua.RtConvertValue(repl, typeof(string))); } string r = regex.Replace(s, matchEvaluator.MatchEvaluator, n); return(new LuaResult(r, matchEvaluator.MatchCount)); } // func gsub
/// <summary>Implementation of http://www.lua.org/manual/5.3/manual.html#pdf-string.gsub </summary> /// <param name="s"></param> /// <param name="pattern"></param> /// <param name="repl"></param> /// <param name="n"></param> /// <returns></returns> public static LuaResult gsub(this string s, string pattern, object repl, int n) { Regex regex = new Regex(TranslateRegularExpression(pattern)); if (n <= 0) n = Int32.MaxValue; GSubMatchEvaluator matchEvaluator; if (repl is LuaTable) matchEvaluator = new GSubLuaTableMatchEvaluator((LuaTable)repl); else if (repl is Delegate || repl is ILuaMethod) matchEvaluator = new GSubFunctionMatchEvaluator(repl); else matchEvaluator = new GSubStringMatchEvaluator((string)Lua.RtConvertValue(repl, typeof(string))); string r = regex.Replace(s, matchEvaluator.MatchEvaluator, n); return new LuaResult(r, matchEvaluator.MatchCount); }