public static bool Equals(JValue left, JValue right) { var leftType = left.Type; var rightType = right.Type; if (leftType == rightType) { switch (leftType) { case TypeCode.Null: return(true); case TypeCode.Boolean: return(left.ToBooleanCore() == right.ToBooleanCore()); case TypeCode.Number: return(JNumber.Equals(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN))); case TypeCode.String: return(EqualsString(left, right)); case TypeCode.Array: return(SequenceEqual(left.Array().GetEnumerator(), right.Array().GetEnumerator(), Equals)); case TypeCode.Object: return(SequenceEqual(left.Object().GetEnumerator(), right.Object().GetEnumerator(), EqualsMember)); } } return(false); }
public static int Compare(JValue left, JValue right) { var leftType = left.typeCode; var rightType = right.typeCode; if (leftType == rightType) { switch (leftType) { case TypeCode.Null: return(0); case TypeCode.Boolean: return(left.ToBooleanCore().CompareTo(right.ToBooleanCore())); case TypeCode.Number: return(JNumber.Compare(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN))); case TypeCode.String: return(SequenceCompare <char, CharEnumerator>(left.GetCharEnumerator(), right.GetCharEnumerator(), (x, y) => x.CompareTo(y))); case TypeCode.Array: return(SequenceCompare(left.GetArrayItems(), right.GetArrayItems(), Compare)); case TypeCode.Object: return(SequenceCompare(left.GetObjectKeyValues().GetEnumerator(), right.GetObjectKeyValues(), CompareMember)); default: return(0); } } return(((int)leftType).CompareTo((int)rightType)); }
public static bool Equals(JValue left, JValue right) { var leftType = left.typeCode; var rightType = right.typeCode; if (leftType == rightType) { switch (leftType) { case TypeCode.Null: return(true); case TypeCode.Boolean: return(left.ToBooleanCore() == right.ToBooleanCore()); case TypeCode.Number: return(JNumber.Equals(left.ToNumberCore(JNumber.NaN), right.ToNumberCore(JNumber.NaN))); case TypeCode.String: return(EqualsString(left, right)); case TypeCode.Array: return(SequenceEqual <JValue, ArrayEnumerator>(left.GetArrayItems(), right.GetArrayItems(), Equals)); case TypeCode.Object: return(SequenceEqual <KeyValuePair, ObjectKeyValueEnumerator>(left.GetObjectKeyValues(), right.GetObjectKeyValues(), EqualsMember)); } } return(false); }
public void Parse(string input, string expectedIntegerPart, string expectedFractionalPart = null, string expectedExponent = null) { var number = JNumber.Parse(input); if (string.IsNullOrEmpty(expectedIntegerPart) == false) { Assert.AreEqual(expectedIntegerPart, number.IntegerPart.ToString()); } else { Assert.IsTrue(number.IntegerPart.IsNaN); } if (string.IsNullOrEmpty(expectedFractionalPart) == false) { Assert.AreEqual(expectedFractionalPart, number.FractionalPart.ToString()); } else { Assert.IsTrue(number.FractionalPart.IsNaN); } if (string.IsNullOrEmpty(expectedExponent) == false) { Assert.AreEqual(expectedExponent, number.Exponent.ToString()); } else { Assert.IsTrue(number.Exponent.IsNaN); } }
public int JValueParse() { return (JNumber.ParseInt32(shortNumber) + JNumber.ParseInt32(longNumber) + JNumber.ParseInt32(negativeNumber) + JNumber.ParseInt32(minNumber) + JNumber.ParseInt32(maxNumber)); }
public void Equality(string left, string right) { Assert.IsTrue(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right))); if (left.StartsWith("-", StringComparison.Ordinal) == false) { left = FormattableString.Invariant($"-{left}"); right = FormattableString.Invariant($"-{right}"); Assert.IsTrue(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right))); } }
public JNumber ToNumber(JNumber defaultValue) { switch (Type) { case TypeCode.Boolean: return(ToBooleanCore() ? JNumber.One : JNumber.Zero); case TypeCode.Number: return(ToNumberCore(defaultValue)); case TypeCode.String: return(ConvertForNumberParsing().ToNumberCore(defaultValue)); default: return(JNumber.NaN); } }
private double ToDoubleCore(double defaultValue) => JNumber.ParseDouble(source, startIndex, defaultValue);
public void TwoNumber_Are_Equal_But_NotEquivalent(string left, string right) { Assert.IsTrue( JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)) && JNumber.Compare(JNumber.Parse(left), JNumber.Parse(right)) != 0); }
public int LeadingZeros(string input) => JNumber.Parse(input).FractionalPart.LeadingZeros;
public void Inequality(string left, string right) => Assert.IsFalse(JNumber.Equals(JNumber.Parse(left), JNumber.Parse(right)));
public void Compare(string less, string greater) { Assert.IsTrue(JNumber.Compare(JNumber.Parse(less), JNumber.Parse(greater)) < 0); Assert.IsTrue(JNumber.Compare(JNumber.Parse(greater), JNumber.Parse(less)) > 0); }
private byte ToByteCore(byte defaultValue) => (byte)JNumber.ParseInt32(source, startIndex, defaultValue); // TODO
private int ToInt32Core(int defaultValue) => JNumber.ParseInt32(source, startIndex, defaultValue);
static int Parse(string s) => JNumber.ParseInt32(s);
private long ToInt64Core(long defaultValue) => JNumber.ParseInt64(source, startIndex, defaultValue);
private float ToSingleCore(float defaultValue) => JNumber.ParseSingle(source, startIndex, defaultValue);
public double JValueParse() { return (JNumber.ParseDouble(number1) + JNumber.ParseDouble(number2)); }
private decimal ToDecimalCore(decimal defaultValue) => JNumber.ParseDecimal(source, startIndex, length, defaultValue);
public float JValueParse() { return (JNumber.ParseSingle(number1) + JNumber.ParseSingle(number2)); }
private JNumber ToNumberCore(JNumber defaultValue) => JNumber.TryParse(source, startIndex, out var value) ? value : defaultValue;