private string Extract(string text)
{
if (string.IsNullOrEmpty(text))
throw new ArgumentNullException("text");
StringBuilder stringBuilder = new StringBuilder(text.Length);
for (int i = 0; i < text.Length; i++)
if (!char.IsWhiteSpace(text[i]))
stringBuilder.Append(text[i]);
string uri = stringBuilder.ToString();
int firstCharPosition = 0;
int lastCharPosition = 0;
firstCharPosition = uri.IndexOf(Pkcs11UriSpec.Pk11UriSchemeName + Pkcs11UriSpec.Pk11UriAndPathSeparator, StringComparison.Ordinal);
if (firstCharPosition > 0)
{
if (uri[firstCharPosition - 1] == '"')
{
uri = uri.Remove(0, firstCharPosition);
lastCharPosition = uri.IndexOf('"');
}
else if (uri[firstCharPosition - 1] == '<')
{
uri = uri.Remove(0, firstCharPosition);
lastCharPosition = uri.IndexOf('>');
}
else
throw new Pkcs11UriException("URI is not delimited within double quotes or angle brackets");
if (lastCharPosition < 0)
throw new Pkcs11UriException("URI is not correctly delimited within double quotes or angle brackets");
uri = uri.Substring(0, lastCharPosition);
}
return uri;
}