/// <devdoc>
/// Parses given name and checks it validity
/// </devdoc>
internal static string ParseName(char[] text, int start, int pos)
{
char esc = '\0';
string charsToEscape = "";
int saveStart = start;
int savePos = pos;
if (text[start] == '`')
{
Debug.Assert(text[checked ((int)pos - 1)] == '`', "Invalid identifyer bracketing, pos = " + pos.ToString(CultureInfo.InvariantCulture) + ", end = " + text[checked ((int)pos - 1)].ToString(CultureInfo.InvariantCulture));
start = checked ((int)start + 1);
pos = checked ((int)pos - 1);
esc = '\\';
charsToEscape = "`";
}
else if (text[start] == '[')
{
Debug.Assert(text[checked ((int)pos - 1)] == ']', "Invalid identifyer bracketing of name " + new string(text, start, pos - start) + " pos = " + pos.ToString(CultureInfo.InvariantCulture) + ", end = " + text[checked ((int)pos - 1)].ToString(CultureInfo.InvariantCulture));
start = checked ((int)start + 1);
pos = checked ((int)pos - 1);
esc = '\\';
charsToEscape = "]\\";
}
if (esc != '\0')
{
// scan the name in search for the ESC
int posEcho = start;
for (int i = start; i < pos; i++)
{
if (text[i] == esc)
{
if (i + 1 < pos && charsToEscape.IndexOf(text[i + 1]) >= 0)
{
i++;
}
}
text[posEcho] = text[i];
posEcho++;
}
pos = posEcho;
}
if (pos == start)
{
throw ExprException.InvalidName(new string(text, saveStart, savePos - saveStart));
}
return(new string(text, start, pos - start));
}