private static void getXPathLex(string avt, ref int start, StringBuilder lex)
{
// AVT parser states
const int InExp = 0; // Inside AVT expression
const int InLiteralA = 1; // Inside literal in expression, apostrophe delimited
const int InLiteralQ = 2; // Inside literal in expression, quote delimited
Debug.Assert(avt.Length != start, "Empty string not supposed here");
Debug.Assert(lex.Length == 0, "Builder shoud to be reset here");
Debug.Assert(avt[start] == '{', "We calling getXPathLex() only after we realy meet {");
int avtLength = avt.Length;
int state = InExp;
for (int i = start + 1; i < avtLength; i++)
{
char ch = avt[i];
switch (state)
{
case InExp:
switch (ch)
{
case '{':
throw XsltException.Create(SR.Xslt_NestedAvt, avt);
case '}':
i++; // include '}'
if (i == start + 2)
{ // empty XPathExpresion
throw XsltException.Create(SR.Xslt_EmptyAvtExpr, avt);
}
lex.Append(avt, start + 1, i - start - 2); // avt without {}
start = i;
return;
case '\'':
state = InLiteralA;
break;
case '"':
state = InLiteralQ;
break;
}
break;
case InLiteralA:
if (ch == '\'')
{
state = InExp;
}
break;
case InLiteralQ:
if (ch == '"')
{
state = InExp;
}
break;
}
}
// if we meet end of string before } we have an error
throw XsltException.Create(state == InExp ? SR.Xslt_OpenBracesAvt : SR.Xslt_OpenLiteralAvt, avt);
}