private static bool ParseUser (ParserState state)
{
string part = state.remaining;
StringBuilder sb = null;
int index;
for (index = 0; index < part.Length; index++) {
char ch = part [index];
bool isEscapedChar = false;
var oldIndex = index;
if (ch == '%'){
if (!Uri.IsHexEncoding (part, index))
return false;
ch = Uri.HexUnescape (part, ref index);
index--;
isEscapedChar = true;
}
if (!Char.IsLetterOrDigit (ch) && !IsUnreserved (ch) && !IsSubDelim (ch) && ch != ':'){
if (!isEscapedChar)
break;
ch = '%';
index = oldIndex;
}
if (sb == null)
sb = new StringBuilder ();
sb.Append (ch);
}
if (index + 1 <= part.Length && part [index] == '@') {
if (state.elements.scheme == Uri.UriSchemeFile) {
state.error = "Invalid URI: The hostname could not be parsed.";
return false;
}
state.elements.user = sb == null ? "" : sb.ToString ();
state.remaining = state.remaining.Substring (index + 1);
}
return state.remaining.Length > 0;
}