using System;
using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
public static class UriExtensions
{
///
/// Gets the username from the given URI.
///
///
///
[NotNull]
public static string GetUserName([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.UserInfo.Split(':').FirstOrDefault(string.Empty);
}
///
/// Gets the password from the given URI.
///
///
///
[NotNull]
public static string GetPassword([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.UserInfo.Split(':').Skip(1).FirstOrDefault(string.Empty);
}
///
/// Returns true if the URI matches the default http://localhost/
///
///
///
public static bool GetIsDefault([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.ToString() == "http://localhost/";
}
///
/// Returns the string representation of the given URI, replacing the password with asterixes.
///
///
///
public static string ToPrivateString([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
IcdUriBuilder builder = new IcdUriBuilder(extends);
builder.Password = builder.Password == null ? null : StringUtils.PasswordFormat(builder.Password);
return builder.ToString();
}
}
}