Compare commits

...
9 Commits
Author SHA1 Message Date
BlubbFish 63561dc90d move to net10 2026-08-03 22:56:10 +02:00
BlubbFish d6b6a365c7 make miror to github.com 2021-08-22 00:32:36 +02:00
BlubbFish 9eb978caea Make netcore as default, also using 3.1 now 2021-01-09 00:19:58 +01:00
BlubbFish 875248bcdc Typo 2019-11-29 14:43:26 +01:00
BlubbFish 420831eb52 Add netcore 2019-11-24 20:43:32 +01:00
BlubbFish cab3ec2d06 Refactoring and fixing a bug when add json text 2019-07-24 17:07:28 +02:00
BlubbFish aae12f70d3 ref, and change project settings 2019-07-24 13:00:06 +02:00
BlubbFish 59b7ead200 and move on 2019-07-23 17:15:23 +02:00
BlubbFish 81b0cb3990 make it nice 2019-07-23 14:04:06 +02:00
16 changed files with 2437 additions and 2846 deletions
+2
View File
@@ -1,2 +1,4 @@
# 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).
+25
View File
@@ -0,0 +1,25 @@
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
+8 -8
View File
@@ -1,9 +1,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2010
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson", "litjson\litjson.csproj", "{244B45C3-E7A0-428B-8AF2-E992FA9E5964}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -11,15 +11,15 @@ Global
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
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Debug|Any CPU.Build.0 = Debug|Any CPU
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Release|Any CPU.ActiveCfg = Release|Any CPU
{244B45C3-E7A0-428B-8AF2-E992FA9E5964}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AF2398AC-1EAA-4615-B21A-33C68CD44849}
SolutionGuid = {E215FE79-F42D-4A58-B702-EC7E8AAFADFF}
EndGlobalSection
EndGlobal
+22
View File
@@ -0,0 +1,22 @@
// 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.JsonData.#ctor(System.Object)")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.op_Explicit(LitJson.JsonData)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.op_Explicit(LitJson.JsonData)~System.Double")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.op_Explicit(LitJson.JsonData)~System.Int32")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.op_Explicit(LitJson.JsonData)~System.Int64")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.op_Explicit(LitJson.JsonData)~System.String")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.LitJson#IJsonWrapper#GetBoolean~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.LitJson#IJsonWrapper#GetDouble~System.Double")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.LitJson#IJsonWrapper#GetInt~System.Int32")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.LitJson#IJsonWrapper#GetLong~System.Int64")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.LitJson#IJsonWrapper#GetString~System.String")]
[assembly: SuppressMessage("Style", "IDE0046:In bedingten Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.EnsureCollection~System.Collections.ICollection")]
[assembly: SuppressMessage("Style", "IDE0038:Musterabgleich verwenden", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.ToJsonData(System.Object)~LitJson.JsonData")]
[assembly: SuppressMessage("Style", "IDE0066:Switch-Anweisung in Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.Equals(LitJson.JsonData)~System.Boolean")]
[assembly: SuppressMessage("Style", "IDE0066:Switch-Anweisung in Ausdruck konvertieren", Justification = "<Ausstehend>", Scope = "member", Target = "~M:LitJson.JsonData.ToString~System.String")]
+22 -25
View File
@@ -11,16 +11,14 @@
#endregion
using System;
using System.Collections;
using System.Collections.Specialized;
namespace LitJson
{
public enum JsonType
{
namespace LitJson {
public enum JsonType {
None,
Object,
Array,
String,
@@ -30,31 +28,30 @@ namespace LitJson
Boolean
}
public interface IJsonWrapper : IList, IOrderedDictionary
{
bool IsArray { get; }
bool IsBoolean { get; }
bool IsDouble { get; }
bool IsInt { get; }
bool IsLong { get; }
bool IsObject { get; }
bool IsString { get; }
public interface IJsonWrapper : IList, IOrderedDictionary {
Boolean IsArray { get; }
Boolean IsBoolean { get; }
Boolean IsDouble { get; }
Boolean IsInt { get; }
Boolean IsLong { get; }
Boolean IsObject { get; }
Boolean IsString { get; }
bool GetBoolean ();
double GetDouble ();
int GetInt ();
Boolean GetBoolean();
Double GetDouble();
Int32 GetInt();
JsonType GetJsonType();
long GetLong ();
string GetString ();
Int64 GetLong();
String GetString();
void SetBoolean (bool val);
void SetDouble (double val);
void SetInt (int val);
void SetBoolean(Boolean val);
void SetDouble(Double val);
void SetInt(Int32 val);
void SetJsonType(JsonType type);
void SetLong (long val);
void SetString (string val);
void SetLong(Int64 val);
void SetString(String val);
string ToJson ();
String ToJson();
void ToJson(JsonWriter writer);
}
}
+351 -577
View File
File diff suppressed because it is too large Load Diff
+8 -36
View File
@@ -12,8 +12,7 @@
using System;
namespace LitJson
{
namespace LitJson {
public class JsonException :
#if NETSTANDARD1_5
Exception
@@ -21,45 +20,18 @@ namespace LitJson
ApplicationException
#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 (int c) :
base (String.Format (
"Invalid character '{0}' in input string", (char) c))
{
}
internal JsonException(Int32 c) : base(String.Format("Invalid character '{0}' in input string", (Char)c)) { }
internal JsonException (int c, Exception inner_exception) :
base (String.Format (
"Invalid character '{0}' in input string", (char) c),
inner_exception)
{
}
internal JsonException(Int32 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) : base (message)
{
}
public JsonException (string message, Exception inner_exception) :
base (message, inner_exception)
{
}
public JsonException(String message, Exception inner_exception) : base(message, inner_exception) { }
}
}
+29 -88
View File
@@ -28,15 +28,8 @@ namespace LitJson {
private Type element_type;
public Type ElementType {
get {
if (this.element_type == null) {
return typeof(JsonData);
}
return this.element_type;
}
set { this.element_type = value; }
get => this.element_type ?? typeof(JsonData);
set => this.element_type = value;
}
public Boolean IsArray { get; set; }
@@ -48,15 +41,8 @@ namespace LitJson {
private Type element_type;
public Type ElementType {
get {
if (this.element_type == null) {
return typeof(JsonData);
}
return this.element_type;
}
set { this.element_type = value; }
get => this.element_type ?? typeof(JsonData);
set => this.element_type = value;
}
public Boolean IsDictionary { get; set; }
@@ -64,7 +50,6 @@ namespace LitJson {
public IDictionary<String, PropertyMetadata> Properties { get; set; }
}
internal delegate void ExporterFunc(Object obj, JsonWriter writer);
public delegate void ExporterFunc<T>(T obj, JsonWriter writer);
@@ -340,8 +325,9 @@ namespace LitJson {
// Maybe it's an enum
#if NETSTANDARD1_5
if (value_type.IsEnum())
if (value_type.IsEnum()) {
return Enum.ToObject (value_type, reader.Value);
}
#else
if (value_type.IsEnum) {
return Enum.ToObject(value_type, reader.Value);
@@ -450,7 +436,7 @@ namespace LitJson {
}
private static IJsonWrapper ReadValue(WrapperFactory factory, JsonReader reader) {
reader.Read();
_ = reader.Read();
if (reader.Token == JsonToken.ArrayEnd ||
reader.Token == JsonToken.Null) {
@@ -492,13 +478,13 @@ namespace LitJson {
if (item == null && reader.Token == JsonToken.ArrayEnd) {
break;
}
instance.Add(item);
_ = instance.Add(item);
}
} else if (reader.Token == JsonToken.ObjectStart) {
instance.SetJsonType(JsonType.Object);
while (true) {
reader.Read();
_ = reader.Read();
if (reader.Token == JsonToken.ObjectEnd) {
break;
@@ -514,9 +500,7 @@ namespace LitJson {
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() {
base_exporters_table[typeof(Byte)] = delegate (Object obj, JsonWriter writer) {
@@ -643,7 +627,10 @@ namespace LitJson {
if (obj is IJsonWrapper) {
if (writer_is_private) {
writer.TextWriter.Write(((IJsonWrapper)obj).ToJson());
String t = ((IJsonWrapper)obj).ToJson();
writer.WriteJson(t);
//writer.TextWriter.Write(t);
//this.context.ExpectingValue = false;
} else {
((IJsonWrapper)obj).ToJson(writer);
}
@@ -769,7 +756,6 @@ namespace LitJson {
}
#endregion
public static String ToJson(Object obj) {
lock (static_writer_lock) {
static_writer.Reset();
@@ -780,78 +766,33 @@ 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) {
return (JsonData)ToWrapper(delegate { return new JsonData(); }, reader);
}
public static JsonData ToObject(JsonReader reader) => (JsonData)ToWrapper(delegate { return new JsonData(); }, reader);
public static JsonData ToObject(TextReader reader) {
JsonReader json_reader = new JsonReader(reader);
public static JsonData ToObject(TextReader reader) => (JsonData)ToWrapper(delegate { return new JsonData(); }, new JsonReader(reader));
return (JsonData)ToWrapper(delegate { return new JsonData(); }, json_reader);
}
public static JsonData ToObject(String json) => (JsonData)ToWrapper(delegate { return new JsonData(); }, json);
public static JsonData ToObject(String json) {
return (JsonData)ToWrapper(delegate { return new JsonData(); }, json);
}
public static T ToObject<T>(JsonReader reader) => (T)ReadValue(typeof(T), reader);
public static T ToObject<T>(JsonReader reader) {
return (T)ReadValue(typeof(T), reader);
}
public static T ToObject<T>(TextReader reader) => (T)ReadValue(typeof(T), new JsonReader(reader));
public static T ToObject<T>(TextReader reader) {
JsonReader json_reader = new JsonReader(reader);
public static T ToObject<T>(String json) => (T)ReadValue(typeof(T), new JsonReader(json));
return (T)ReadValue(typeof(T), json_reader);
}
public static Object ToObject(String json, Type ConvertType) => ReadValue(ConvertType, new JsonReader(json));
public static T ToObject<T>(String json) {
JsonReader reader = new JsonReader(json);
public static IJsonWrapper ToWrapper(WrapperFactory factory, JsonReader reader) => ReadValue(factory, reader);
return (T)ReadValue(typeof(T), reader);
}
public static IJsonWrapper ToWrapper(WrapperFactory factory, String json) => ReadValue(factory, new JsonReader(json));
public static Object ToObject(String json, Type ConvertType) {
JsonReader reader = new JsonReader(json);
public static void RegisterExporter<T>(ExporterFunc<T> exporter) => custom_exporters_table[typeof(T)] = (Object obj, JsonWriter writer) => exporter((T)obj, writer);
return ReadValue(ConvertType, reader);
}
public static void RegisterImporter<TJson, TValue>(ImporterFunc<TJson, TValue> importer) => RegisterImporter(custom_importers_table, typeof(TJson), typeof(TValue), (Object input) => importer((TJson)input));
public static IJsonWrapper ToWrapper(WrapperFactory factory, JsonReader reader) {
return ReadValue(factory, reader);
}
public static void UnregisterExporters() => custom_exporters_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();
}
public static void UnregisterImporters() => custom_importers_table.Clear();
public static Object ToObject() => throw new NotImplementedException();
}
}
+86 -59
View File
@@ -15,91 +15,118 @@ using System.Collections;
using System.Collections.Specialized;
namespace LitJson
{
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; } }
namespace LitJson {
public class JsonMockWrapper : IJsonWrapper {
public Boolean IsArray => 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 IsBoolean => false;
public Boolean IsDouble => false;
public Boolean IsInt => false;
public Boolean IsLong => false;
public Boolean IsObject => false;
public Boolean IsString => false;
public Boolean GetBoolean() => false;
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 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 string ToJson () { return ""; }
public void SetLong(Int64 val) { }
public void SetString(String val) { }
public String ToJson() => "";
public void ToJson(JsonWriter writer) { }
Boolean IList.IsFixedSize => true;
bool IList.IsFixedSize { get { return true; } }
bool IList.IsReadOnly { get { return true; } }
Boolean IList.IsReadOnly => true;
object IList.this[int index] {
get { return null; }
set {}
Object IList.this[Int32 index] {
get => null;
set {
}
}
int IList.Add (object value) { return 0; }
Int32 IList.Add(Object value) => 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) {}
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; }
set {}
void ICollection.CopyTo(Array array, Int32 index) { }
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) {}
IDictionaryEnumerator IDictionary.GetEnumerator () { return null; }
Boolean IDictionary.Contains(Object key) => false;
void IDictionary.Remove(Object key) { }
object IOrderedDictionary.this[int idx] {
get { return null; }
set {}
}
IDictionaryEnumerator IDictionary.GetEnumerator() => null;
IDictionaryEnumerator IOrderedDictionary.GetEnumerator () {
return null;
}
void IOrderedDictionary.Insert (int i, object k, object v) {}
void IOrderedDictionary.RemoveAt (int i) {}
Object IOrderedDictionary.this[Int32 idx] {
get => null;
set {
}
}
IDictionaryEnumerator IOrderedDictionary.GetEnumerator() => null;
void IOrderedDictionary.Insert(Int32 i, Object k, Object v) { }
void IOrderedDictionary.RemoveAt(Int32 i) { }
}
}
+227 -337
View File
@@ -16,440 +16,328 @@ using System.IO;
using System.Text;
namespace LitJson
{
public enum JsonToken
{
namespace LitJson {
public enum JsonToken {
None,
ObjectStart,
PropertyName,
ObjectEnd,
ArrayStart,
ArrayEnd,
Int,
Long,
Double,
String,
Boolean,
Null
}
public class JsonReader
{
public class JsonReader {
#region Fields
private static readonly IDictionary<int, IDictionary<int, int[]>> parse_table;
private static readonly IDictionary<Int32, IDictionary<Int32, Int32[]>> parse_table;
private Stack<int> automaton_stack;
private int current_input;
private int current_symbol;
private bool end_of_json;
private bool end_of_input;
private Lexer lexer;
private bool parser_in_string;
private bool parser_return;
private bool read_started;
private readonly Stack<Int32> automaton_stack;
private Int32 current_input;
private Int32 current_symbol;
private readonly Lexer lexer;
private Boolean parser_in_string;
private Boolean parser_return;
private Boolean read_started;
private TextReader reader;
private bool reader_is_owned;
private bool skip_non_members;
private object token_value;
private JsonToken token;
private readonly Boolean reader_is_owned;
#endregion
#region Public Properties
public bool AllowComments {
get { return lexer.AllowComments; }
set { lexer.AllowComments = value; }
public Boolean AllowComments {
get => this.lexer.AllowComments;
set => this.lexer.AllowComments = value;
}
public bool AllowSingleQuotedStrings {
get { return lexer.AllowSingleQuotedStrings; }
set { lexer.AllowSingleQuotedStrings = value; }
public Boolean AllowSingleQuotedStrings {
get => this.lexer.AllowSingleQuotedStrings;
set => this.lexer.AllowSingleQuotedStrings = value;
}
public bool SkipNonMembers {
get { return skip_non_members; }
set { skip_non_members = value; }
}
public Boolean SkipNonMembers { get; set; }
public bool EndOfInput {
get { return end_of_input; }
}
public Boolean EndOfInput { get; private set; }
public bool EndOfJson {
get { return end_of_json; }
}
public Boolean EndOfJson { get; private set; }
public JsonToken Token {
get { return token; }
}
public JsonToken Token { get; private set; }
public object Value {
get { return token_value; }
}
public Object Value { get; private set; }
#endregion
#region Constructors
static JsonReader ()
{
parse_table = PopulateParseTable ();
}
static JsonReader() => parse_table = PopulateParseTable();
public JsonReader (string json_text) :
this (new StringReader (json_text), true)
{
}
public JsonReader(String json_text) : this(new StringReader(json_text), true) { }
public JsonReader (TextReader reader) :
this (reader, false)
{
}
public JsonReader(TextReader reader) : this(reader, false) { }
private JsonReader (TextReader reader, bool owned)
{
if (reader == null)
private JsonReader(TextReader reader, Boolean owned) {
if(reader == null) {
throw new ArgumentNullException("reader");
}
parser_in_string = false;
parser_return = false;
this.parser_in_string = false;
this.parser_return = false;
read_started = false;
automaton_stack = new Stack<int> ();
automaton_stack.Push ((int) ParserToken.End);
automaton_stack.Push ((int) ParserToken.Text);
this.read_started = false;
this.automaton_stack = new Stack<Int32>();
this.automaton_stack.Push((Int32)ParserToken.End);
this.automaton_stack.Push((Int32)ParserToken.Text);
lexer = new Lexer (reader);
this.lexer = new Lexer(reader);
end_of_input = false;
end_of_json = false;
this.EndOfInput = false;
this.EndOfJson = false;
skip_non_members = true;
this.SkipNonMembers = true;
this.reader = reader;
reader_is_owned = owned;
this.reader_is_owned = owned;
}
#endregion
#region Static Methods
private static IDictionary<int, IDictionary<int, int[]>> PopulateParseTable ()
{
private static IDictionary<Int32, IDictionary<Int32, Int32[]>> PopulateParseTable() =>
// See section A.2. of the manual for details
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)
new Dictionary<Int32, IDictionary<Int32, Int32[]>> {
{
parse_table[(int) row].Add (col, symbols);
(Int32)ParserToken.Array,
new Dictionary<Int32, Int32[]> {
{ '[', new Int32[] { '[', (Int32)ParserToken.ArrayPrime } }
}
private static void TableAddRow (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken rule)
},
{
parse_table.Add ((int) rule, new Dictionary<int, int[]> ());
(Int32)ParserToken.ArrayPrime,
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
#region Private Methods
private void ProcessNumber (string number)
{
if (number.IndexOf ('.') != -1 ||
number.IndexOf ('e') != -1 ||
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;
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)) {
this.Token = JsonToken.Double;
this.Value = n_double;
return;
}
}
int n_int32;
if (int.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int32)) {
token = JsonToken.Int;
token_value = n_int32;
if(Int32.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out Int32 n_int32)) {
this.Token = JsonToken.Int;
this.Value = n_int32;
return;
}
long n_int64;
if (long.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int64)) {
token = JsonToken.Long;
token_value = n_int64;
if(Int64.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out Int64 n_int64)) {
this.Token = JsonToken.Long;
this.Value = n_int64;
return;
}
ulong n_uint64;
if (ulong.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_uint64))
{
token = JsonToken.Long;
token_value = n_uint64;
if(UInt64.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out UInt64 n_uint64)) {
this.Token = JsonToken.Long;
this.Value = n_uint64;
return;
}
// Shouldn't happen, but just in case, return something
token = JsonToken.Int;
token_value = 0;
this.Token = JsonToken.Int;
this.Value = 0;
}
private void ProcessSymbol ()
{
if (current_symbol == '[') {
token = JsonToken.ArrayStart;
parser_return = true;
} else if (current_symbol == ']') {
token = JsonToken.ArrayEnd;
parser_return = true;
} else if (current_symbol == '{') {
token = JsonToken.ObjectStart;
parser_return = true;
} else if (current_symbol == '}') {
token = JsonToken.ObjectEnd;
parser_return = true;
} else if (current_symbol == '"') {
if (parser_in_string) {
parser_in_string = false;
parser_return = true;
private void ProcessSymbol() {
if(this.current_symbol == '[') {
this.Token = JsonToken.ArrayStart;
this.parser_return = true;
} else if(this.current_symbol == ']') {
this.Token = JsonToken.ArrayEnd;
this.parser_return = true;
} else if(this.current_symbol == '{') {
this.Token = JsonToken.ObjectStart;
this.parser_return = true;
} else if(this.current_symbol == '}') {
this.Token = JsonToken.ObjectEnd;
this.parser_return = true;
} else if(this.current_symbol == '"') {
if(this.parser_in_string) {
this.parser_in_string = false;
this.parser_return = true;
} else {
if (token == JsonToken.None)
token = JsonToken.String;
parser_in_string = true;
if(this.Token == JsonToken.None) {
this.Token = JsonToken.String;
}
} else if (current_symbol == (int) ParserToken.CharSeq) {
token_value = lexer.StringValue;
} else if (current_symbol == (int) ParserToken.False) {
token = JsonToken.Boolean;
token_value = false;
parser_return = true;
} else if (current_symbol == (int) ParserToken.Null) {
token = JsonToken.Null;
parser_return = true;
} else if (current_symbol == (int) ParserToken.Number) {
ProcessNumber (lexer.StringValue);
parser_return = true;
} else if (current_symbol == (int) ParserToken.Pair) {
token = JsonToken.PropertyName;
} else if (current_symbol == (int) ParserToken.True) {
token = JsonToken.Boolean;
token_value = true;
parser_return = true;
this.parser_in_string = true;
}
} else if(this.current_symbol == (Int32)ParserToken.CharSeq) {
this.Value = this.lexer.StringValue;
} else if(this.current_symbol == (Int32)ParserToken.False) {
this.Token = JsonToken.Boolean;
this.Value = false;
this.parser_return = true;
} else if(this.current_symbol == (Int32)ParserToken.Null) {
this.Token = JsonToken.Null;
this.parser_return = true;
} else if(this.current_symbol == (Int32)ParserToken.Number) {
this.ProcessNumber(this.lexer.StringValue);
this.parser_return = true;
} else if(this.current_symbol == (Int32)ParserToken.Pair) {
this.Token = JsonToken.PropertyName;
} else if(this.current_symbol == (Int32)ParserToken.True) {
this.Token = JsonToken.Boolean;
this.Value = true;
this.parser_return = true;
}
}
private bool ReadToken ()
{
if (end_of_input)
return false;
lexer.NextToken ();
if (lexer.EndOfInput) {
Close ();
private Boolean ReadToken() {
if(this.EndOfInput) {
return false;
}
current_input = lexer.Token;
_ = this.lexer.NextToken();
if(this.lexer.EndOfInput) {
this.Close();
return false;
}
this.current_input = this.lexer.Token;
return true;
}
#endregion
public void Close ()
{
if (end_of_input)
public void Close() {
if(this.EndOfInput) {
return;
end_of_input = true;
end_of_json = true;
if (reader_is_owned)
{
using(reader){}
}
this.EndOfInput = true;
this.EndOfJson = true;
if(this.reader_is_owned) {
using(this.reader) {
}
}
this.reader = null;
}
reader = null;
}
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 ())
public Boolean Read() {
if(this.EndOfInput) {
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;
}
}
int[] entry_symbols;
Int32[] entry_symbols;
while(true) {
if (parser_return) {
if (automaton_stack.Peek () == (int) ParserToken.End)
end_of_json = true;
if(this.parser_return) {
if(this.automaton_stack.Peek() == (Int32)ParserToken.End) {
this.EndOfJson = true;
}
return true;
}
current_symbol = automaton_stack.Pop ();
this.current_symbol = this.automaton_stack.Pop();
ProcessSymbol ();
this.ProcessSymbol();
if (current_symbol == current_input) {
if (! ReadToken ()) {
if (automaton_stack.Peek () != (int) ParserToken.End)
if(this.current_symbol == this.current_input) {
if(!this.ReadToken()) {
if(this.automaton_stack.Peek() != (Int32)ParserToken.End) {
throw new JsonException(
"Input doesn't evaluate to proper JSON text");
}
if (parser_return)
if(this.parser_return) {
return true;
}
return false;
}
@@ -460,17 +348,19 @@ namespace LitJson
try {
entry_symbols =
parse_table[current_symbol][current_input];
parse_table[this.current_symbol][this.current_input];
} catch(KeyNotFoundException e) {
throw new JsonException ((ParserToken) current_input, e);
throw new JsonException((ParserToken)this.current_input, e);
}
if (entry_symbols[0] == (int) ParserToken.Epsilon)
if(entry_symbols[0] == (Int32)ParserToken.Epsilon) {
continue;
}
for (int i = entry_symbols.Length - 1; i >= 0; i--)
automaton_stack.Push (entry_symbols[i]);
for(Int32 i = entry_symbols.Length - 1; i >= 0; i--) {
this.automaton_stack.Push(entry_symbols[i]);
}
}
}
+116 -155
View File
@@ -18,8 +18,7 @@ using System.Text;
namespace LitJson
{
internal enum Condition
{
internal enum Condition {
InArray,
InObject,
NotAProperty,
@@ -27,8 +26,7 @@ namespace LitJson
Value
}
internal class WriterContext
{
internal class WriterContext {
public Int32 Count;
public Boolean InArray;
public Boolean InObject;
@@ -46,121 +44,90 @@ namespace LitJson
private Char[] hex_seq;
private Int32 indentation;
private Int32 indent_value;
private StringBuilder inst_string_builder;
private Boolean pretty_print;
private Boolean validate;
private Boolean lower_case_properties;
private TextWriter writer;
private readonly StringBuilder inst_string_builder;
#endregion
#region Properties
public Int32 IndentValue {
get { return this.indent_value; }
get => this.indent_value;
set {
this.indentation = (this.indentation / this.indent_value) * value;
this.indentation = this.indentation / this.indent_value * value;
this.indent_value = value;
}
}
public Boolean PrettyPrint {
get { return this.pretty_print; }
set { this.pretty_print = value; }
}
public Boolean PrettyPrint { get; set; }
public TextWriter TextWriter {
get { return this.writer; }
}
private TextWriter TextWriter { get; }
public Boolean Validate {
get { return this.validate; }
set { this.validate = value; }
}
public Boolean Validate { get; set; }
public Boolean LowerCaseProperties {
get { return this.lower_case_properties; }
set { this.lower_case_properties = value; }
}
public Boolean LowerCaseProperties { get; set; }
#endregion
#region Constructors
static JsonWriter() {
number_format = NumberFormatInfo.InvariantInfo;
}
static JsonWriter() => number_format = NumberFormatInfo.InvariantInfo;
public JsonWriter() {
this.inst_string_builder = new StringBuilder();
this.writer = new StringWriter(this.inst_string_builder);
Init();
this.TextWriter = new StringWriter(this.inst_string_builder);
this.Init();
}
public JsonWriter(StringBuilder sb) :
this(new StringWriter(sb)) {
}
public JsonWriter(StringBuilder sb) : this(new StringWriter(sb)) { }
public JsonWriter(TextWriter writer) {
this.writer = writer ?? throw new ArgumentNullException("writer");
Init();
this.TextWriter = writer ?? throw new ArgumentNullException("writer");
this.Init();
}
#endregion
#region Private Methods
private void DoValidation(Condition cond) {
if (!this.context.ExpectingValue) {
this.context.Count++;
}
if (!this.validate) {
if (!this.Validate) {
return;
}
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) {
case Condition.InArray:
if (!this.context.InArray) {
throw new JsonException(
"Can't close an array here");
throw new JsonException("Can't close an array here");
}
break;
case Condition.InObject:
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;
case Condition.NotAProperty:
if (this.context.InObject && !this.context.ExpectingValue) {
throw new JsonException(
"Expected a property");
throw new JsonException("Expected a property");
}
break;
case Condition.Property:
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;
case Condition.Value:
if (!this.context.InArray &&
(!this.context.InObject || !this.context.ExpectingValue)) {
throw new JsonException(
"Can't add a value here");
if (!this.context.InArray && (!this.context.InObject || !this.context.ExpectingValue)) {
throw new JsonException("Can't add a value here");
}
break;
@@ -172,9 +139,9 @@ namespace LitJson
this.hex_seq = new Char[4];
this.indentation = 0;
this.indent_value = 4;
this.pretty_print = false;
this.validate = true;
this.lower_case_properties = false;
this.PrettyPrint = false;
this.Validate = true;
this.LowerCaseProperties = false;
this.ctx_stack = new Stack<WriterContext>();
this.context = new WriterContext();
@@ -183,114 +150,96 @@ namespace LitJson
private static void IntToHex(Int32 n, Char[] hex) {
Int32 num;
for (Int32 i = 0; i < 4; i++) {
num = n % 16;
if (num < 10) {
hex[3 - i] = (Char)('0' + num);
} else {
hex[3 - i] = (Char)('A' + (num - 10));
}
hex[3 - i] = num < 10 ? (Char)('0' + num) : (Char)('A' + (num - 10));
n >>= 4;
}
}
private void Indent() {
if (this.pretty_print) {
if (this.PrettyPrint) {
this.indentation += this.indent_value;
}
}
private void Put(String str) {
if (this.pretty_print && !this.context.ExpectingValue) {
if (this.PrettyPrint && !this.context.ExpectingValue) {
for (Int32 i = 0; i < this.indentation; i++) {
this.writer.Write(' ');
this.TextWriter.Write(' ');
}
}
this.TextWriter.Write(str);
}
this.writer.Write(str);
}
private void PutNewline() {
PutNewline(true);
}
private void PutNewline() => this.PutNewline(true);
private void PutNewline(Boolean add_comma) {
if (add_comma && !this.context.ExpectingValue &&
this.context.Count > 1) {
this.writer.Write(',');
if (add_comma && !this.context.ExpectingValue && this.context.Count > 1) {
this.TextWriter.Write(',');
}
if (this.pretty_print && !this.context.ExpectingValue) {
this.writer.Write(Environment.NewLine);
if (this.PrettyPrint && !this.context.ExpectingValue) {
this.TextWriter.Write(Environment.NewLine);
}
}
private void PutString(String str) {
Put(String.Empty);
this.Put(String.Empty);
this.writer.Write('"');
this.TextWriter.Write('"');
Int32 n = str.Length;
for (Int32 i = 0; i < n; i++) {
switch (str[i]) {
case '\n':
this.writer.Write("\\n");
this.TextWriter.Write("\\n");
continue;
case '\r':
this.writer.Write("\\r");
this.TextWriter.Write("\\r");
continue;
case '\t':
this.writer.Write("\\t");
this.TextWriter.Write("\\t");
continue;
case '"':
case '\\':
this.writer.Write('\\');
this.writer.Write(str[i]);
this.TextWriter.Write('\\');
this.TextWriter.Write(str[i]);
continue;
case '\f':
this.writer.Write("\\f");
this.TextWriter.Write("\\f");
continue;
case '\b':
this.writer.Write("\\b");
this.TextWriter.Write("\\b");
continue;
}
if (str[i] >= 32 && str[i] <= 126) {
this.writer.Write(str[i]);
this.TextWriter.Write(str[i]);
continue;
}
// Default, turn into a \uXXXX sequence
IntToHex(str[i], this.hex_seq);
this.writer.Write("\\u");
this.writer.Write(this.hex_seq);
this.TextWriter.Write("\\u");
this.TextWriter.Write(this.hex_seq);
}
this.writer.Write('"');
this.TextWriter.Write('"');
}
private void Unindent() {
if (this.pretty_print) {
if (this.PrettyPrint) {
this.indentation -= this.indent_value;
}
}
#endregion
public override String ToString() {
if (this.inst_string_builder == null) {
return String.Empty;
}
return this.inst_string_builder.ToString();
}
public override String ToString() => this.inst_string_builder == null ? String.Empty : this.inst_string_builder.ToString();
public void Reset() {
this.has_reached_end = false;
@@ -300,88 +249,100 @@ namespace LitJson
this.ctx_stack.Push(this.context);
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) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
Put(boolean ? "true" : "false");
this.Put(boolean ? "true" : "false");
this.context.ExpectingValue = false;
}
public void Write(Decimal number) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
Put(Convert.ToString(number, number_format));
this.Put(Convert.ToString(number, number_format));
this.context.ExpectingValue = false;
}
public void Write(Double number) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
String str = Convert.ToString(number, number_format);
Put(str);
this.Put(str);
if (str.IndexOf('.') == -1 && str.IndexOf('E') == -1) {
this.writer.Write(".0");
this.TextWriter.Write(".0");
}
this.context.ExpectingValue = false;
}
public void Write(Int32 number) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
Put(Convert.ToString(number, number_format));
this.Put(Convert.ToString(number, number_format));
this.context.ExpectingValue = false;
}
public void Write(Int64 number) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
Put(Convert.ToString(number, number_format));
this.Put(Convert.ToString(number, number_format));
this.context.ExpectingValue = false;
}
public void Write(String str) {
DoValidation(Condition.Value);
PutNewline();
this.DoValidation(Condition.Value);
this.PutNewline();
if (str == null) {
Put("null");
this.Put("null");
} else {
PutString(str);
this.PutString(str);
}
this.context.ExpectingValue = false;
}
// [CLSCompliant(false)]
public void Write(UInt64 number) {
DoValidation(Condition.Value);
PutNewline();
public void WriteJson(String str) {
this.DoValidation(Condition.Value);
this.PutNewline();
Put(Convert.ToString(number, number_format));
if(str == null) {
this.Put("null");
} else {
this.TextWriter.Write(str);
}
this.context.ExpectingValue = false;
}
public void Write(UInt64 number) {
this.DoValidation(Condition.Value);
this.PutNewline();
this.Put(Convert.ToString(number, number_format));
this.context.ExpectingValue = false;
}
public void WriteArrayEnd() {
DoValidation(Condition.InArray);
PutNewline(false);
this.DoValidation(Condition.InArray);
this.PutNewline(false);
this.ctx_stack.Pop();
_ = this.ctx_stack.Pop();
if (this.ctx_stack.Count == 1) {
this.has_reached_end = true;
} else {
@@ -389,29 +350,29 @@ namespace LitJson
this.context.ExpectingValue = false;
}
Unindent();
Put("]");
this.Unindent();
this.Put("]");
}
public void WriteArrayStart() {
DoValidation(Condition.NotAProperty);
PutNewline();
this.DoValidation(Condition.NotAProperty);
this.PutNewline();
Put("[");
this.Put("[");
this.context = new WriterContext {
InArray = true
};
this.ctx_stack.Push(this.context);
Indent();
this.Indent();
}
public void WriteObjectEnd() {
DoValidation(Condition.InObject);
PutNewline(false);
this.DoValidation(Condition.InObject);
this.PutNewline(false);
this.ctx_stack.Pop();
_ = this.ctx_stack.Pop();
if (this.ctx_stack.Count == 1) {
this.has_reached_end = true;
} else {
@@ -419,44 +380,44 @@ namespace LitJson
this.context.ExpectingValue = false;
}
Unindent();
Put("}");
this.Unindent();
this.Put("}");
}
public void WriteObjectStart() {
DoValidation(Condition.NotAProperty);
PutNewline();
this.DoValidation(Condition.NotAProperty);
this.PutNewline();
Put("{");
this.Put("{");
this.context = new WriterContext {
InObject = true
};
this.ctx_stack.Push(this.context);
Indent();
this.Indent();
}
public void WritePropertyName(String property_name) {
DoValidation(Condition.Property);
PutNewline();
String propertyName = (property_name == null || !this.lower_case_properties) ? property_name : property_name.ToLowerInvariant();
this.DoValidation(Condition.Property);
this.PutNewline();
String propertyName = (property_name == null || !this.LowerCaseProperties) ? property_name : property_name.ToLowerInvariant();
PutString(propertyName);
this.PutString(propertyName);
if (this.pretty_print) {
if (this.PrettyPrint) {
if (propertyName.Length > this.context.Padding) {
this.context.Padding = propertyName.Length;
}
for (Int32 i = this.context.Padding - propertyName.Length;
i >= 0; i--) {
this.writer.Write(' ');
this.TextWriter.Write(' ');
}
this.writer.Write(": ");
this.TextWriter.Write(": ");
} else {
this.writer.Write(':');
this.TextWriter.Write(':');
}
this.context.ExpectingValue = true;
+150 -209
View File
@@ -10,96 +10,66 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace LitJson
{
internal class FsmContext
{
public bool Return;
public int NextState;
namespace LitJson {
internal class FsmContext {
public Boolean Return;
public Int32 NextState;
public Lexer L;
public int StateStack;
public Int32 StateStack;
}
internal class Lexer
{
internal class Lexer {
#region Fields
private delegate bool StateHandler (FsmContext ctx);
private delegate Boolean StateHandler(FsmContext ctx);
private static readonly int[] fsm_return_table;
private static readonly Int32[] fsm_return_table;
private static readonly StateHandler[] fsm_handler_table;
private bool allow_comments;
private bool allow_single_quoted_strings;
private bool end_of_input;
private FsmContext fsm_context;
private int input_buffer;
private int input_char;
private TextReader reader;
private int state;
private StringBuilder string_buffer;
private string string_value;
private int token;
private int unichar;
private readonly FsmContext fsm_context;
private Int32 input_buffer;
private Int32 input_char;
private readonly TextReader reader;
private Int32 state;
private readonly StringBuilder string_buffer;
private Int32 unichar;
#endregion
#region Properties
public bool AllowComments {
get { return allow_comments; }
set { allow_comments = value; }
}
public Boolean AllowComments { get; set; }
public bool AllowSingleQuotedStrings {
get { return allow_single_quoted_strings; }
set { allow_single_quoted_strings = value; }
}
public Boolean AllowSingleQuotedStrings { get; set; }
public bool EndOfInput {
get { return end_of_input; }
}
public Boolean EndOfInput { get; private set; }
public int Token {
get { return token; }
}
public Int32 Token { get; private set; }
public string StringValue {
get { return string_value; }
}
public String StringValue { get; private set; }
#endregion
#region Constructors
static Lexer ()
{
PopulateFsmTables (out fsm_handler_table, out fsm_return_table);
}
static Lexer() => PopulateFsmTables(out fsm_handler_table, out fsm_return_table);
public Lexer (TextReader reader)
{
allow_comments = true;
allow_single_quoted_strings = true;
public Lexer(TextReader reader) {
this.AllowComments = true;
this.AllowSingleQuotedStrings = true;
input_buffer = 0;
string_buffer = new StringBuilder (128);
state = 1;
end_of_input = false;
this.input_buffer = 0;
this.string_buffer = new StringBuilder(128);
this.state = 1;
this.EndOfInput = false;
this.reader = reader;
fsm_context = new FsmContext ();
fsm_context.L = this;
this.fsm_context = new FsmContext {
L = this
};
}
#endregion
#region Static Methods
private static int HexValue (int digit)
{
private static Int32 HexValue(Int32 digit) {
switch(digit) {
case 'a':
case 'A':
@@ -130,8 +100,7 @@ namespace LitJson
}
}
private static void PopulateFsmTables (out StateHandler[] fsm_handler_table, out int[] fsm_return_table)
{
private static void PopulateFsmTables(out StateHandler[] fsm_handler_table, out Int32[] fsm_return_table) {
// See section A.1. of the manual for details of the finite
// state machine.
fsm_handler_table = new StateHandler[28] {
@@ -165,31 +134,31 @@ namespace LitJson
State28
};
fsm_return_table = new int[28] {
(int) ParserToken.Char,
fsm_return_table = new Int32[28] {
(Int32) ParserToken.Char,
0,
(int) ParserToken.Number,
(int) ParserToken.Number,
(Int32) ParserToken.Number,
(Int32) ParserToken.Number,
0,
(int) ParserToken.Number,
(Int32) ParserToken.Number,
0,
(int) ParserToken.Number,
(Int32) ParserToken.Number,
0,
0,
(int) ParserToken.True,
(Int32) ParserToken.True,
0,
0,
0,
(int) ParserToken.False,
(Int32) ParserToken.False,
0,
0,
(int) ParserToken.Null,
(int) ParserToken.CharSeq,
(int) ParserToken.Char,
(Int32) ParserToken.Null,
(Int32) ParserToken.CharSeq,
(Int32) ParserToken.Char,
0,
0,
(int) ParserToken.CharSeq,
(int) ParserToken.Char,
(Int32) ParserToken.CharSeq,
(Int32) ParserToken.Char,
0,
0,
0,
@@ -197,8 +166,7 @@ namespace LitJson
};
}
private static char ProcessEscChar (int esc_char)
{
private static Char ProcessEscChar(Int32 esc_char) {
switch(esc_char) {
case '"':
case '\'':
@@ -227,15 +195,15 @@ namespace LitJson
}
}
private static bool State1 (FsmContext ctx)
{
private static Boolean State1(FsmContext ctx) {
while(ctx.L.GetChar()) {
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') {
continue;
}
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;
return true;
}
@@ -257,12 +225,12 @@ namespace LitJson
return true;
case '-':
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
ctx.NextState = 2;
return true;
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;
return true;
@@ -279,8 +247,9 @@ namespace LitJson
return true;
case '\'':
if (! ctx.L.allow_single_quoted_strings)
if(!ctx.L.AllowSingleQuotedStrings) {
return false;
}
ctx.L.input_char = '"';
ctx.NextState = 23;
@@ -288,8 +257,9 @@ namespace LitJson
return true;
case '/':
if (! ctx.L.allow_comments)
if(!ctx.L.AllowComments) {
return false;
}
ctx.NextState = 25;
return true;
@@ -302,19 +272,18 @@ namespace LitJson
return true;
}
private static bool State2 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State2(FsmContext ctx) {
_ = ctx.L.GetChar();
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;
return true;
}
switch(ctx.L.input_char) {
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;
return true;
@@ -323,11 +292,10 @@ namespace LitJson
}
}
private static bool State3 (FsmContext ctx)
{
private static Boolean State3(FsmContext ctx) {
while(ctx.L.GetChar()) {
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);
continue;
}
@@ -348,13 +316,13 @@ namespace LitJson
return true;
case '.':
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
ctx.NextState = 5;
return true;
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;
return true;
@@ -365,9 +333,8 @@ namespace LitJson
return true;
}
private static bool State4 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State4(FsmContext ctx) {
_ = ctx.L.GetChar();
if(ctx.L.input_char == ' ' ||
ctx.L.input_char >= '\t' && ctx.L.input_char <= '\r') {
@@ -386,13 +353,13 @@ namespace LitJson
return true;
case '.':
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
ctx.NextState = 5;
return true;
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;
return true;
@@ -401,12 +368,11 @@ namespace LitJson
}
}
private static bool State5 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State5(FsmContext ctx) {
_ = ctx.L.GetChar();
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;
return true;
}
@@ -414,11 +380,10 @@ namespace LitJson
return false;
}
private static bool State6 (FsmContext ctx)
{
private static Boolean State6(FsmContext ctx) {
while(ctx.L.GetChar()) {
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);
continue;
}
@@ -440,7 +405,7 @@ namespace LitJson
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;
return true;
@@ -452,12 +417,11 @@ namespace LitJson
return true;
}
private static bool State7 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State7(FsmContext ctx) {
_ = ctx.L.GetChar();
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;
return true;
}
@@ -465,7 +429,7 @@ namespace LitJson
switch(ctx.L.input_char) {
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;
return true;
@@ -474,11 +438,10 @@ namespace LitJson
}
}
private static bool State8 (FsmContext ctx)
{
private static Boolean State8(FsmContext ctx) {
while(ctx.L.GetChar()) {
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);
continue;
}
@@ -506,9 +469,8 @@ namespace LitJson
return true;
}
private static bool State9 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State9(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'r':
@@ -520,9 +482,8 @@ namespace LitJson
}
}
private static bool State10 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State10(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'u':
@@ -534,9 +495,8 @@ namespace LitJson
}
}
private static bool State11 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State11(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'e':
@@ -549,9 +509,8 @@ namespace LitJson
}
}
private static bool State12 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State12(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'a':
@@ -563,9 +522,8 @@ namespace LitJson
}
}
private static bool State13 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State13(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'l':
@@ -577,9 +535,8 @@ namespace LitJson
}
}
private static bool State14 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State14(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 's':
@@ -591,9 +548,8 @@ namespace LitJson
}
}
private static bool State15 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State15(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'e':
@@ -606,9 +562,8 @@ namespace LitJson
}
}
private static bool State16 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State16(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'u':
@@ -620,9 +575,8 @@ namespace LitJson
}
}
private static bool State17 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State17(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'l':
@@ -634,9 +588,8 @@ namespace LitJson
}
}
private static bool State18 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State18(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'l':
@@ -649,8 +602,7 @@ namespace LitJson
}
}
private static bool State19 (FsmContext ctx)
{
private static Boolean State19(FsmContext ctx) {
while(ctx.L.GetChar()) {
switch(ctx.L.input_char) {
case '"':
@@ -665,7 +617,7 @@ namespace LitJson
return true;
default:
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
continue;
}
}
@@ -673,9 +625,8 @@ namespace LitJson
return true;
}
private static bool State20 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State20(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case '"':
@@ -688,9 +639,8 @@ namespace LitJson
}
}
private static bool State21 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State21(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case 'u':
@@ -706,7 +656,7 @@ namespace LitJson
case 'n':
case 'r':
case 't':
ctx.L.string_buffer.Append (
_ = ctx.L.string_buffer.Append(
ProcessEscChar(ctx.L.input_char));
ctx.NextState = ctx.StateStack;
return true;
@@ -716,10 +666,9 @@ namespace LitJson
}
}
private static bool State22 (FsmContext ctx)
{
int counter = 0;
int mult = 4096;
private static Boolean State22(FsmContext ctx) {
Int32 counter = 0;
Int32 mult = 4096;
ctx.L.unichar = 0;
@@ -735,7 +684,7 @@ namespace LitJson
mult /= 16;
if(counter == 4) {
ctx.L.string_buffer.Append (
_ = ctx.L.string_buffer.Append(
Convert.ToChar(ctx.L.unichar));
ctx.NextState = ctx.StateStack;
return true;
@@ -750,8 +699,7 @@ namespace LitJson
return true;
}
private static bool State23 (FsmContext ctx)
{
private static Boolean State23(FsmContext ctx) {
while(ctx.L.GetChar()) {
switch(ctx.L.input_char) {
case '\'':
@@ -766,7 +714,7 @@ namespace LitJson
return true;
default:
ctx.L.string_buffer.Append ((char) ctx.L.input_char);
_ = ctx.L.string_buffer.Append((Char)ctx.L.input_char);
continue;
}
}
@@ -774,9 +722,8 @@ namespace LitJson
return true;
}
private static bool State24 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State24(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case '\'':
@@ -790,9 +737,8 @@ namespace LitJson
}
}
private static bool State25 (FsmContext ctx)
{
ctx.L.GetChar ();
private static Boolean State25(FsmContext ctx) {
_ = ctx.L.GetChar();
switch(ctx.L.input_char) {
case '*':
@@ -808,8 +754,7 @@ namespace LitJson
}
}
private static bool State26 (FsmContext ctx)
{
private static Boolean State26(FsmContext ctx) {
while(ctx.L.GetChar()) {
if(ctx.L.input_char == '\n') {
ctx.NextState = 1;
@@ -820,8 +765,7 @@ namespace LitJson
return true;
}
private static bool State27 (FsmContext ctx)
{
private static Boolean State27(FsmContext ctx) {
while(ctx.L.GetChar()) {
if(ctx.L.input_char == '*') {
ctx.NextState = 28;
@@ -832,11 +776,11 @@ namespace LitJson
return true;
}
private static bool State28 (FsmContext ctx)
{
private static Boolean State28(FsmContext ctx) {
while(ctx.L.GetChar()) {
if (ctx.L.input_char == '*')
if(ctx.L.input_char == '*') {
continue;
}
if(ctx.L.input_char == '/') {
ctx.NextState = 1;
@@ -851,62 +795,59 @@ namespace LitJson
}
#endregion
private bool GetChar ()
{
if ((input_char = NextChar ()) != -1)
private Boolean GetChar() {
if((this.input_char = this.NextChar()) != -1) {
return true;
}
end_of_input = true;
this.EndOfInput = true;
return false;
}
private int NextChar ()
{
if (input_buffer != 0) {
int tmp = input_buffer;
input_buffer = 0;
private Int32 NextChar() {
if(this.input_buffer != 0) {
Int32 tmp = this.input_buffer;
this.input_buffer = 0;
return tmp;
}
return reader.Read ();
return this.reader.Read();
}
public bool NextToken ()
{
public Boolean NextToken() {
StateHandler handler;
fsm_context.Return = false;
this.fsm_context.Return = false;
while(true) {
handler = fsm_handler_table[state - 1];
handler = fsm_handler_table[this.state - 1];
if (! handler (fsm_context))
throw new JsonException (input_char);
if(!handler(this.fsm_context)) {
throw new JsonException(this.input_char);
}
if (end_of_input)
if(this.EndOfInput) {
return false;
}
if (fsm_context.Return) {
string_value = string_buffer.ToString ();
string_buffer.Remove (0, string_buffer.Length);
token = fsm_return_table[state - 1];
if(this.fsm_context.Return) {
this.StringValue = this.string_buffer.ToString();
_ = this.string_buffer.Remove(0, this.string_buffer.Length);
this.Token = fsm_return_table[this.state - 1];
if (token == (int) ParserToken.Char)
token = input_char;
if(this.Token == (Int32)ParserToken.Char) {
this.Token = this.input_char;
}
state = fsm_context.NextState;
this.state = this.fsm_context.NextState;
return true;
}
state = fsm_context.NextState;
this.state = this.fsm_context.NextState;
}
}
private void UngetChar ()
{
input_buffer = input_char;
}
private void UngetChar() => this.input_buffer = this.input_char;
}
}
+2 -4
View File
@@ -9,10 +9,8 @@
#endregion
namespace LitJson
{
internal enum ParserToken
{
namespace LitJson {
internal enum ParserToken {
// Lexer tokens (see section A.1.1. of the manual)
None = System.Char.MaxValue + 1,
Number,
+3 -1
View File
@@ -1,4 +1,5 @@
using System.Reflection;
#if !NETCOREAPP
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -34,3 +35,4 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.12.0")]
[assembly: AssemblyFileVersion("0.12.0")]
#endif
+33
View File
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</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>
+6
View File
@@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -29,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -53,5 +55,9 @@
<Compile Include="ParserToken.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\COPYING" />
<Content Include="..\README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>