|
using System;
namespace Ranslant.JSON.Linq
{
// use only for invalid JSON text (see specs: http://www.json.org/ )
public class JsonException: Exception
{
public JsonException(string s) : base("JSON: " + s)
{ }
}
public class JsonParserException : Exception
{
public JsonParserException(string s) : base(s)
{ }
}
internal static class JExtenssions
{
// extension method
public static string ConsumeToken(this string thisString, string token, bool removeSpaceBeforeToken, bool removeSpaceAfterToken)
{
string result = thisString;
char[] spaces = { ' ', '\n', '\t', '\r' };
if (removeSpaceBeforeToken)
result = result.TrimStart(spaces);
if (result.StartsWith(token))
result = result.Remove(0, token.Length);
else
throw new JsonParserException("token '" + token + "' not found");
if (removeSpaceAfterToken)
result = result.TrimStart(spaces);
return result;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.