private static object intersectPair(object L, object R, out bool isUri) {
//VERY OLD OPTION: return new Regex("(?=(" + ((Regex)X[i]).ToString()+ "))(" + ((Regex)Y[j]).ToString() + ")","i");
//STILL OLD OPTION: return new Regex("(?=.*?(" + L.ToString() + "))" + "(?=.*?(" + R.ToString() + "))");
// check RegexSpec.doc
//CURRENT OPTION: return new Regex("(?=(" + L.ToString() + "))(" + R.ToString() + ")", RegexOptions.IgnoreCase );
isUri = false;
DelayedRegex L_Pattern =L as DelayedRegex;
DelayedRegex R_Pattern =R as DelayedRegex;
if(L_Pattern != null && R_Pattern != null) { //both are Regex
return new DelayedRegex("(?=(" + L_Pattern.ToString() + "))(" + R_Pattern.ToString() + ")");
}
else if(L_Pattern != null && R_Pattern == null) { //only L is a Regex
isUri = R is Uri;
string uriString = isUri? ((Uri)R).GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped): R.ToString();
Match M = L_Pattern.AsRegex.Match(uriString);
if ((M != null) // Found match for the regular expression?
&& (M.Index == 0) // ... which starts at the begining
&& (M.Length == uriString.Length)) { // ... and the whole string matched
return R;
}
return null;
}
else if(L_Pattern == null && R_Pattern != null) { //only R is a Regex
isUri = L is Uri;
string uriString = isUri? ((Uri)L).GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped): L.ToString();
Match M = R_Pattern.AsRegex.Match(uriString);
if ((M != null) // Found match for the regular expression?
&& (M.Index == 0) // ... which starts at the begining
&& (M.Length == uriString.Length)) { // ... and the whole string matched
return L;
}
return null;
}
//both are Uris or strings
isUri = L is Uri;
if (isUri)
return L.Equals(R)? L : null;
else
return string.Compare(L.ToString(), R.ToString(), StringComparison.OrdinalIgnoreCase ) == 0? L : null;
}
} // class WebPermission