+#if NET_4_0
+ // @is_error_type - log as errors, else warnings
+ Func<string, bool> GetTryMatchRegexFunc (string regex_str, bool is_error_type)
+ {
+ bool is_bad = false;
+ Regex regex = null;
+ return (singleLine) => {
+ if (String.IsNullOrEmpty (regex_str) || is_bad)
+ return false;
+
+ try {
+ if (regex == null)
+ regex = new Regex (regex_str, RegexOptions.Compiled);
+ } catch (ArgumentException ae) {
+ Log.LogError ("The regular expression specified for '{0}' is invalid : {1}",
+ is_error_type ? "errors" : "warnings", ae.Message);
+ Log.LogMessage (MessageImportance.Low, "The regular expression specified for '{0}' is invalid : {1}",
+ is_error_type ? "errors" : "warnings", ae.ToString ());
+
+ is_bad = true;
+ return false;
+ }
+
+ if (!regex.Match (singleLine).Success)
+ return false;
+
+ if (is_error_type)
+ Log.LogError (singleLine);
+ else
+ Log.LogWarning (singleLine);
+ return true;
+ };
+ }
+#endif
+