public static Tuple<string, Uri> ParseSource(string sourceHtml)
{
if (string.IsNullOrEmpty(sourceHtml))
return Tuple.Create<string, Uri>("", null);
string sourceText;
Uri sourceUri;
// sourceHtmlの例: <a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>
var match = Regex.Match(sourceHtml, "^<a href=\"(?<uri>.+?)\".*?>(?<text>.+)</a>$", RegexOptions.IgnoreCase);
if (match.Success)
{
sourceText = WebUtility.HtmlDecode(match.Groups["text"].Value);
try
{
var uriStr = WebUtility.HtmlDecode(match.Groups["uri"].Value);
sourceUri = new Uri(SourceUriBase, uriStr);
}
catch (UriFormatException)
{
sourceUri = null;
}
}
else
{
sourceText = WebUtility.HtmlDecode(sourceHtml);
sourceUri = null;
}
return Tuple.Create(sourceText, sourceUri);
}