private static bool ParseScheme (ParserState state)
{
string part = state.remaining;
StringBuilder sb = new StringBuilder ();
sb.Append (part [0]);
int index;
for (index = 1; index < part.Length; index++ ) {
char ch = part [index];
if (ch != '.' && ch != '-' && ch != '+' && !IsAlpha (ch) && !Char.IsDigit (ch))
break;
sb.Append (ch);
}
if (index == 0 || index >= part.Length) {
if (state.kind == UriKind.Absolute) {
state.error = "Invalid URI: The format of the URI could not be determined.";
return false;
}
state.elements.isAbsoluteUri = false;
return state.remaining.Length > 0;
}
if (part [index] != ':') {
if (state.kind == UriKind.Absolute) {
state.error = "Invalid URI: The URI scheme is not valid.";
return false;
}
state.elements.isAbsoluteUri = false;
return state.remaining.Length > 0;
}
state.elements.scheme = sb.ToString ().ToLowerInvariant ();
state.remaining = part.Substring (index);
// Check scheme name characters as specified in RFC2396.
// Note: different checks in 1.x and 2.0
if (!Uri.CheckSchemeName (state.elements.scheme)) {
if (state.kind == UriKind.Absolute) {
state.error = "Invalid URI: The URI scheme is not valid.";
return false;
}
state.elements.isAbsoluteUri = false;
return state.remaining.Length > 0;
}
return ParseDelimiter (state);
}