本文整理汇总了C#中MatchEvaluator类的典型用法代码示例。如果您正苦于以下问题:C# MatchEvaluator类的具体用法?C# MatchEvaluator怎么用?C# MatchEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatchEvaluator类属于命名空间,在下文中一共展示了MatchEvaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(error);
}
HttpResponseBase response = context.HttpContext.Response;
if (!String.IsNullOrEmpty(ContentType))
{
response.ContentType = ContentType;
}
else
{
response.ContentType = "application/json";
}
if (ContentEncoding != null)
{
response.ContentEncoding = ContentEncoding;
}
if (Data != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsonstring = serializer.Serialize(Data);
string p = @"\\/Date\(\d+\)\\/";
MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertJsonDateToDateString);
Regex reg = new Regex(p);
jsonstring = reg.Replace(jsonstring, matchEvaluator);
response.Write(jsonstring);
}
}
示例2: Minify
public static string Minify(System.Web.Mvc.UrlHelper urlHelper, string cssPath, string requestPath, string cssContent)
{
// this construct is to enable us to refer to the relativePath above ...
MatchEvaluator urlDelegate = new MatchEvaluator(delegate(Match m)
{
// Change relative (to the original CSS) URL references to make them relative to the requested URL (controller / action)
string url = m.Value;
Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri || VirtualPathUtility.IsAbsolute(url))
{
// if the URL is absolute ("http://server/path/file.ext") or app absolute ("/path/file.ext") then leave it as it is
}
else
{
// get app relative url
url = VirtualPathUtility.Combine(cssPath, url);
url = VirtualPathUtility.MakeRelative(requestPath, url);
url = urlHelper.Content(url);
}
return url;
});
return Minify(urlHelper, urlDelegate, cssContent, 0);
}
示例3: ExecuteResult
/// <summary>
/// 重写执行视图
/// </summary>
/// <param name="context">上下文</param>
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
HttpResponseBase response = context.HttpContext.Response;
if (string.IsNullOrEmpty(this.ContentType))
{
response.ContentType = this.ContentType;
}
else
{
response.ContentType = "application/json";
}
if (this.ContentEncoding != null)
{
response.ContentEncoding = this.ContentEncoding;
}
if (this.Data != null)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
string jsonString = jss.Serialize(Data);
string p = @"\\/Date\((\d+)\)\\/";
MatchEvaluator matchEvaluator = new MatchEvaluator(this.ConvertJsonDateToDateString);
Regex reg = new Regex(p);
jsonString = reg.Replace(jsonString, matchEvaluator);
response.Write(jsonString);
}
}
示例4: DecodeNoTextileZones
public static string DecodeNoTextileZones(string tmp, string patternPrefix, string patternSuffix, string[] exceptions)
{
m_decodeExceptions = exceptions;
MatchEvaluator me = new MatchEvaluator(DecodeNoTextileZonesMatchEvaluator);
tmp = Regex.Replace(tmp, string.Format("({0}(?<notex>.+?){1})*", patternPrefix, patternSuffix), me);
return tmp;
}
示例5: ShowEscapeChars
/// <summary>
/// Replaces the characters null, alert, backspace, form feed,
/// newline, carriage return, horizontal tab and vertical tab
/// with their escaped version. This allows you to show
/// the escape characters.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ShowEscapeChars(string str)
{
Regex regex = new Regex("\0|\a|\b|\f|\n|\r|\t|\v");
MatchEvaluator evaluator =
new MatchEvaluator((new StringUtil()).MatchEvent);
return regex.Replace(str,evaluator);
}
示例6: ChangeAgentDB
private static void ChangeAgentDB()
{
if (File.Exists(".agent.db"))
{
var text = File.ReadAllText(".agent.db");
var evaluator1 = new MatchEvaluator(replaceAgent1);
text = Regex.Replace(
text,
"(\"s2_)([A-Za-z]{4})(\")",
evaluator1
);
text = Regex.Replace(
text,
"(http://)([A-Za-z]{4})(.patch.battle.net:1119/patch)",
evaluator1
);
text = Regex.Replace(
text,
"(\"installed_locales\" : " + @"\[\s+" + "\")([A-Za-z]{4})(\")",
evaluator1
);
text = Regex.Replace(
text,
"(\"display_locales\" : " + @"\[\s+" + "\")([A-Za-z]{4})(\")",
evaluator1
);
File.Delete(".agent.db");
File.WriteAllText(".agent.db", text);
}
}
示例7: Build
internal string Build (SubtitleCollection collection, SubtitleProperties subtitleProperties, FileProperties fileProperties) {
this.subtitleProperties = subtitleProperties;
StringBuilder output = new StringBuilder();
if (format.HasHeaders)
output.Append(format.HeadersToString(subtitleProperties, fileProperties));
if (format.HasBodyBegin)
output.Append(format.BodyBeginOut);
string subtitleExpression = GetSubtitleExpression(format, subtitleProperties, fileProperties);
Regex fieldExpression = new Regex(@"<<(?<Field>\w+)(,(?<Width>\d+))?>>");
MatchEvaluator matchEvaluator = new MatchEvaluator(this.FieldEvaluator);
foreach (Subtitle currentSubtitle in collection) {
subtitle = currentSubtitle;
string outputSubtitle = fieldExpression.Replace(subtitleExpression, matchEvaluator);
output.Append(outputSubtitle);
output.Append("\n");
subtitleNumber++;
previousSubtitle = subtitle;
}
if (format.HasBodyEnd)
output.Append(format.BodyEndOut);
subtitle = null;
previousSubtitle = null;
subtitleNumber = 1;
ConvertNewlines(output, fileProperties);
return output.ToString();
}
示例8: ExpandUrls
/// <summary>
/// Expands links into HTML hyperlinks inside of text or HTML.
/// </summary>
/// <param name="text">The text to expand</param>
/// <returns></returns>
public string ExpandUrls(string text)
{
MatchEvaluator matchEval = null;
string pattern = null;
string updated = null;
// *** Expand embedded hyperlinks
RegexOptions options =
RegexOptions.Multiline |
RegexOptions.IgnoreCase;
if (ParseFormattedLinks)
{
pattern = @"\[(.*?)\|(.*?)]";
matchEval = new MatchEvaluator(ExpandFormattedLinks);
updated = Regex.Replace(text, pattern, matchEval, options);
}
else
updated = text;
pattern = @"([""'=]|")?(http://|ftp://|https://|www\.|ftp\.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])";
matchEval = new MatchEvaluator(ExpandUrlsRegExEvaluator);
updated = Regex.Replace(updated, pattern, matchEval, options);
return updated;
}
示例9: MinifyJavascript
public string MinifyJavascript(string text)
{
// remove /* ... */ comments
text = Regex.Replace(text, @"(?<!/)/\*((?!\*/).)*\*/", string.Empty, RegexOptions.Singleline);
// remove // comments - remove all text beginning with // unless it is a hyperlink
text = Regex.Replace(text, @"(?<!https?:)//[^\n\r]*[\n\r]", string.Empty, RegexOptions.IgnoreCase);
//remove all line breaks and tabs
text = Regex.Replace(text, @"[\f\n\r\t\v]", string.Empty, RegexOptions.Singleline);
//remove all extraneous spaces
text = Regex.Replace(text, @" {2,}", string.Empty);
// temporarily replace spaces with a character sequence in the following: string phrases ("" or ''), regular expressions (//)
var evaluator = new MatchEvaluator(ReplaceSpaces);
text = Regex.Replace(text, @"'[^']*'|""[^""]*""", evaluator);
// remove any spaces around code characters - excluded: / (because it is used for regular expressions)
var codeCharacters = "[+*=(){}<>!|,;:?&-]+";
text = Regex.Replace(text, @"(?<!/) *(" + codeCharacters + ") *", "$1");
// restore spaces
text = text.Replace("~¬@~", " ");
return text;
}
示例10: Fix
public static string Fix(object data, MatchEvaluator replacer = null)
{
if (data == null) return null;
string fixed_data;
if (replacer != null) fixed_data = ControlChars.Value.Replace(data.ToString(), replacer);
else fixed_data = ControlChars.Value.Replace(data.ToString(), FixData_Replace);
return fixed_data;
}
示例11: ChangeContent
// Replace some swf to mp4.
public static void ChangeContent(ref string content, string pattern, MatchEvaluator evaluator)
{
Regex grx = new Regex(pattern, RegexOptions.IgnoreCase);
if (grx.IsMatch(content))
{
content = grx.Replace(content, evaluator);
}
}
示例12: ComplexReplace
/// <summary>
///
/// </summary>
/// <param name="matchPattern"></param>
/// <param name="source"></param>
public static void ComplexReplace(string matchPattern, string source)
{
MatchEvaluator replaceCallback = new MatchEvaluator(MatchHandler);
Regex RE = new Regex(matchPattern, RegexOptions.Multiline);
string newString = RE.Replace(source, replaceCallback);
Console.WriteLine("Replaced String = " + newString);
}
示例13: ConvertVariableLikeTOCInlines
public static string ConvertVariableLikeTOCInlines(string text, PreprocessedTextLocationMap map)
{
var evaluator = new MatchEvaluator(match => "[" + match.Groups["content"].Value + "]");
return map == null
? TOCPatternVariableLike.Replace(text, evaluator)
: Preprocessor.Replace(TOCPatternVariableLike, text, evaluator, map);
}
示例14: Replace
/// <summary>
/// 替换标签
/// </summary>
/// <param name="html"></param>
/// <param name="eval"></param>
/// <returns></returns>
public static string Replace(string html, MatchEvaluator eval)
{
//如果包含部分视图,则替换成部分视图的内容
//ReplacePartial(html);
//替换匹配
return tagRegex.Replace(html, eval);
}
示例15: ExpandUrls
public static string ExpandUrls(string inputText)
{
string pattern = @"[""'=]?(http://|ftp://|https://|www\.|ftp\.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])";
System.Text.RegularExpressions.RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase;
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern, options);
MatchEvaluator MatchEval = new MatchEvaluator(ExpandUrlsRegExEvaluator);
return Regex.Replace(inputText, pattern, MatchEval);
}