mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-24 03:25:41 -05:00
remove unused JsonDiff
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public enum JsonDiffType
|
||||
{
|
||||
KeyAdded,
|
||||
KeyRemoved,
|
||||
ValueChanged,
|
||||
}
|
||||
|
||||
public struct JsonDiff
|
||||
{
|
||||
public JsonPointer Path;
|
||||
public JsonDiffType DiffType;
|
||||
public string Msg;
|
||||
|
||||
public static JsonDiff Create(JsonNode node, JsonDiffType diffType, string msg)
|
||||
{
|
||||
return new JsonDiff
|
||||
{
|
||||
Path = JsonPointer.Create(node),
|
||||
DiffType = diffType,
|
||||
Msg = msg,
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
switch (DiffType)
|
||||
{
|
||||
case JsonDiffType.KeyAdded:
|
||||
return string.Format("+ {0}: {1}", Path, Msg);
|
||||
case JsonDiffType.KeyRemoved:
|
||||
return string.Format("- {0}: {1}", Path, Msg);
|
||||
case JsonDiffType.ValueChanged:
|
||||
return string.Format("= {0}: {1}", Path, Msg);
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97356eb7e23aca64c84f836d6c298f43
|
||||
timeCreated: 1543427903
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -197,96 +197,6 @@ namespace UniJSON
|
||||
return string.Join("", ToString(indent, 0).ToArray());
|
||||
}
|
||||
|
||||
public IEnumerable<JsonDiff> Diff(JsonNode rhs, JsonPointer path = default(JsonPointer))
|
||||
{
|
||||
switch (Value.ValueType)
|
||||
{
|
||||
case ValueNodeType.Null:
|
||||
case ValueNodeType.Boolean:
|
||||
case ValueNodeType.Number:
|
||||
case ValueNodeType.Integer:
|
||||
case ValueNodeType.String:
|
||||
if (!Equals(rhs))
|
||||
{
|
||||
yield return JsonDiff.Create(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value, rhs.Value));
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Value.ValueType != rhs.Value.ValueType)
|
||||
{
|
||||
yield return JsonDiff.Create(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value.ValueType, rhs.Value));
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (Value.ValueType == ValueNodeType.Object)
|
||||
{
|
||||
|
||||
var l = this.ObjectItems().ToDictionary(x => x.Key, x => x.Value);
|
||||
var r = rhs.ObjectItems().ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
foreach (var kv in l)
|
||||
{
|
||||
JsonNode x;
|
||||
if (r.TryGetValue(kv.Key, out x))
|
||||
{
|
||||
r.Remove(kv.Key);
|
||||
// Found
|
||||
foreach (var y in kv.Value.Diff(x))
|
||||
{
|
||||
yield return y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Removed
|
||||
yield return JsonDiff.Create(kv.Value, JsonDiffType.KeyRemoved, kv.Value.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in r)
|
||||
{
|
||||
// Added
|
||||
yield return JsonDiff.Create(kv.Value, JsonDiffType.KeyAdded, kv.Value.Value.ToString());
|
||||
}
|
||||
}
|
||||
else if (Value.ValueType == ValueNodeType.Array)
|
||||
{
|
||||
var ll = this.ArrayItems().GetEnumerator();
|
||||
var rr = rhs.ArrayItems().GetEnumerator();
|
||||
while (true)
|
||||
{
|
||||
var lll = ll.MoveNext();
|
||||
var rrr = rr.MoveNext();
|
||||
if (lll && rrr)
|
||||
{
|
||||
// found
|
||||
foreach (var y in ll.Current.Diff(rr.Current))
|
||||
{
|
||||
yield return y;
|
||||
}
|
||||
}
|
||||
else if (lll)
|
||||
{
|
||||
yield return JsonDiff.Create(ll.Current, JsonDiffType.KeyRemoved, ll.Current.Value.ToString());
|
||||
}
|
||||
else if (rrr)
|
||||
{
|
||||
yield return JsonDiff.Create(rr.Current, JsonDiffType.KeyAdded, rr.Current.Value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// end
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whole tree nodes
|
||||
/// </summary>
|
||||
|
||||
@@ -42,20 +42,6 @@ namespace UniJSON
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiffTest()
|
||||
{
|
||||
var a = @"{
|
||||
""a"": 1
|
||||
}";
|
||||
|
||||
var b = @"{
|
||||
}";
|
||||
|
||||
var diff = JsonParser.Parse(a).Diff(JsonParser.Parse(b)).ToArray();
|
||||
Assert.AreEqual(1, diff.Length);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[Test]
|
||||
public void Vector3()
|
||||
|
||||
Reference in New Issue
Block a user