Files
VAR.WebFormsCore/Scrummer/Code/JSON/ParserContext.cs
2015-05-23 20:58:21 +02:00

87 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Scrummer.Code.JSON
{
public class ParserContext
{
#region Declarations
private String text;
private int length;
private int i;
private int markStart;
#endregion
#region Creator
public ParserContext(String text)
{
this.text = text;
this.length = text.Length;
this.i = 0;
this.markStart = 0;
}
#endregion
#region Public methods
public char SkipWhite()
{
while (i < length && Char.IsWhiteSpace(text[i]))
{
i++;
}
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public char Next()
{
i++;
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public bool AtEnd()
{
return i >= length;
}
public void Mark()
{
markStart = this.i;
}
public String GetMarked()
{
if (i < length && markStart < length)
{
return text.Substring(markStart, i);
}
else
{
if (markStart < length)
{
return text.Substring(markStart, length);
}
else
{
return string.Empty;
}
}
}
#endregion
}
}