Compare commits
No commits in common. "master" and "v0.12.0" have entirely different histories.
31
COPYING
31
COPYING
@ -1,31 +0,0 @@
|
|||||||
This is free and unencumbered software released into the public domain.
|
|
||||||
|
|
||||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
||||||
distribute this software, either in source code form or as a compiled
|
|
||||||
binary, for any purpose, commercial or non-commercial, and by any
|
|
||||||
means.
|
|
||||||
|
|
||||||
In jurisdictions that recognize copyright laws, the author or authors
|
|
||||||
of this software dedicate any and all copyright interest in the
|
|
||||||
software to the public domain. We make this dedication for the benefit
|
|
||||||
of the public at large and to the detriment of our heirs and
|
|
||||||
successors. We intend this dedication to be an overt act of
|
|
||||||
relinquishment in perpetuity of all present and future rights to this
|
|
||||||
software under copyright law.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
||||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
For more information, please refer to <http://unlicense.org/>
|
|
||||||
|
|
||||||
Thank you for reading this notice. Following the tradition of other public
|
|
||||||
domain projects, here's a blessing:
|
|
||||||
|
|
||||||
May you find forgiveness for yourself and forgive others.
|
|
||||||
May you experience and share the gift of unconditional love.
|
|
||||||
May you see light, wherever the illusion of darkness appears.
|
|
@ -1,4 +0,0 @@
|
|||||||
# LitJSON
|
|
||||||
Based on https://github.com/LitJSON/litjson
|
|
||||||
|
|
||||||
Maybe you find this Repo on Github. This is a mirror from [here](https://git.blubbfish.net/vs_librarys/litjson).
|
|
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 15
|
|
||||||
VisualStudioVersion = 15.0.27004.2010
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {AF2398AC-1EAA-4615-B21A-33C68CD44849}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
16
litjson.sln
16
litjson.sln
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 16.0.29519.87
|
VisualStudioVersion = 15.0.27004.2010
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson", "litjson\litjson.csproj", "{244B45C3-E7A0-428B-8AF2-E992FA9E5964}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,15 +11,15 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Release|Any CPU.Build.0 = Release|Any CPU
|
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {E215FE79-F42D-4A58-B702-EC7E8AAFADFF}
|
SolutionGuid = {AF2398AC-1EAA-4615-B21A-33C68CD44849}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
// This file is used by Code Analysis to maintain SuppressMessage
|
|
||||||
// attributes that are applied to this project.
|
|
||||||
// Project-level suppressions either have no target or are given
|
|
||||||
// a specific target and scoped to a namespace, type, member, etc.
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
[assembly: SuppressMessage("Style", "IDE0038:Musterabgleich verwenden", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonMapper.WriteValue(System.Object,LitJson.JsonWriter,System.Boolean,System.Int32)")]
|
|
@ -11,14 +11,16 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
public enum JsonType {
|
{
|
||||||
|
public enum JsonType
|
||||||
|
{
|
||||||
None,
|
None,
|
||||||
|
|
||||||
Object,
|
Object,
|
||||||
Array,
|
Array,
|
||||||
String,
|
String,
|
||||||
@ -28,30 +30,31 @@ namespace LitJson {
|
|||||||
Boolean
|
Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IJsonWrapper : IList, IOrderedDictionary {
|
public interface IJsonWrapper : IList, IOrderedDictionary
|
||||||
Boolean IsArray { get; }
|
{
|
||||||
Boolean IsBoolean { get; }
|
bool IsArray { get; }
|
||||||
Boolean IsDouble { get; }
|
bool IsBoolean { get; }
|
||||||
Boolean IsInt { get; }
|
bool IsDouble { get; }
|
||||||
Boolean IsLong { get; }
|
bool IsInt { get; }
|
||||||
Boolean IsObject { get; }
|
bool IsLong { get; }
|
||||||
Boolean IsString { get; }
|
bool IsObject { get; }
|
||||||
|
bool IsString { get; }
|
||||||
|
|
||||||
Boolean GetBoolean();
|
bool GetBoolean ();
|
||||||
Double GetDouble();
|
double GetDouble ();
|
||||||
Int32 GetInt();
|
int GetInt ();
|
||||||
JsonType GetJsonType();
|
JsonType GetJsonType ();
|
||||||
Int64 GetLong();
|
long GetLong ();
|
||||||
String GetString();
|
string GetString ();
|
||||||
|
|
||||||
void SetBoolean(Boolean val);
|
void SetBoolean (bool val);
|
||||||
void SetDouble(Double val);
|
void SetDouble (double val);
|
||||||
void SetInt(Int32 val);
|
void SetInt (int val);
|
||||||
void SetJsonType(JsonType type);
|
void SetJsonType (JsonType type);
|
||||||
void SetLong(Int64 val);
|
void SetLong (long val);
|
||||||
void SetString(String val);
|
void SetString (string val);
|
||||||
|
|
||||||
String ToJson();
|
string ToJson ();
|
||||||
void ToJson(JsonWriter writer);
|
void ToJson (JsonWriter writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
|
{
|
||||||
public class JsonException :
|
public class JsonException :
|
||||||
#if NETSTANDARD1_5
|
#if NETSTANDARD1_5
|
||||||
Exception
|
Exception
|
||||||
@ -20,18 +21,45 @@ namespace LitJson {
|
|||||||
ApplicationException
|
ApplicationException
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public JsonException() : base() { }
|
public JsonException () : base ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
internal JsonException(ParserToken token) : base(String.Format("Invalid token '{0}' in input string", token)) { }
|
internal JsonException (ParserToken token) :
|
||||||
|
base (String.Format (
|
||||||
|
"Invalid token '{0}' in input string", token))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
internal JsonException(ParserToken token, Exception inner_exception) : base(String.Format("Invalid token '{0}' in input string", token), inner_exception) { }
|
internal JsonException (ParserToken token,
|
||||||
|
Exception inner_exception) :
|
||||||
|
base (String.Format (
|
||||||
|
"Invalid token '{0}' in input string", token),
|
||||||
|
inner_exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
internal JsonException(Int32 c) : base(String.Format("Invalid character '{0}' in input string", (Char)c)) { }
|
internal JsonException (int c) :
|
||||||
|
base (String.Format (
|
||||||
|
"Invalid character '{0}' in input string", (char) c))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
internal JsonException(Int32 c, Exception inner_exception) : base(String.Format("Invalid character '{0}' in input string", (Char)c), inner_exception) { }
|
internal JsonException (int c, Exception inner_exception) :
|
||||||
|
base (String.Format (
|
||||||
|
"Invalid character '{0}' in input string", (char) c),
|
||||||
|
inner_exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public JsonException(String message) : base(message) { }
|
|
||||||
|
|
||||||
public JsonException(String message, Exception inner_exception) : base(message, inner_exception) { }
|
public JsonException (string message) : base (message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonException (string message, Exception inner_exception) :
|
||||||
|
base (message, inner_exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,15 @@ namespace LitJson {
|
|||||||
private Type element_type;
|
private Type element_type;
|
||||||
|
|
||||||
public Type ElementType {
|
public Type ElementType {
|
||||||
get => this.element_type ?? typeof(JsonData);
|
get {
|
||||||
set => this.element_type = value;
|
if (this.element_type == null) {
|
||||||
|
return typeof(JsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.element_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set { this.element_type = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean IsArray { get; set; }
|
public Boolean IsArray { get; set; }
|
||||||
@ -41,8 +48,15 @@ namespace LitJson {
|
|||||||
private Type element_type;
|
private Type element_type;
|
||||||
|
|
||||||
public Type ElementType {
|
public Type ElementType {
|
||||||
get => this.element_type ?? typeof(JsonData);
|
get {
|
||||||
set => this.element_type = value;
|
if (this.element_type == null) {
|
||||||
|
return typeof(JsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.element_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
set { this.element_type = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean IsDictionary { get; set; }
|
public Boolean IsDictionary { get; set; }
|
||||||
@ -50,6 +64,7 @@ namespace LitJson {
|
|||||||
public IDictionary<String, PropertyMetadata> Properties { get; set; }
|
public IDictionary<String, PropertyMetadata> Properties { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal delegate void ExporterFunc(Object obj, JsonWriter writer);
|
internal delegate void ExporterFunc(Object obj, JsonWriter writer);
|
||||||
public delegate void ExporterFunc<T>(T obj, JsonWriter writer);
|
public delegate void ExporterFunc<T>(T obj, JsonWriter writer);
|
||||||
|
|
||||||
@ -276,15 +291,15 @@ namespace LitJson {
|
|||||||
Type value_type = underlying_type ?? inst_type;
|
Type value_type = underlying_type ?? inst_type;
|
||||||
|
|
||||||
if (reader.Token == JsonToken.Null) {
|
if (reader.Token == JsonToken.Null) {
|
||||||
#if NETSTANDARD1_5
|
#if NETSTANDARD1_5
|
||||||
if (inst_type.IsClass() || underlying_type != null) {
|
if (inst_type.IsClass() || underlying_type != null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (inst_type.IsClass || underlying_type != null) {
|
if (inst_type.IsClass || underlying_type != null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
throw new JsonException(String.Format("Can't assign null to an instance of type {0}", inst_type));
|
throw new JsonException(String.Format("Can't assign null to an instance of type {0}", inst_type));
|
||||||
}
|
}
|
||||||
@ -324,15 +339,14 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maybe it's an enum
|
// Maybe it's an enum
|
||||||
#if NETSTANDARD1_5
|
#if NETSTANDARD1_5
|
||||||
if (value_type.IsEnum()) {
|
if (value_type.IsEnum())
|
||||||
return Enum.ToObject (value_type, reader.Value);
|
return Enum.ToObject (value_type, reader.Value);
|
||||||
}
|
#else
|
||||||
#else
|
|
||||||
if (value_type.IsEnum) {
|
if (value_type.IsEnum) {
|
||||||
return Enum.ToObject(value_type, reader.Value);
|
return Enum.ToObject(value_type, reader.Value);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Try using an implicit conversion operator
|
// Try using an implicit conversion operator
|
||||||
MethodInfo conv_op = GetConvOp(value_type, json_type);
|
MethodInfo conv_op = GetConvOp(value_type, json_type);
|
||||||
|
|
||||||
@ -436,7 +450,7 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static IJsonWrapper ReadValue(WrapperFactory factory, JsonReader reader) {
|
private static IJsonWrapper ReadValue(WrapperFactory factory, JsonReader reader) {
|
||||||
_ = reader.Read();
|
reader.Read();
|
||||||
|
|
||||||
if (reader.Token == JsonToken.ArrayEnd ||
|
if (reader.Token == JsonToken.ArrayEnd ||
|
||||||
reader.Token == JsonToken.Null) {
|
reader.Token == JsonToken.Null) {
|
||||||
@ -478,13 +492,13 @@ namespace LitJson {
|
|||||||
if (item == null && reader.Token == JsonToken.ArrayEnd) {
|
if (item == null && reader.Token == JsonToken.ArrayEnd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ = instance.Add(item);
|
instance.Add(item);
|
||||||
}
|
}
|
||||||
} else if (reader.Token == JsonToken.ObjectStart) {
|
} else if (reader.Token == JsonToken.ObjectStart) {
|
||||||
instance.SetJsonType(JsonType.Object);
|
instance.SetJsonType(JsonType.Object);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
_ = reader.Read();
|
reader.Read();
|
||||||
|
|
||||||
if (reader.Token == JsonToken.ObjectEnd) {
|
if (reader.Token == JsonToken.ObjectEnd) {
|
||||||
break;
|
break;
|
||||||
@ -500,7 +514,9 @@ namespace LitJson {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReadSkip(JsonReader reader) => ToWrapper(delegate { return new JsonMockWrapper(); }, reader);
|
private static void ReadSkip(JsonReader reader) {
|
||||||
|
ToWrapper(delegate { return new JsonMockWrapper(); }, reader);
|
||||||
|
}
|
||||||
|
|
||||||
private static void RegisterBaseExporters() {
|
private static void RegisterBaseExporters() {
|
||||||
base_exporters_table[typeof(Byte)] = delegate (Object obj, JsonWriter writer) {
|
base_exporters_table[typeof(Byte)] = delegate (Object obj, JsonWriter writer) {
|
||||||
@ -627,10 +643,7 @@ namespace LitJson {
|
|||||||
|
|
||||||
if (obj is IJsonWrapper) {
|
if (obj is IJsonWrapper) {
|
||||||
if (writer_is_private) {
|
if (writer_is_private) {
|
||||||
String t = ((IJsonWrapper)obj).ToJson();
|
writer.TextWriter.Write(((IJsonWrapper)obj).ToJson());
|
||||||
writer.WriteJson(t);
|
|
||||||
//writer.TextWriter.Write(t);
|
|
||||||
//this.context.ExpectingValue = false;
|
|
||||||
} else {
|
} else {
|
||||||
((IJsonWrapper)obj).ToJson(writer);
|
((IJsonWrapper)obj).ToJson(writer);
|
||||||
}
|
}
|
||||||
@ -756,6 +769,7 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public static String ToJson(Object obj) {
|
public static String ToJson(Object obj) {
|
||||||
lock (static_writer_lock) {
|
lock (static_writer_lock) {
|
||||||
static_writer.Reset();
|
static_writer.Reset();
|
||||||
@ -766,32 +780,78 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ToJson(Object obj, JsonWriter writer) => WriteValue(obj, writer, false, 0);
|
public static void ToJson(Object obj, JsonWriter writer) {
|
||||||
|
WriteValue(obj, writer, false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public static JsonData ToObject(JsonReader reader) => (JsonData)ToWrapper(delegate { return new JsonData(); }, reader);
|
public static JsonData ToObject(JsonReader reader) {
|
||||||
|
return (JsonData)ToWrapper(delegate { return new JsonData(); }, reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static JsonData ToObject(TextReader reader) => (JsonData)ToWrapper(delegate { return new JsonData(); }, new JsonReader(reader));
|
public static JsonData ToObject(TextReader reader) {
|
||||||
|
JsonReader json_reader = new JsonReader(reader);
|
||||||
|
|
||||||
public static JsonData ToObject(String json) => (JsonData)ToWrapper(delegate { return new JsonData(); }, json);
|
return (JsonData)ToWrapper(delegate { return new JsonData(); }, json_reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static T ToObject<T>(JsonReader reader) => (T)ReadValue(typeof(T), reader);
|
public static JsonData ToObject(String json) {
|
||||||
|
return (JsonData)ToWrapper(delegate { return new JsonData(); }, json);
|
||||||
|
}
|
||||||
|
|
||||||
public static T ToObject<T>(TextReader reader) => (T)ReadValue(typeof(T), new JsonReader(reader));
|
public static T ToObject<T>(JsonReader reader) {
|
||||||
|
return (T)ReadValue(typeof(T), reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static T ToObject<T>(String json) => (T)ReadValue(typeof(T), new JsonReader(json));
|
public static T ToObject<T>(TextReader reader) {
|
||||||
|
JsonReader json_reader = new JsonReader(reader);
|
||||||
|
|
||||||
public static Object ToObject(String json, Type ConvertType) => ReadValue(ConvertType, new JsonReader(json));
|
return (T)ReadValue(typeof(T), json_reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static IJsonWrapper ToWrapper(WrapperFactory factory, JsonReader reader) => ReadValue(factory, reader);
|
public static T ToObject<T>(String json) {
|
||||||
|
JsonReader reader = new JsonReader(json);
|
||||||
|
|
||||||
public static IJsonWrapper ToWrapper(WrapperFactory factory, String json) => ReadValue(factory, new JsonReader(json));
|
return (T)ReadValue(typeof(T), reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static void RegisterExporter<T>(ExporterFunc<T> exporter) => custom_exporters_table[typeof(T)] = (Object obj, JsonWriter writer) => exporter((T)obj, writer);
|
public static Object ToObject(String json, Type ConvertType) {
|
||||||
|
JsonReader reader = new JsonReader(json);
|
||||||
|
|
||||||
public static void RegisterImporter<TJson, TValue>(ImporterFunc<TJson, TValue> importer) => RegisterImporter(custom_importers_table, typeof(TJson), typeof(TValue), (Object input) => importer((TJson)input));
|
return ReadValue(ConvertType, reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static void UnregisterExporters() => custom_exporters_table.Clear();
|
public static IJsonWrapper ToWrapper(WrapperFactory factory, JsonReader reader) {
|
||||||
|
return ReadValue(factory, reader);
|
||||||
|
}
|
||||||
|
|
||||||
public static void UnregisterImporters() => custom_importers_table.Clear();
|
public static IJsonWrapper ToWrapper(WrapperFactory factory, String json) {
|
||||||
|
JsonReader reader = new JsonReader(json);
|
||||||
|
|
||||||
|
return ReadValue(factory, reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterExporter<T>(ExporterFunc<T> exporter) {
|
||||||
|
ExporterFunc exporter_wrapper = delegate (Object obj, JsonWriter writer) {
|
||||||
|
exporter((T)obj, writer);
|
||||||
|
};
|
||||||
|
|
||||||
|
custom_exporters_table[typeof(T)] = exporter_wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RegisterImporter<TJson, TValue>(ImporterFunc<TJson, TValue> importer) {
|
||||||
|
ImporterFunc importer_wrapper = delegate (Object input) {
|
||||||
|
return importer((TJson)input);
|
||||||
|
};
|
||||||
|
|
||||||
|
RegisterImporter(custom_importers_table, typeof(TJson), typeof(TValue), importer_wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UnregisterExporters() {
|
||||||
|
custom_exporters_table.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UnregisterImporters() {
|
||||||
|
custom_importers_table.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,118 +15,91 @@ using System.Collections;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
public class JsonMockWrapper : IJsonWrapper {
|
{
|
||||||
public Boolean IsArray => false;
|
public class JsonMockWrapper : IJsonWrapper
|
||||||
|
{
|
||||||
|
public bool IsArray { get { return false; } }
|
||||||
|
public bool IsBoolean { get { return false; } }
|
||||||
|
public bool IsDouble { get { return false; } }
|
||||||
|
public bool IsInt { get { return false; } }
|
||||||
|
public bool IsLong { get { return false; } }
|
||||||
|
public bool IsObject { get { return false; } }
|
||||||
|
public bool IsString { get { return false; } }
|
||||||
|
|
||||||
public Boolean IsBoolean => false;
|
public bool GetBoolean () { return false; }
|
||||||
|
public double GetDouble () { return 0.0; }
|
||||||
|
public int GetInt () { return 0; }
|
||||||
|
public JsonType GetJsonType () { return JsonType.None; }
|
||||||
|
public long GetLong () { return 0L; }
|
||||||
|
public string GetString () { return ""; }
|
||||||
|
|
||||||
public Boolean IsDouble => false;
|
public void SetBoolean (bool val) {}
|
||||||
|
public void SetDouble (double val) {}
|
||||||
|
public void SetInt (int val) {}
|
||||||
|
public void SetJsonType (JsonType type) {}
|
||||||
|
public void SetLong (long val) {}
|
||||||
|
public void SetString (string val) {}
|
||||||
|
|
||||||
public Boolean IsInt => false;
|
public string ToJson () { return ""; }
|
||||||
|
public void ToJson (JsonWriter writer) {}
|
||||||
|
|
||||||
public Boolean IsLong => false;
|
|
||||||
|
|
||||||
public Boolean IsObject => false;
|
bool IList.IsFixedSize { get { return true; } }
|
||||||
|
bool IList.IsReadOnly { get { return true; } }
|
||||||
|
|
||||||
public Boolean IsString => false;
|
object IList.this[int index] {
|
||||||
|
get { return null; }
|
||||||
public Boolean GetBoolean() => false;
|
set {}
|
||||||
|
|
||||||
public Double GetDouble() => 0.0;
|
|
||||||
|
|
||||||
public Int32 GetInt() => 0;
|
|
||||||
|
|
||||||
public JsonType GetJsonType() => JsonType.None;
|
|
||||||
|
|
||||||
public Int64 GetLong() => 0L;
|
|
||||||
|
|
||||||
public String GetString() => "";
|
|
||||||
|
|
||||||
public void SetBoolean(Boolean val) { }
|
|
||||||
|
|
||||||
public void SetDouble(Double val) { }
|
|
||||||
|
|
||||||
public void SetInt(Int32 val) { }
|
|
||||||
|
|
||||||
public void SetJsonType(JsonType type) { }
|
|
||||||
|
|
||||||
public void SetLong(Int64 val) { }
|
|
||||||
|
|
||||||
public void SetString(String val) { }
|
|
||||||
|
|
||||||
public String ToJson() => "";
|
|
||||||
|
|
||||||
public void ToJson(JsonWriter writer) { }
|
|
||||||
|
|
||||||
Boolean IList.IsFixedSize => true;
|
|
||||||
|
|
||||||
Boolean IList.IsReadOnly => true;
|
|
||||||
|
|
||||||
Object IList.this[Int32 index] {
|
|
||||||
get => null;
|
|
||||||
set {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 IList.Add(Object value) => 0;
|
int IList.Add (object value) { return 0; }
|
||||||
|
void IList.Clear () {}
|
||||||
|
bool IList.Contains (object value) { return false; }
|
||||||
|
int IList.IndexOf (object value) { return -1; }
|
||||||
|
void IList.Insert (int i, object v) {}
|
||||||
|
void IList.Remove (object value) {}
|
||||||
|
void IList.RemoveAt (int index) {}
|
||||||
|
|
||||||
void IList.Clear() { }
|
|
||||||
|
|
||||||
Boolean IList.Contains(Object value) => false;
|
int ICollection.Count { get { return 0; } }
|
||||||
|
bool ICollection.IsSynchronized { get { return false; } }
|
||||||
|
object ICollection.SyncRoot { get { return null; } }
|
||||||
|
|
||||||
Int32 IList.IndexOf(Object value) => -1;
|
void ICollection.CopyTo (Array array, int index) {}
|
||||||
|
|
||||||
void IList.Insert(Int32 i, Object v) { }
|
|
||||||
|
|
||||||
void IList.Remove(Object value) { }
|
IEnumerator IEnumerable.GetEnumerator () { return null; }
|
||||||
|
|
||||||
void IList.RemoveAt(Int32 index) { }
|
|
||||||
|
|
||||||
Int32 ICollection.Count => 0;
|
bool IDictionary.IsFixedSize { get { return true; } }
|
||||||
|
bool IDictionary.IsReadOnly { get { return true; } }
|
||||||
|
|
||||||
Boolean ICollection.IsSynchronized => false;
|
ICollection IDictionary.Keys { get { return null; } }
|
||||||
|
ICollection IDictionary.Values { get { return null; } }
|
||||||
|
|
||||||
Object ICollection.SyncRoot => null;
|
object IDictionary.this[object key] {
|
||||||
|
get { return null; }
|
||||||
void ICollection.CopyTo(Array array, Int32 index) { }
|
set {}
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => null;
|
|
||||||
|
|
||||||
Boolean IDictionary.IsFixedSize => true;
|
|
||||||
|
|
||||||
Boolean IDictionary.IsReadOnly => true;
|
|
||||||
|
|
||||||
ICollection IDictionary.Keys => null;
|
|
||||||
|
|
||||||
ICollection IDictionary.Values => null;
|
|
||||||
|
|
||||||
Object IDictionary.this[Object key] {
|
|
||||||
get => null;
|
|
||||||
set {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDictionary.Add(Object k, Object v) { }
|
void IDictionary.Add (object k, object v) {}
|
||||||
|
void IDictionary.Clear () {}
|
||||||
|
bool IDictionary.Contains (object key) { return false; }
|
||||||
|
void IDictionary.Remove (object key) {}
|
||||||
|
|
||||||
void IDictionary.Clear() { }
|
IDictionaryEnumerator IDictionary.GetEnumerator () { return null; }
|
||||||
|
|
||||||
Boolean IDictionary.Contains(Object key) => false;
|
|
||||||
|
|
||||||
void IDictionary.Remove(Object key) { }
|
object IOrderedDictionary.this[int idx] {
|
||||||
|
get { return null; }
|
||||||
IDictionaryEnumerator IDictionary.GetEnumerator() => null;
|
set {}
|
||||||
|
|
||||||
Object IOrderedDictionary.this[Int32 idx] {
|
|
||||||
get => null;
|
|
||||||
set {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IDictionaryEnumerator IOrderedDictionary.GetEnumerator() => null;
|
IDictionaryEnumerator IOrderedDictionary.GetEnumerator () {
|
||||||
|
return null;
|
||||||
void IOrderedDictionary.Insert(Int32 i, Object k, Object v) { }
|
}
|
||||||
|
void IOrderedDictionary.Insert (int i, object k, object v) {}
|
||||||
void IOrderedDictionary.RemoveAt(Int32 i) { }
|
void IOrderedDictionary.RemoveAt (int i) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,328 +16,440 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
public enum JsonToken {
|
{
|
||||||
|
public enum JsonToken
|
||||||
|
{
|
||||||
None,
|
None,
|
||||||
|
|
||||||
ObjectStart,
|
ObjectStart,
|
||||||
PropertyName,
|
PropertyName,
|
||||||
ObjectEnd,
|
ObjectEnd,
|
||||||
|
|
||||||
ArrayStart,
|
ArrayStart,
|
||||||
ArrayEnd,
|
ArrayEnd,
|
||||||
|
|
||||||
Int,
|
Int,
|
||||||
Long,
|
Long,
|
||||||
Double,
|
Double,
|
||||||
|
|
||||||
String,
|
String,
|
||||||
|
|
||||||
Boolean,
|
Boolean,
|
||||||
Null
|
Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class JsonReader {
|
public class JsonReader
|
||||||
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private static readonly IDictionary<Int32, IDictionary<Int32, Int32[]>> parse_table;
|
private static readonly IDictionary<int, IDictionary<int, int[]>> parse_table;
|
||||||
|
|
||||||
private readonly Stack<Int32> automaton_stack;
|
private Stack<int> automaton_stack;
|
||||||
private Int32 current_input;
|
private int current_input;
|
||||||
private Int32 current_symbol;
|
private int current_symbol;
|
||||||
private readonly Lexer lexer;
|
private bool end_of_json;
|
||||||
private Boolean parser_in_string;
|
private bool end_of_input;
|
||||||
private Boolean parser_return;
|
private Lexer lexer;
|
||||||
private Boolean read_started;
|
private bool parser_in_string;
|
||||||
|
private bool parser_return;
|
||||||
|
private bool read_started;
|
||||||
private TextReader reader;
|
private TextReader reader;
|
||||||
private readonly Boolean reader_is_owned;
|
private bool reader_is_owned;
|
||||||
|
private bool skip_non_members;
|
||||||
|
private object token_value;
|
||||||
|
private JsonToken token;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
public Boolean AllowComments {
|
public bool AllowComments {
|
||||||
get => this.lexer.AllowComments;
|
get { return lexer.AllowComments; }
|
||||||
set => this.lexer.AllowComments = value;
|
set { lexer.AllowComments = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean AllowSingleQuotedStrings {
|
public bool AllowSingleQuotedStrings {
|
||||||
get => this.lexer.AllowSingleQuotedStrings;
|
get { return lexer.AllowSingleQuotedStrings; }
|
||||||
set => this.lexer.AllowSingleQuotedStrings = value;
|
set { lexer.AllowSingleQuotedStrings = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean SkipNonMembers { get; set; }
|
public bool SkipNonMembers {
|
||||||
|
get { return skip_non_members; }
|
||||||
|
set { skip_non_members = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean EndOfInput { get; private set; }
|
public bool EndOfInput {
|
||||||
|
get { return end_of_input; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean EndOfJson { get; private set; }
|
public bool EndOfJson {
|
||||||
|
get { return end_of_json; }
|
||||||
|
}
|
||||||
|
|
||||||
public JsonToken Token { get; private set; }
|
public JsonToken Token {
|
||||||
|
get { return token; }
|
||||||
|
}
|
||||||
|
|
||||||
public Object Value { get; private set; }
|
public object Value {
|
||||||
|
get { return token_value; }
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
static JsonReader() => parse_table = PopulateParseTable();
|
static JsonReader ()
|
||||||
|
{
|
||||||
public JsonReader(String json_text) : this(new StringReader(json_text), true) { }
|
parse_table = PopulateParseTable ();
|
||||||
|
|
||||||
public JsonReader(TextReader reader) : this(reader, false) { }
|
|
||||||
|
|
||||||
private JsonReader(TextReader reader, Boolean owned) {
|
|
||||||
if(reader == null) {
|
|
||||||
throw new ArgumentNullException("reader");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parser_in_string = false;
|
public JsonReader (string json_text) :
|
||||||
this.parser_return = false;
|
this (new StringReader (json_text), true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
this.read_started = false;
|
public JsonReader (TextReader reader) :
|
||||||
this.automaton_stack = new Stack<Int32>();
|
this (reader, false)
|
||||||
this.automaton_stack.Push((Int32)ParserToken.End);
|
{
|
||||||
this.automaton_stack.Push((Int32)ParserToken.Text);
|
}
|
||||||
|
|
||||||
this.lexer = new Lexer(reader);
|
private JsonReader (TextReader reader, bool owned)
|
||||||
|
{
|
||||||
|
if (reader == null)
|
||||||
|
throw new ArgumentNullException ("reader");
|
||||||
|
|
||||||
this.EndOfInput = false;
|
parser_in_string = false;
|
||||||
this.EndOfJson = false;
|
parser_return = false;
|
||||||
|
|
||||||
this.SkipNonMembers = true;
|
read_started = false;
|
||||||
|
automaton_stack = new Stack<int> ();
|
||||||
|
automaton_stack.Push ((int) ParserToken.End);
|
||||||
|
automaton_stack.Push ((int) ParserToken.Text);
|
||||||
|
|
||||||
|
lexer = new Lexer (reader);
|
||||||
|
|
||||||
|
end_of_input = false;
|
||||||
|
end_of_json = false;
|
||||||
|
|
||||||
|
skip_non_members = true;
|
||||||
|
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.reader_is_owned = owned;
|
reader_is_owned = owned;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Static Methods
|
#region Static Methods
|
||||||
private static IDictionary<Int32, IDictionary<Int32, Int32[]>> PopulateParseTable() =>
|
private static IDictionary<int, IDictionary<int, int[]>> PopulateParseTable ()
|
||||||
|
{
|
||||||
// See section A.2. of the manual for details
|
// See section A.2. of the manual for details
|
||||||
new Dictionary<Int32, IDictionary<Int32, Int32[]>> {
|
IDictionary<int, IDictionary<int, int[]>> parse_table = new Dictionary<int, IDictionary<int, int[]>> ();
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Array, '[',
|
||||||
|
'[',
|
||||||
|
(int) ParserToken.ArrayPrime);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ArrayPrime);
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '"',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '[',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, ']',
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, '{',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Number,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.True,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.False,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Null,
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest,
|
||||||
|
']');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Object);
|
||||||
|
TableAddCol (parse_table, ParserToken.Object, '{',
|
||||||
|
'{',
|
||||||
|
(int) ParserToken.ObjectPrime);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ObjectPrime);
|
||||||
|
TableAddCol (parse_table, ParserToken.ObjectPrime, '"',
|
||||||
|
(int) ParserToken.Pair,
|
||||||
|
(int) ParserToken.PairRest,
|
||||||
|
'}');
|
||||||
|
TableAddCol (parse_table, ParserToken.ObjectPrime, '}',
|
||||||
|
'}');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Pair);
|
||||||
|
TableAddCol (parse_table, ParserToken.Pair, '"',
|
||||||
|
(int) ParserToken.String,
|
||||||
|
':',
|
||||||
|
(int) ParserToken.Value);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.PairRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.PairRest, ',',
|
||||||
|
',',
|
||||||
|
(int) ParserToken.Pair,
|
||||||
|
(int) ParserToken.PairRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.PairRest, '}',
|
||||||
|
(int) ParserToken.Epsilon);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.String);
|
||||||
|
TableAddCol (parse_table, ParserToken.String, '"',
|
||||||
|
'"',
|
||||||
|
(int) ParserToken.CharSeq,
|
||||||
|
'"');
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Text);
|
||||||
|
TableAddCol (parse_table, ParserToken.Text, '[',
|
||||||
|
(int) ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Text, '{',
|
||||||
|
(int) ParserToken.Object);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.Value);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '"',
|
||||||
|
(int) ParserToken.String);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '[',
|
||||||
|
(int) ParserToken.Array);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, '{',
|
||||||
|
(int) ParserToken.Object);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Number,
|
||||||
|
(int) ParserToken.Number);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.True,
|
||||||
|
(int) ParserToken.True);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.False,
|
||||||
|
(int) ParserToken.False);
|
||||||
|
TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Null,
|
||||||
|
(int) ParserToken.Null);
|
||||||
|
|
||||||
|
TableAddRow (parse_table, ParserToken.ValueRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.ValueRest, ',',
|
||||||
|
',',
|
||||||
|
(int) ParserToken.Value,
|
||||||
|
(int) ParserToken.ValueRest);
|
||||||
|
TableAddCol (parse_table, ParserToken.ValueRest, ']',
|
||||||
|
(int) ParserToken.Epsilon);
|
||||||
|
|
||||||
|
return parse_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TableAddCol (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken row, int col,
|
||||||
|
params int[] symbols)
|
||||||
{
|
{
|
||||||
(Int32)ParserToken.Array,
|
parse_table[(int) row].Add (col, symbols);
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '[', new Int32[] { '[', (Int32)ParserToken.ArrayPrime } }
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
private static void TableAddRow (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken rule)
|
||||||
{
|
{
|
||||||
(Int32)ParserToken.ArrayPrime,
|
parse_table.Add ((int) rule, new Dictionary<int, int[]> ());
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '"', new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ '[', new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ ']', new Int32[] { ']' } },
|
|
||||||
{ '{', new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ (Int32)ParserToken.Number, new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ (Int32)ParserToken.True, new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ (Int32)ParserToken.False, new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } },
|
|
||||||
{ (Int32)ParserToken.Null, new Int32[] { (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest, ']' } }
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.Object,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '{', new Int32[] { '{', (Int32)ParserToken.ObjectPrime } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.ObjectPrime,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '"', new Int32[] { (Int32)ParserToken.Pair, (Int32)ParserToken.PairRest, '}' } },
|
|
||||||
{ '}', new Int32[] { '}' } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.Pair,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '"', new Int32[] { (Int32)ParserToken.String, ':', (Int32)ParserToken.Value } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.PairRest,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ ',', new Int32[] { ',', (Int32)ParserToken.Pair, (Int32)ParserToken.PairRest } },
|
|
||||||
{ '}', new Int32[] { (Int32)ParserToken.Epsilon } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.String,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '"', new Int32[] { '"', (Int32)ParserToken.CharSeq, '"' } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.Text,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '[', new Int32[] { (Int32)ParserToken.Array } },
|
|
||||||
{ '{', new Int32[] { (Int32)ParserToken.Object } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.Value,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ '"', new Int32[] { (Int32)ParserToken.String } },
|
|
||||||
{ '[', new Int32[] { (Int32)ParserToken.Array } },
|
|
||||||
{ '{', new Int32[] { (Int32)ParserToken.Object } },
|
|
||||||
{ (Int32)ParserToken.Number, new Int32[] { (Int32)ParserToken.Number } },
|
|
||||||
{ (Int32)ParserToken.True, new Int32[] { (Int32)ParserToken.True } },
|
|
||||||
{ (Int32)ParserToken.False, new Int32[] { (Int32)ParserToken.False } },
|
|
||||||
{ (Int32)ParserToken.Null, new Int32[] { (Int32)ParserToken.Null } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
(Int32)ParserToken.ValueRest,
|
|
||||||
new Dictionary<Int32, Int32[]> {
|
|
||||||
{ ',', new Int32[] { ',', (Int32)ParserToken.Value, (Int32)ParserToken.ValueRest } },
|
|
||||||
{ ']', new Int32[] { (Int32)ParserToken.Epsilon } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void ProcessNumber(String number) {
|
private void ProcessNumber (string number)
|
||||||
if(number.IndexOf('.') != -1 || number.IndexOf('e') != -1 || number.IndexOf('E') != -1) {
|
{
|
||||||
if(Double.TryParse(number, NumberStyles.Any, CultureInfo.InvariantCulture, out Double n_double)) {
|
if (number.IndexOf ('.') != -1 ||
|
||||||
this.Token = JsonToken.Double;
|
number.IndexOf ('e') != -1 ||
|
||||||
this.Value = n_double;
|
number.IndexOf ('E') != -1) {
|
||||||
|
|
||||||
|
double n_double;
|
||||||
|
if (double.TryParse (number, NumberStyles.Any, CultureInfo.InvariantCulture, out n_double)) {
|
||||||
|
token = JsonToken.Double;
|
||||||
|
token_value = n_double;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Int32.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out Int32 n_int32)) {
|
int n_int32;
|
||||||
this.Token = JsonToken.Int;
|
if (int.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int32)) {
|
||||||
this.Value = n_int32;
|
token = JsonToken.Int;
|
||||||
|
token_value = n_int32;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Int64.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out Int64 n_int64)) {
|
long n_int64;
|
||||||
this.Token = JsonToken.Long;
|
if (long.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int64)) {
|
||||||
this.Value = n_int64;
|
token = JsonToken.Long;
|
||||||
|
token_value = n_int64;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(UInt64.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out UInt64 n_uint64)) {
|
ulong n_uint64;
|
||||||
this.Token = JsonToken.Long;
|
if (ulong.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_uint64))
|
||||||
this.Value = n_uint64;
|
{
|
||||||
|
token = JsonToken.Long;
|
||||||
|
token_value = n_uint64;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shouldn't happen, but just in case, return something
|
// Shouldn't happen, but just in case, return something
|
||||||
this.Token = JsonToken.Int;
|
token = JsonToken.Int;
|
||||||
this.Value = 0;
|
token_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessSymbol() {
|
private void ProcessSymbol ()
|
||||||
if(this.current_symbol == '[') {
|
{
|
||||||
this.Token = JsonToken.ArrayStart;
|
if (current_symbol == '[') {
|
||||||
this.parser_return = true;
|
token = JsonToken.ArrayStart;
|
||||||
} else if(this.current_symbol == ']') {
|
parser_return = true;
|
||||||
this.Token = JsonToken.ArrayEnd;
|
|
||||||
this.parser_return = true;
|
} else if (current_symbol == ']') {
|
||||||
} else if(this.current_symbol == '{') {
|
token = JsonToken.ArrayEnd;
|
||||||
this.Token = JsonToken.ObjectStart;
|
parser_return = true;
|
||||||
this.parser_return = true;
|
|
||||||
} else if(this.current_symbol == '}') {
|
} else if (current_symbol == '{') {
|
||||||
this.Token = JsonToken.ObjectEnd;
|
token = JsonToken.ObjectStart;
|
||||||
this.parser_return = true;
|
parser_return = true;
|
||||||
} else if(this.current_symbol == '"') {
|
|
||||||
if(this.parser_in_string) {
|
} else if (current_symbol == '}') {
|
||||||
this.parser_in_string = false;
|
token = JsonToken.ObjectEnd;
|
||||||
this.parser_return = true;
|
parser_return = true;
|
||||||
|
|
||||||
|
} else if (current_symbol == '"') {
|
||||||
|
if (parser_in_string) {
|
||||||
|
parser_in_string = false;
|
||||||
|
|
||||||
|
parser_return = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(this.Token == JsonToken.None) {
|
if (token == JsonToken.None)
|
||||||
this.Token = JsonToken.String;
|
token = JsonToken.String;
|
||||||
|
|
||||||
|
parser_in_string = true;
|
||||||
}
|
}
|
||||||
this.parser_in_string = true;
|
|
||||||
}
|
} else if (current_symbol == (int) ParserToken.CharSeq) {
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.CharSeq) {
|
token_value = lexer.StringValue;
|
||||||
this.Value = this.lexer.StringValue;
|
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.False) {
|
} else if (current_symbol == (int) ParserToken.False) {
|
||||||
this.Token = JsonToken.Boolean;
|
token = JsonToken.Boolean;
|
||||||
this.Value = false;
|
token_value = false;
|
||||||
this.parser_return = true;
|
parser_return = true;
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.Null) {
|
|
||||||
this.Token = JsonToken.Null;
|
} else if (current_symbol == (int) ParserToken.Null) {
|
||||||
this.parser_return = true;
|
token = JsonToken.Null;
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.Number) {
|
parser_return = true;
|
||||||
this.ProcessNumber(this.lexer.StringValue);
|
|
||||||
this.parser_return = true;
|
} else if (current_symbol == (int) ParserToken.Number) {
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.Pair) {
|
ProcessNumber (lexer.StringValue);
|
||||||
this.Token = JsonToken.PropertyName;
|
|
||||||
} else if(this.current_symbol == (Int32)ParserToken.True) {
|
parser_return = true;
|
||||||
this.Token = JsonToken.Boolean;
|
|
||||||
this.Value = true;
|
} else if (current_symbol == (int) ParserToken.Pair) {
|
||||||
this.parser_return = true;
|
token = JsonToken.PropertyName;
|
||||||
|
|
||||||
|
} else if (current_symbol == (int) ParserToken.True) {
|
||||||
|
token = JsonToken.Boolean;
|
||||||
|
token_value = true;
|
||||||
|
parser_return = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean ReadToken() {
|
private bool ReadToken ()
|
||||||
if(this.EndOfInput) {
|
{
|
||||||
|
if (end_of_input)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lexer.NextToken ();
|
||||||
|
|
||||||
|
if (lexer.EndOfInput) {
|
||||||
|
Close ();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_ = this.lexer.NextToken();
|
|
||||||
if(this.lexer.EndOfInput) {
|
current_input = lexer.Token;
|
||||||
this.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.current_input = this.lexer.Token;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public void Close() {
|
public void Close ()
|
||||||
if(this.EndOfInput) {
|
{
|
||||||
|
if (end_of_input)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
this.EndOfInput = true;
|
end_of_input = true;
|
||||||
this.EndOfJson = true;
|
end_of_json = true;
|
||||||
if(this.reader_is_owned) {
|
|
||||||
using(this.reader) {
|
if (reader_is_owned)
|
||||||
}
|
{
|
||||||
}
|
using(reader){}
|
||||||
this.reader = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean Read() {
|
reader = null;
|
||||||
if(this.EndOfInput) {
|
}
|
||||||
|
|
||||||
|
public bool Read ()
|
||||||
|
{
|
||||||
|
if (end_of_input)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (end_of_json) {
|
||||||
|
end_of_json = false;
|
||||||
|
automaton_stack.Clear ();
|
||||||
|
automaton_stack.Push ((int) ParserToken.End);
|
||||||
|
automaton_stack.Push ((int) ParserToken.Text);
|
||||||
|
}
|
||||||
|
|
||||||
|
parser_in_string = false;
|
||||||
|
parser_return = false;
|
||||||
|
|
||||||
|
token = JsonToken.None;
|
||||||
|
token_value = null;
|
||||||
|
|
||||||
|
if (! read_started) {
|
||||||
|
read_started = true;
|
||||||
|
|
||||||
|
if (! ReadToken ())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(this.EndOfJson) {
|
|
||||||
this.EndOfJson = false;
|
|
||||||
this.automaton_stack.Clear();
|
|
||||||
this.automaton_stack.Push((Int32)ParserToken.End);
|
|
||||||
this.automaton_stack.Push((Int32)ParserToken.Text);
|
|
||||||
}
|
|
||||||
this.parser_in_string = false;
|
|
||||||
this.parser_return = false;
|
|
||||||
this.Token = JsonToken.None;
|
|
||||||
this.Value = null;
|
|
||||||
if(!this.read_started) {
|
|
||||||
this.read_started = true;
|
|
||||||
if(!this.ReadToken()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Int32[] entry_symbols;
|
int[] entry_symbols;
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
if(this.parser_return) {
|
if (parser_return) {
|
||||||
if(this.automaton_stack.Peek() == (Int32)ParserToken.End) {
|
if (automaton_stack.Peek () == (int) ParserToken.End)
|
||||||
this.EndOfJson = true;
|
end_of_json = true;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.current_symbol = this.automaton_stack.Pop();
|
current_symbol = automaton_stack.Pop ();
|
||||||
|
|
||||||
this.ProcessSymbol();
|
ProcessSymbol ();
|
||||||
|
|
||||||
if(this.current_symbol == this.current_input) {
|
if (current_symbol == current_input) {
|
||||||
if(!this.ReadToken()) {
|
if (! ReadToken ()) {
|
||||||
if(this.automaton_stack.Peek() != (Int32)ParserToken.End) {
|
if (automaton_stack.Peek () != (int) ParserToken.End)
|
||||||
throw new JsonException(
|
throw new JsonException (
|
||||||
"Input doesn't evaluate to proper JSON text");
|
"Input doesn't evaluate to proper JSON text");
|
||||||
}
|
|
||||||
|
|
||||||
if(this.parser_return) {
|
if (parser_return)
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -348,19 +460,17 @@ namespace LitJson {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
entry_symbols =
|
entry_symbols =
|
||||||
parse_table[this.current_symbol][this.current_input];
|
parse_table[current_symbol][current_input];
|
||||||
|
|
||||||
} catch(KeyNotFoundException e) {
|
} catch (KeyNotFoundException e) {
|
||||||
throw new JsonException((ParserToken)this.current_input, e);
|
throw new JsonException ((ParserToken) current_input, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entry_symbols[0] == (Int32)ParserToken.Epsilon) {
|
if (entry_symbols[0] == (int) ParserToken.Epsilon)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
for(Int32 i = entry_symbols.Length - 1; i >= 0; i--) {
|
for (int i = entry_symbols.Length - 1; i >= 0; i--)
|
||||||
this.automaton_stack.Push(entry_symbols[i]);
|
automaton_stack.Push (entry_symbols[i]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ using System.Text;
|
|||||||
|
|
||||||
namespace LitJson
|
namespace LitJson
|
||||||
{
|
{
|
||||||
internal enum Condition {
|
internal enum Condition
|
||||||
|
{
|
||||||
InArray,
|
InArray,
|
||||||
InObject,
|
InObject,
|
||||||
NotAProperty,
|
NotAProperty,
|
||||||
@ -26,7 +27,8 @@ namespace LitJson
|
|||||||
Value
|
Value
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class WriterContext {
|
internal class WriterContext
|
||||||
|
{
|
||||||
public Int32 Count;
|
public Int32 Count;
|
||||||
public Boolean InArray;
|
public Boolean InArray;
|
||||||
public Boolean InObject;
|
public Boolean InObject;
|
||||||
@ -44,90 +46,121 @@ namespace LitJson
|
|||||||
private Char[] hex_seq;
|
private Char[] hex_seq;
|
||||||
private Int32 indentation;
|
private Int32 indentation;
|
||||||
private Int32 indent_value;
|
private Int32 indent_value;
|
||||||
private readonly StringBuilder inst_string_builder;
|
private StringBuilder inst_string_builder;
|
||||||
|
private Boolean pretty_print;
|
||||||
|
private Boolean validate;
|
||||||
|
private Boolean lower_case_properties;
|
||||||
|
private TextWriter writer;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public Int32 IndentValue {
|
public Int32 IndentValue {
|
||||||
get => this.indent_value;
|
get { return this.indent_value; }
|
||||||
set {
|
set {
|
||||||
this.indentation = this.indentation / this.indent_value * value;
|
this.indentation = (this.indentation / this.indent_value) * value;
|
||||||
this.indent_value = value;
|
this.indent_value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean PrettyPrint { get; set; }
|
public Boolean PrettyPrint {
|
||||||
|
get { return this.pretty_print; }
|
||||||
|
set { this.pretty_print = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private TextWriter TextWriter { get; }
|
public TextWriter TextWriter {
|
||||||
|
get { return this.writer; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean Validate { get; set; }
|
public Boolean Validate {
|
||||||
|
get { return this.validate; }
|
||||||
|
set { this.validate = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean LowerCaseProperties { get; set; }
|
public Boolean LowerCaseProperties {
|
||||||
|
get { return this.lower_case_properties; }
|
||||||
|
set { this.lower_case_properties = value; }
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
static JsonWriter() => number_format = NumberFormatInfo.InvariantInfo;
|
static JsonWriter() {
|
||||||
|
number_format = NumberFormatInfo.InvariantInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public JsonWriter() {
|
public JsonWriter() {
|
||||||
this.inst_string_builder = new StringBuilder();
|
this.inst_string_builder = new StringBuilder();
|
||||||
this.TextWriter = new StringWriter(this.inst_string_builder);
|
this.writer = new StringWriter(this.inst_string_builder);
|
||||||
this.Init();
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonWriter(StringBuilder sb) : this(new StringWriter(sb)) { }
|
public JsonWriter(StringBuilder sb) :
|
||||||
|
this(new StringWriter(sb)) {
|
||||||
|
}
|
||||||
|
|
||||||
public JsonWriter(TextWriter writer) {
|
public JsonWriter(TextWriter writer) {
|
||||||
this.TextWriter = writer ?? throw new ArgumentNullException("writer");
|
this.writer = writer ?? throw new ArgumentNullException("writer");
|
||||||
this.Init();
|
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
private void DoValidation(Condition cond) {
|
private void DoValidation(Condition cond) {
|
||||||
if (!this.context.ExpectingValue) {
|
if (!this.context.ExpectingValue) {
|
||||||
this.context.Count++;
|
this.context.Count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.Validate) {
|
if (!this.validate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.has_reached_end) {
|
if (this.has_reached_end) {
|
||||||
throw new JsonException("A complete JSON symbol has already been written");
|
throw new JsonException(
|
||||||
|
"A complete JSON symbol has already been written");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cond) {
|
switch (cond) {
|
||||||
case Condition.InArray:
|
case Condition.InArray:
|
||||||
if (!this.context.InArray) {
|
if (!this.context.InArray) {
|
||||||
throw new JsonException("Can't close an array here");
|
throw new JsonException(
|
||||||
|
"Can't close an array here");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Condition.InObject:
|
case Condition.InObject:
|
||||||
if (!this.context.InObject || this.context.ExpectingValue) {
|
if (!this.context.InObject || this.context.ExpectingValue) {
|
||||||
throw new JsonException("Can't close an object here");
|
throw new JsonException(
|
||||||
|
"Can't close an object here");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Condition.NotAProperty:
|
case Condition.NotAProperty:
|
||||||
if (this.context.InObject && !this.context.ExpectingValue) {
|
if (this.context.InObject && !this.context.ExpectingValue) {
|
||||||
throw new JsonException("Expected a property");
|
throw new JsonException(
|
||||||
|
"Expected a property");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Condition.Property:
|
case Condition.Property:
|
||||||
if (!this.context.InObject || this.context.ExpectingValue) {
|
if (!this.context.InObject || this.context.ExpectingValue) {
|
||||||
throw new JsonException("Can't add a property here");
|
throw new JsonException(
|
||||||
|
"Can't add a property here");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Condition.Value:
|
case Condition.Value:
|
||||||
if (!this.context.InArray && (!this.context.InObject || !this.context.ExpectingValue)) {
|
if (!this.context.InArray &&
|
||||||
throw new JsonException("Can't add a value here");
|
(!this.context.InObject || !this.context.ExpectingValue)) {
|
||||||
|
throw new JsonException(
|
||||||
|
"Can't add a value here");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -139,9 +172,9 @@ namespace LitJson
|
|||||||
this.hex_seq = new Char[4];
|
this.hex_seq = new Char[4];
|
||||||
this.indentation = 0;
|
this.indentation = 0;
|
||||||
this.indent_value = 4;
|
this.indent_value = 4;
|
||||||
this.PrettyPrint = false;
|
this.pretty_print = false;
|
||||||
this.Validate = true;
|
this.validate = true;
|
||||||
this.LowerCaseProperties = false;
|
this.lower_case_properties = false;
|
||||||
|
|
||||||
this.ctx_stack = new Stack<WriterContext>();
|
this.ctx_stack = new Stack<WriterContext>();
|
||||||
this.context = new WriterContext();
|
this.context = new WriterContext();
|
||||||
@ -150,96 +183,114 @@ namespace LitJson
|
|||||||
|
|
||||||
private static void IntToHex(Int32 n, Char[] hex) {
|
private static void IntToHex(Int32 n, Char[] hex) {
|
||||||
Int32 num;
|
Int32 num;
|
||||||
|
|
||||||
for (Int32 i = 0; i < 4; i++) {
|
for (Int32 i = 0; i < 4; i++) {
|
||||||
num = n % 16;
|
num = n % 16;
|
||||||
hex[3 - i] = num < 10 ? (Char)('0' + num) : (Char)('A' + (num - 10));
|
|
||||||
|
if (num < 10) {
|
||||||
|
hex[3 - i] = (Char)('0' + num);
|
||||||
|
} else {
|
||||||
|
hex[3 - i] = (Char)('A' + (num - 10));
|
||||||
|
}
|
||||||
|
|
||||||
n >>= 4;
|
n >>= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Indent() {
|
private void Indent() {
|
||||||
if (this.PrettyPrint) {
|
if (this.pretty_print) {
|
||||||
this.indentation += this.indent_value;
|
this.indentation += this.indent_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Put(String str) {
|
private void Put(String str) {
|
||||||
if (this.PrettyPrint && !this.context.ExpectingValue) {
|
if (this.pretty_print && !this.context.ExpectingValue) {
|
||||||
for (Int32 i = 0; i < this.indentation; i++) {
|
for (Int32 i = 0; i < this.indentation; i++) {
|
||||||
this.TextWriter.Write(' ');
|
this.writer.Write(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.TextWriter.Write(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PutNewline() => this.PutNewline(true);
|
this.writer.Write(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PutNewline() {
|
||||||
|
PutNewline(true);
|
||||||
|
}
|
||||||
|
|
||||||
private void PutNewline(Boolean add_comma) {
|
private void PutNewline(Boolean add_comma) {
|
||||||
if (add_comma && !this.context.ExpectingValue && this.context.Count > 1) {
|
if (add_comma && !this.context.ExpectingValue &&
|
||||||
this.TextWriter.Write(',');
|
this.context.Count > 1) {
|
||||||
|
this.writer.Write(',');
|
||||||
}
|
}
|
||||||
if (this.PrettyPrint && !this.context.ExpectingValue) {
|
|
||||||
this.TextWriter.Write(Environment.NewLine);
|
if (this.pretty_print && !this.context.ExpectingValue) {
|
||||||
|
this.writer.Write(Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PutString(String str) {
|
private void PutString(String str) {
|
||||||
this.Put(String.Empty);
|
Put(String.Empty);
|
||||||
|
|
||||||
this.TextWriter.Write('"');
|
this.writer.Write('"');
|
||||||
|
|
||||||
Int32 n = str.Length;
|
Int32 n = str.Length;
|
||||||
for (Int32 i = 0; i < n; i++) {
|
for (Int32 i = 0; i < n; i++) {
|
||||||
switch (str[i]) {
|
switch (str[i]) {
|
||||||
case '\n':
|
case '\n':
|
||||||
this.TextWriter.Write("\\n");
|
this.writer.Write("\\n");
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '\r':
|
case '\r':
|
||||||
this.TextWriter.Write("\\r");
|
this.writer.Write("\\r");
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '\t':
|
case '\t':
|
||||||
this.TextWriter.Write("\\t");
|
this.writer.Write("\\t");
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
case '\\':
|
case '\\':
|
||||||
this.TextWriter.Write('\\');
|
this.writer.Write('\\');
|
||||||
this.TextWriter.Write(str[i]);
|
this.writer.Write(str[i]);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '\f':
|
case '\f':
|
||||||
this.TextWriter.Write("\\f");
|
this.writer.Write("\\f");
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case '\b':
|
case '\b':
|
||||||
this.TextWriter.Write("\\b");
|
this.writer.Write("\\b");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[i] >= 32 && str[i] <= 126) {
|
if (str[i] >= 32 && str[i] <= 126) {
|
||||||
this.TextWriter.Write(str[i]);
|
this.writer.Write(str[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default, turn into a \uXXXX sequence
|
// Default, turn into a \uXXXX sequence
|
||||||
IntToHex(str[i], this.hex_seq);
|
IntToHex(str[i], this.hex_seq);
|
||||||
this.TextWriter.Write("\\u");
|
this.writer.Write("\\u");
|
||||||
this.TextWriter.Write(this.hex_seq);
|
this.writer.Write(this.hex_seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.TextWriter.Write('"');
|
this.writer.Write('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Unindent() {
|
private void Unindent() {
|
||||||
if (this.PrettyPrint) {
|
if (this.pretty_print) {
|
||||||
this.indentation -= this.indent_value;
|
this.indentation -= this.indent_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public override String ToString() => this.inst_string_builder == null ? String.Empty : this.inst_string_builder.ToString();
|
|
||||||
|
public override String ToString() {
|
||||||
|
if (this.inst_string_builder == null) {
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
return this.inst_string_builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
this.has_reached_end = false;
|
this.has_reached_end = false;
|
||||||
@ -249,100 +300,88 @@ namespace LitJson
|
|||||||
this.ctx_stack.Push(this.context);
|
this.ctx_stack.Push(this.context);
|
||||||
|
|
||||||
if (this.inst_string_builder != null) {
|
if (this.inst_string_builder != null) {
|
||||||
_ = this.inst_string_builder.Remove(0, this.inst_string_builder.Length);
|
this.inst_string_builder.Remove(0, this.inst_string_builder.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(Boolean boolean) {
|
public void Write(Boolean boolean) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put(boolean ? "true" : "false");
|
Put(boolean ? "true" : "false");
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(Decimal number) {
|
public void Write(Decimal number) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put(Convert.ToString(number, number_format));
|
Put(Convert.ToString(number, number_format));
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(Double number) {
|
public void Write(Double number) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
String str = Convert.ToString(number, number_format);
|
String str = Convert.ToString(number, number_format);
|
||||||
this.Put(str);
|
Put(str);
|
||||||
|
|
||||||
if (str.IndexOf('.') == -1 && str.IndexOf('E') == -1) {
|
if (str.IndexOf('.') == -1 && str.IndexOf('E') == -1) {
|
||||||
this.TextWriter.Write(".0");
|
this.writer.Write(".0");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(Int32 number) {
|
public void Write(Int32 number) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put(Convert.ToString(number, number_format));
|
Put(Convert.ToString(number, number_format));
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(Int64 number) {
|
public void Write(Int64 number) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put(Convert.ToString(number, number_format));
|
Put(Convert.ToString(number, number_format));
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(String str) {
|
public void Write(String str) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
this.Put("null");
|
Put("null");
|
||||||
} else {
|
} else {
|
||||||
this.PutString(str);
|
PutString(str);
|
||||||
}
|
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteJson(String str) {
|
|
||||||
this.DoValidation(Condition.Value);
|
|
||||||
this.PutNewline();
|
|
||||||
|
|
||||||
if(str == null) {
|
|
||||||
this.Put("null");
|
|
||||||
} else {
|
|
||||||
this.TextWriter.Write(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [CLSCompliant(false)]
|
||||||
public void Write(UInt64 number) {
|
public void Write(UInt64 number) {
|
||||||
this.DoValidation(Condition.Value);
|
DoValidation(Condition.Value);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put(Convert.ToString(number, number_format));
|
Put(Convert.ToString(number, number_format));
|
||||||
|
|
||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteArrayEnd() {
|
public void WriteArrayEnd() {
|
||||||
this.DoValidation(Condition.InArray);
|
DoValidation(Condition.InArray);
|
||||||
this.PutNewline(false);
|
PutNewline(false);
|
||||||
|
|
||||||
_ = this.ctx_stack.Pop();
|
this.ctx_stack.Pop();
|
||||||
if (this.ctx_stack.Count == 1) {
|
if (this.ctx_stack.Count == 1) {
|
||||||
this.has_reached_end = true;
|
this.has_reached_end = true;
|
||||||
} else {
|
} else {
|
||||||
@ -350,29 +389,29 @@ namespace LitJson
|
|||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Unindent();
|
Unindent();
|
||||||
this.Put("]");
|
Put("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteArrayStart() {
|
public void WriteArrayStart() {
|
||||||
this.DoValidation(Condition.NotAProperty);
|
DoValidation(Condition.NotAProperty);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put("[");
|
Put("[");
|
||||||
|
|
||||||
this.context = new WriterContext {
|
this.context = new WriterContext {
|
||||||
InArray = true
|
InArray = true
|
||||||
};
|
};
|
||||||
this.ctx_stack.Push(this.context);
|
this.ctx_stack.Push(this.context);
|
||||||
|
|
||||||
this.Indent();
|
Indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteObjectEnd() {
|
public void WriteObjectEnd() {
|
||||||
this.DoValidation(Condition.InObject);
|
DoValidation(Condition.InObject);
|
||||||
this.PutNewline(false);
|
PutNewline(false);
|
||||||
|
|
||||||
_ = this.ctx_stack.Pop();
|
this.ctx_stack.Pop();
|
||||||
if (this.ctx_stack.Count == 1) {
|
if (this.ctx_stack.Count == 1) {
|
||||||
this.has_reached_end = true;
|
this.has_reached_end = true;
|
||||||
} else {
|
} else {
|
||||||
@ -380,44 +419,44 @@ namespace LitJson
|
|||||||
this.context.ExpectingValue = false;
|
this.context.ExpectingValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Unindent();
|
Unindent();
|
||||||
this.Put("}");
|
Put("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteObjectStart() {
|
public void WriteObjectStart() {
|
||||||
this.DoValidation(Condition.NotAProperty);
|
DoValidation(Condition.NotAProperty);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
|
|
||||||
this.Put("{");
|
Put("{");
|
||||||
|
|
||||||
this.context = new WriterContext {
|
this.context = new WriterContext {
|
||||||
InObject = true
|
InObject = true
|
||||||
};
|
};
|
||||||
this.ctx_stack.Push(this.context);
|
this.ctx_stack.Push(this.context);
|
||||||
|
|
||||||
this.Indent();
|
Indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WritePropertyName(String property_name) {
|
public void WritePropertyName(String property_name) {
|
||||||
this.DoValidation(Condition.Property);
|
DoValidation(Condition.Property);
|
||||||
this.PutNewline();
|
PutNewline();
|
||||||
String propertyName = (property_name == null || !this.LowerCaseProperties) ? property_name : property_name.ToLowerInvariant();
|
String propertyName = (property_name == null || !this.lower_case_properties) ? property_name : property_name.ToLowerInvariant();
|
||||||
|
|
||||||
this.PutString(propertyName);
|
PutString(propertyName);
|
||||||
|
|
||||||
if (this.PrettyPrint) {
|
if (this.pretty_print) {
|
||||||
if (propertyName.Length > this.context.Padding) {
|
if (propertyName.Length > this.context.Padding) {
|
||||||
this.context.Padding = propertyName.Length;
|
this.context.Padding = propertyName.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Int32 i = this.context.Padding - propertyName.Length;
|
for (Int32 i = this.context.Padding - propertyName.Length;
|
||||||
i >= 0; i--) {
|
i >= 0; i--) {
|
||||||
this.TextWriter.Write(' ');
|
this.writer.Write(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.TextWriter.Write(": ");
|
this.writer.Write(": ");
|
||||||
} else {
|
} else {
|
||||||
this.TextWriter.Write(':');
|
this.writer.Write(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.ExpectingValue = true;
|
this.context.ExpectingValue = true;
|
||||||
|
505
litjson/Lexer.cs
505
litjson/Lexer.cs
@ -10,67 +10,97 @@
|
|||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
internal class FsmContext {
|
{
|
||||||
public Boolean Return;
|
internal class FsmContext
|
||||||
public Int32 NextState;
|
{
|
||||||
|
public bool Return;
|
||||||
|
public int NextState;
|
||||||
public Lexer L;
|
public Lexer L;
|
||||||
public Int32 StateStack;
|
public int StateStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Lexer {
|
|
||||||
#region Fields
|
|
||||||
private delegate Boolean StateHandler(FsmContext ctx);
|
|
||||||
|
|
||||||
private static readonly Int32[] fsm_return_table;
|
internal class Lexer
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private delegate bool StateHandler (FsmContext ctx);
|
||||||
|
|
||||||
|
private static readonly int[] fsm_return_table;
|
||||||
private static readonly StateHandler[] fsm_handler_table;
|
private static readonly StateHandler[] fsm_handler_table;
|
||||||
private readonly FsmContext fsm_context;
|
|
||||||
private Int32 input_buffer;
|
private bool allow_comments;
|
||||||
private Int32 input_char;
|
private bool allow_single_quoted_strings;
|
||||||
private readonly TextReader reader;
|
private bool end_of_input;
|
||||||
private Int32 state;
|
private FsmContext fsm_context;
|
||||||
private readonly StringBuilder string_buffer;
|
private int input_buffer;
|
||||||
private Int32 unichar;
|
private int input_char;
|
||||||
|
private TextReader reader;
|
||||||
|
private int state;
|
||||||
|
private StringBuilder string_buffer;
|
||||||
|
private string string_value;
|
||||||
|
private int token;
|
||||||
|
private int unichar;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public Boolean AllowComments { get; set; }
|
public bool AllowComments {
|
||||||
|
get { return allow_comments; }
|
||||||
|
set { allow_comments = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean AllowSingleQuotedStrings { get; set; }
|
public bool AllowSingleQuotedStrings {
|
||||||
|
get { return allow_single_quoted_strings; }
|
||||||
|
set { allow_single_quoted_strings = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean EndOfInput { get; private set; }
|
public bool EndOfInput {
|
||||||
|
get { return end_of_input; }
|
||||||
|
}
|
||||||
|
|
||||||
public Int32 Token { get; private set; }
|
public int Token {
|
||||||
|
get { return token; }
|
||||||
|
}
|
||||||
|
|
||||||
public String StringValue { get; private set; }
|
public string StringValue {
|
||||||
#endregion
|
get { return string_value; }
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
static Lexer() => PopulateFsmTables(out fsm_handler_table, out fsm_return_table);
|
|
||||||
|
|
||||||
public Lexer(TextReader reader) {
|
|
||||||
this.AllowComments = true;
|
|
||||||
this.AllowSingleQuotedStrings = true;
|
|
||||||
|
|
||||||
this.input_buffer = 0;
|
|
||||||
this.string_buffer = new StringBuilder(128);
|
|
||||||
this.state = 1;
|
|
||||||
this.EndOfInput = false;
|
|
||||||
this.reader = reader;
|
|
||||||
|
|
||||||
this.fsm_context = new FsmContext {
|
|
||||||
L = this
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
static Lexer ()
|
||||||
|
{
|
||||||
|
PopulateFsmTables (out fsm_handler_table, out fsm_return_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lexer (TextReader reader)
|
||||||
|
{
|
||||||
|
allow_comments = true;
|
||||||
|
allow_single_quoted_strings = true;
|
||||||
|
|
||||||
|
input_buffer = 0;
|
||||||
|
string_buffer = new StringBuilder (128);
|
||||||
|
state = 1;
|
||||||
|
end_of_input = false;
|
||||||
|
this.reader = reader;
|
||||||
|
|
||||||
|
fsm_context = new FsmContext ();
|
||||||
|
fsm_context.L = this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Static Methods
|
#region Static Methods
|
||||||
private static Int32 HexValue(Int32 digit) {
|
private static int HexValue (int digit)
|
||||||
switch(digit) {
|
{
|
||||||
|
switch (digit) {
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
return 10;
|
return 10;
|
||||||
@ -100,7 +130,8 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PopulateFsmTables(out StateHandler[] fsm_handler_table, out Int32[] fsm_return_table) {
|
private static void PopulateFsmTables (out StateHandler[] fsm_handler_table, out int[] fsm_return_table)
|
||||||
|
{
|
||||||
// See section A.1. of the manual for details of the finite
|
// See section A.1. of the manual for details of the finite
|
||||||
// state machine.
|
// state machine.
|
||||||
fsm_handler_table = new StateHandler[28] {
|
fsm_handler_table = new StateHandler[28] {
|
||||||
@ -134,31 +165,31 @@ namespace LitJson {
|
|||||||
State28
|
State28
|
||||||
};
|
};
|
||||||
|
|
||||||
fsm_return_table = new Int32[28] {
|
fsm_return_table = new int[28] {
|
||||||
(Int32) ParserToken.Char,
|
(int) ParserToken.Char,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.Number,
|
(int) ParserToken.Number,
|
||||||
(Int32) ParserToken.Number,
|
(int) ParserToken.Number,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.Number,
|
(int) ParserToken.Number,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.Number,
|
(int) ParserToken.Number,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.True,
|
(int) ParserToken.True,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.False,
|
(int) ParserToken.False,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.Null,
|
(int) ParserToken.Null,
|
||||||
(Int32) ParserToken.CharSeq,
|
(int) ParserToken.CharSeq,
|
||||||
(Int32) ParserToken.Char,
|
(int) ParserToken.Char,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(Int32) ParserToken.CharSeq,
|
(int) ParserToken.CharSeq,
|
||||||
(Int32) ParserToken.Char,
|
(int) ParserToken.Char,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -166,13 +197,14 @@ namespace LitJson {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Char ProcessEscChar(Int32 esc_char) {
|
private static char ProcessEscChar (int esc_char)
|
||||||
switch(esc_char) {
|
{
|
||||||
|
switch (esc_char) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
case '\\':
|
case '\\':
|
||||||
case '/':
|
case '/':
|
||||||
return Convert.ToChar(esc_char);
|
return Convert.ToChar (esc_char);
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
return '\n';
|
return '\n';
|
||||||
@ -195,20 +227,20 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State1(FsmContext ctx) {
|
private static bool State1 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char == ' ' ||
|
while (ctx.L.GetChar ()) {
|
||||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
if (ctx.L.input_char == ' ' ||
|
||||||
|
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r')
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.L.input_char >= '1' && ctx.L.input_char <= '9') {
|
if (ctx.L.input_char >= '1' && ctx.L.input_char <= '9') {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 3;
|
ctx.NextState = 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '"':
|
case '"':
|
||||||
ctx.NextState = 19;
|
ctx.NextState = 19;
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
@ -225,12 +257,12 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 2;
|
ctx.NextState = 2;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '0':
|
case '0':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 4;
|
ctx.NextState = 4;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -247,9 +279,8 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
if(!ctx.L.AllowSingleQuotedStrings) {
|
if (! ctx.L.allow_single_quoted_strings)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
ctx.L.input_char = '"';
|
ctx.L.input_char = '"';
|
||||||
ctx.NextState = 23;
|
ctx.NextState = 23;
|
||||||
@ -257,9 +288,8 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '/':
|
case '/':
|
||||||
if(!ctx.L.AllowComments) {
|
if (! ctx.L.allow_comments)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
ctx.NextState = 25;
|
ctx.NextState = 25;
|
||||||
return true;
|
return true;
|
||||||
@ -272,18 +302,19 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State2(FsmContext ctx) {
|
private static bool State2 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
if(ctx.L.input_char >= '1' && ctx.L.input_char <= '9') {
|
if (ctx.L.input_char >= '1' && ctx.L.input_char<= '9') {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 3;
|
ctx.NextState = 3;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '0':
|
case '0':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 4;
|
ctx.NextState = 4;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -292,37 +323,38 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State3(FsmContext ctx) {
|
private static bool State3 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
while (ctx.L.GetChar ()) {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
||||||
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx.L.input_char == ' ' ||
|
if (ctx.L.input_char == ' ' ||
|
||||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case ',':
|
case ',':
|
||||||
case ']':
|
case ']':
|
||||||
case '}':
|
case '}':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 5;
|
ctx.NextState = 5;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 7;
|
ctx.NextState = 7;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -333,33 +365,34 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State4(FsmContext ctx) {
|
private static bool State4 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
if(ctx.L.input_char == ' ' ||
|
if (ctx.L.input_char == ' ' ||
|
||||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case ',':
|
case ',':
|
||||||
case ']':
|
case ']':
|
||||||
case '}':
|
case '}':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 5;
|
ctx.NextState = 5;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 7;
|
ctx.NextState = 7;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -368,11 +401,12 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State5(FsmContext ctx) {
|
private static bool State5 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 6;
|
ctx.NextState = 6;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -380,32 +414,33 @@ namespace LitJson {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State6(FsmContext ctx) {
|
private static bool State6 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
while (ctx.L.GetChar ()) {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
||||||
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx.L.input_char == ' ' ||
|
if (ctx.L.input_char == ' ' ||
|
||||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case ',':
|
case ',':
|
||||||
case ']':
|
case ']':
|
||||||
case '}':
|
case '}':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 7;
|
ctx.NextState = 7;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -417,19 +452,20 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State7(FsmContext ctx) {
|
private static bool State7 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
if (ctx.L.input_char >= '0' && ctx.L.input_char<= '9') {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 8;
|
ctx.NextState = 8;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '+':
|
case '+':
|
||||||
case '-':
|
case '-':
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
ctx.NextState = 8;
|
ctx.NextState = 8;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -438,25 +474,26 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State8(FsmContext ctx) {
|
private static bool State8 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9') {
|
while (ctx.L.GetChar ()) {
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
if (ctx.L.input_char >= '0' && ctx.L.input_char<= '9') {
|
||||||
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx.L.input_char == ' ' ||
|
if (ctx.L.input_char == ' ' ||
|
||||||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
|
ctx.L.input_char >= '\t' && ctx.L.input_char<= '\r') {
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case ',':
|
case ',':
|
||||||
case ']':
|
case ']':
|
||||||
case '}':
|
case '}':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
@ -469,10 +506,11 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State9(FsmContext ctx) {
|
private static bool State9 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'r':
|
case 'r':
|
||||||
ctx.NextState = 10;
|
ctx.NextState = 10;
|
||||||
return true;
|
return true;
|
||||||
@ -482,10 +520,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State10(FsmContext ctx) {
|
private static bool State10 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'u':
|
case 'u':
|
||||||
ctx.NextState = 11;
|
ctx.NextState = 11;
|
||||||
return true;
|
return true;
|
||||||
@ -495,10 +534,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State11(FsmContext ctx) {
|
private static bool State11 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'e':
|
case 'e':
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
@ -509,10 +549,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State12(FsmContext ctx) {
|
private static bool State12 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'a':
|
case 'a':
|
||||||
ctx.NextState = 13;
|
ctx.NextState = 13;
|
||||||
return true;
|
return true;
|
||||||
@ -522,10 +563,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State13(FsmContext ctx) {
|
private static bool State13 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'l':
|
case 'l':
|
||||||
ctx.NextState = 14;
|
ctx.NextState = 14;
|
||||||
return true;
|
return true;
|
||||||
@ -535,10 +577,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State14(FsmContext ctx) {
|
private static bool State14 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 's':
|
case 's':
|
||||||
ctx.NextState = 15;
|
ctx.NextState = 15;
|
||||||
return true;
|
return true;
|
||||||
@ -548,10 +591,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State15(FsmContext ctx) {
|
private static bool State15 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'e':
|
case 'e':
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
@ -562,10 +606,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State16(FsmContext ctx) {
|
private static bool State16 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'u':
|
case 'u':
|
||||||
ctx.NextState = 17;
|
ctx.NextState = 17;
|
||||||
return true;
|
return true;
|
||||||
@ -575,10 +620,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State17(FsmContext ctx) {
|
private static bool State17 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'l':
|
case 'l':
|
||||||
ctx.NextState = 18;
|
ctx.NextState = 18;
|
||||||
return true;
|
return true;
|
||||||
@ -588,10 +634,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State18(FsmContext ctx) {
|
private static bool State18 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'l':
|
case 'l':
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
@ -602,11 +649,12 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State19(FsmContext ctx) {
|
private static bool State19 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
switch(ctx.L.input_char) {
|
while (ctx.L.GetChar ()) {
|
||||||
|
switch (ctx.L.input_char) {
|
||||||
case '"':
|
case '"':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 20;
|
ctx.NextState = 20;
|
||||||
return true;
|
return true;
|
||||||
@ -617,7 +665,7 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -625,10 +673,11 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State20(FsmContext ctx) {
|
private static bool State20 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '"':
|
case '"':
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
@ -639,10 +688,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State21(FsmContext ctx) {
|
private static bool State21 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case 'u':
|
case 'u':
|
||||||
ctx.NextState = 22;
|
ctx.NextState = 22;
|
||||||
return true;
|
return true;
|
||||||
@ -656,8 +706,8 @@ namespace LitJson {
|
|||||||
case 'n':
|
case 'n':
|
||||||
case 'r':
|
case 'r':
|
||||||
case 't':
|
case 't':
|
||||||
_ = ctx.L.string_buffer.Append(
|
ctx.L.string_buffer.Append (
|
||||||
ProcessEscChar(ctx.L.input_char));
|
ProcessEscChar (ctx.L.input_char));
|
||||||
ctx.NextState = ctx.StateStack;
|
ctx.NextState = ctx.StateStack;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -666,26 +716,27 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State22(FsmContext ctx) {
|
private static bool State22 (FsmContext ctx)
|
||||||
Int32 counter = 0;
|
{
|
||||||
Int32 mult = 4096;
|
int counter = 0;
|
||||||
|
int mult = 4096;
|
||||||
|
|
||||||
ctx.L.unichar = 0;
|
ctx.L.unichar = 0;
|
||||||
|
|
||||||
while(ctx.L.GetChar()) {
|
while (ctx.L.GetChar ()) {
|
||||||
|
|
||||||
if(ctx.L.input_char >= '0' && ctx.L.input_char <= '9' ||
|
if (ctx.L.input_char >= '0' && ctx.L.input_char <= '9' ||
|
||||||
ctx.L.input_char >= 'A' && ctx.L.input_char <= 'F' ||
|
ctx.L.input_char >= 'A' && ctx.L.input_char <= 'F' ||
|
||||||
ctx.L.input_char >= 'a' && ctx.L.input_char <= 'f') {
|
ctx.L.input_char >= 'a' && ctx.L.input_char <= 'f') {
|
||||||
|
|
||||||
ctx.L.unichar += HexValue(ctx.L.input_char) * mult;
|
ctx.L.unichar += HexValue (ctx.L.input_char) * mult;
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
mult /= 16;
|
mult /= 16;
|
||||||
|
|
||||||
if(counter == 4) {
|
if (counter == 4) {
|
||||||
_ = ctx.L.string_buffer.Append(
|
ctx.L.string_buffer.Append (
|
||||||
Convert.ToChar(ctx.L.unichar));
|
Convert.ToChar (ctx.L.unichar));
|
||||||
ctx.NextState = ctx.StateStack;
|
ctx.NextState = ctx.StateStack;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -699,11 +750,12 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State23(FsmContext ctx) {
|
private static bool State23 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
switch(ctx.L.input_char) {
|
while (ctx.L.GetChar ()) {
|
||||||
|
switch (ctx.L.input_char) {
|
||||||
case '\'':
|
case '\'':
|
||||||
ctx.L.UngetChar();
|
ctx.L.UngetChar ();
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
ctx.NextState = 24;
|
ctx.NextState = 24;
|
||||||
return true;
|
return true;
|
||||||
@ -714,7 +766,7 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
|
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -722,10 +774,11 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State24(FsmContext ctx) {
|
private static bool State24 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '\'':
|
case '\'':
|
||||||
ctx.L.input_char = '"';
|
ctx.L.input_char = '"';
|
||||||
ctx.Return = true;
|
ctx.Return = true;
|
||||||
@ -737,10 +790,11 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State25(FsmContext ctx) {
|
private static bool State25 (FsmContext ctx)
|
||||||
_ = ctx.L.GetChar();
|
{
|
||||||
|
ctx.L.GetChar ();
|
||||||
|
|
||||||
switch(ctx.L.input_char) {
|
switch (ctx.L.input_char) {
|
||||||
case '*':
|
case '*':
|
||||||
ctx.NextState = 27;
|
ctx.NextState = 27;
|
||||||
return true;
|
return true;
|
||||||
@ -754,9 +808,10 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State26(FsmContext ctx) {
|
private static bool State26 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char == '\n') {
|
while (ctx.L.GetChar ()) {
|
||||||
|
if (ctx.L.input_char == '\n') {
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -765,9 +820,10 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State27(FsmContext ctx) {
|
private static bool State27 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char == '*') {
|
while (ctx.L.GetChar ()) {
|
||||||
|
if (ctx.L.input_char == '*') {
|
||||||
ctx.NextState = 28;
|
ctx.NextState = 28;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -776,13 +832,13 @@ namespace LitJson {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Boolean State28(FsmContext ctx) {
|
private static bool State28 (FsmContext ctx)
|
||||||
while(ctx.L.GetChar()) {
|
{
|
||||||
if(ctx.L.input_char == '*') {
|
while (ctx.L.GetChar ()) {
|
||||||
|
if (ctx.L.input_char == '*')
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.L.input_char == '/') {
|
if (ctx.L.input_char == '/') {
|
||||||
ctx.NextState = 1;
|
ctx.NextState = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -795,59 +851,62 @@ namespace LitJson {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Boolean GetChar() {
|
|
||||||
if((this.input_char = this.NextChar()) != -1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.EndOfInput = true;
|
private bool GetChar ()
|
||||||
|
{
|
||||||
|
if ((input_char = NextChar ()) != -1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
end_of_input = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Int32 NextChar() {
|
private int NextChar ()
|
||||||
if(this.input_buffer != 0) {
|
{
|
||||||
Int32 tmp = this.input_buffer;
|
if (input_buffer != 0) {
|
||||||
this.input_buffer = 0;
|
int tmp = input_buffer;
|
||||||
|
input_buffer = 0;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.reader.Read();
|
return reader.Read ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean NextToken() {
|
public bool NextToken ()
|
||||||
|
{
|
||||||
StateHandler handler;
|
StateHandler handler;
|
||||||
this.fsm_context.Return = false;
|
fsm_context.Return = false;
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
handler = fsm_handler_table[this.state - 1];
|
handler = fsm_handler_table[state - 1];
|
||||||
|
|
||||||
if(!handler(this.fsm_context)) {
|
if (! handler (fsm_context))
|
||||||
throw new JsonException(this.input_char);
|
throw new JsonException (input_char);
|
||||||
}
|
|
||||||
|
|
||||||
if(this.EndOfInput) {
|
if (end_of_input)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if(this.fsm_context.Return) {
|
if (fsm_context.Return) {
|
||||||
this.StringValue = this.string_buffer.ToString();
|
string_value = string_buffer.ToString ();
|
||||||
_ = this.string_buffer.Remove(0, this.string_buffer.Length);
|
string_buffer.Remove (0, string_buffer.Length);
|
||||||
this.Token = fsm_return_table[this.state - 1];
|
token = fsm_return_table[state - 1];
|
||||||
|
|
||||||
if(this.Token == (Int32)ParserToken.Char) {
|
if (token == (int) ParserToken.Char)
|
||||||
this.Token = this.input_char;
|
token = input_char;
|
||||||
}
|
|
||||||
|
|
||||||
this.state = this.fsm_context.NextState;
|
state = fsm_context.NextState;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = this.fsm_context.NextState;
|
state = fsm_context.NextState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UngetChar() => this.input_buffer = this.input_char;
|
private void UngetChar ()
|
||||||
|
{
|
||||||
|
input_buffer = input_char;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
namespace LitJson {
|
namespace LitJson
|
||||||
internal enum ParserToken {
|
{
|
||||||
|
internal enum ParserToken
|
||||||
|
{
|
||||||
// Lexer tokens (see section A.1.1. of the manual)
|
// Lexer tokens (see section A.1.1. of the manual)
|
||||||
None = System.Char.MaxValue + 1,
|
None = System.Char.MaxValue + 1,
|
||||||
Number,
|
Number,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#if !NETCOREAPP
|
using System.Reflection;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
@ -35,4 +34,3 @@ using System.Runtime.InteropServices;
|
|||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.12.0")]
|
[assembly: AssemblyVersion("0.12.0")]
|
||||||
[assembly: AssemblyFileVersion("0.12.0")]
|
[assembly: AssemblyFileVersion("0.12.0")]
|
||||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
<AssemblyName>LitJson</AssemblyName>
|
|
||||||
<RootNamespace>litjson</RootNamespace>
|
|
||||||
<PackageId>LitJson</PackageId>
|
|
||||||
<Product>LitJSON</Product>
|
|
||||||
<Description>LitJSON library</Description>
|
|
||||||
<Company />
|
|
||||||
<Authors />
|
|
||||||
<Version>0.12.0</Version>
|
|
||||||
<AssemblyVersion>0.12.0</AssemblyVersion>
|
|
||||||
<FileVersion>0.12.0</FileVersion>
|
|
||||||
<PackageLicenseFile>COPYING</PackageLicenseFile>
|
|
||||||
<Copyright>The authors disclaim copyright to this source code</Copyright>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="../COPYING" />
|
|
||||||
<Content Include="../README.md" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="..\COPYING">
|
|
||||||
<Pack>True</Pack>
|
|
||||||
<PackagePath></PackagePath>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -21,7 +21,6 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<LangVersion>7.1</LangVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
@ -30,7 +29,6 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<LangVersion>7.1</LangVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@ -55,9 +53,5 @@
|
|||||||
<Compile Include="ParserToken.cs" />
|
<Compile Include="ParserToken.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\COPYING" />
|
|
||||||
<Content Include="..\README.md" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user