public static void read_long_string(LexState LS, SemInfo seminfo)
{
int cont = 0;
int l = 0;
checkbuffer(LS, l);
save(LS, '[', ref l); /* save first `[' */
save_and_next(LS, ref l); /* pass the second `[' */
if (LS.current == '\n' || LS.current == '\r') /* string starts with a newline? */
inclinenumber(LS); /* skip it */
bool bBreak = false;
for (; !bBreak; )
{
checkbuffer(LS, l);
switch (LS.current)
{
case EOZ:
save(LS, '\0', ref l);
luaX_lexerror(LS, (seminfo != null) ? "unfinished long string" :
"unfinished long comment", (int)RESERVED.TK_EOS);
break; /* to avoid warnings */
case '[':
save_and_next(LS, ref l);
if (LS.current == '[')
{
cont++;
save_and_next(LS, ref l);
}
continue;
case ']':
save_and_next(LS, ref l);
if (LS.current == ']')
{
if (cont == 0) bBreak = true;
cont--;
save_and_next(LS, ref l);
}
continue;
case '\n':
case '\r': // lua 5.1 syntax fix
save(LS, '\n', ref l);
inclinenumber(LS);
if (seminfo == null) l = 0; /* reset buffer to avoid wasting space */
continue;
default:
save_and_next(LS, ref l);
break;
}
}
save_and_next(LS, ref l); /* skip the second `]' */
save(LS, '\0', ref l);
if (seminfo != null)
{
seminfo.ts = new string(LS.buff, 2, l - 5);
}
}