Skip to content

Commit

Permalink
rename CBORObject.FromInt to CBORObject.FromInt32
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Oct 20, 2023
1 parent 600153a commit 0e8456d
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions CBOR/PeterO/Cbor/CBORDataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ internal static CBORObject ParseSmallNumberAsNegative(
} else {
// NOTE: Assumes digit is greater than zero, so PreserveNegativeZeros is
// irrelevant
return CBORObject.FromInt(-digit);
return CBORObject.FromInt32(-digit);
}
}

Expand All @@ -328,7 +328,7 @@ internal static CBORObject ParseSmallNumber(int digit, JSONOptions
return CBORObject.FromEDecimal(EDecimal.FromInt32(digit));
} else {
// NOTE: Assumes digit is nonnegative, so PreserveNegativeZeros is irrelevant
return CBORObject.FromInt(digit);
return CBORObject.FromInt32(digit);
}
}

Expand Down
8 changes: 4 additions & 4 deletions CBOR/PeterO/Cbor/CBORDataUtilitiesByteArrayString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static CBORObject ParseJSONNumber(
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble ||
kind == JSONOptions.ConversionMode.IntOrFloat) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else if (negativeExp) {
// underflow
Expand All @@ -170,7 +170,7 @@ internal static CBORObject ParseJSONNumber(
return !negative ? CBORObject.FromFloatingPointBits(0, 2) :
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else {
// overflow
Expand Down Expand Up @@ -247,7 +247,7 @@ internal static CBORObject ParseJSONNumber(
} else {
var cbor = CBORObject.FromArrayBackedObject(
new CBORObject[] {
CBORObject.FromInt(expo),
CBORObject.FromInt32(expo),
CBORObject.FromInt64(lv),
});
return cbor.WithTag(4);
Expand All @@ -264,7 +264,7 @@ internal static CBORObject ParseJSONNumber(
if (ed.Exponent.IsZero) {
return preserveNegativeZero ?
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromInt(0);
CBORObject.FromInt32(0);
} else {
return !preserveNegativeZero ?
CBORObject.FromEDecimal(ed.Negate()) : CBORObject.FromEDecimal(ed);
Expand Down
8 changes: 4 additions & 4 deletions CBOR/PeterO/Cbor/CBORDataUtilitiesCharArrayString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static CBORObject ParseJSONNumber(
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble ||
kind == JSONOptions.ConversionMode.IntOrFloat) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else if (negativeExp) {
// underflow
Expand All @@ -170,7 +170,7 @@ internal static CBORObject ParseJSONNumber(
return !negative ? CBORObject.FromFloatingPointBits(0, 2) :
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else {
// overflow
Expand Down Expand Up @@ -247,7 +247,7 @@ internal static CBORObject ParseJSONNumber(
} else {
var cbor = CBORObject.FromArrayBackedObject(
new CBORObject[] {
CBORObject.FromInt(expo),
CBORObject.FromInt32(expo),
CBORObject.FromInt64(lv),
});
return cbor.WithTag(4);
Expand All @@ -264,7 +264,7 @@ internal static CBORObject ParseJSONNumber(
if (ed.Exponent.IsZero) {
return preserveNegativeZero ?
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromInt(0);
CBORObject.FromInt32(0);
} else {
return !preserveNegativeZero ?
CBORObject.FromEDecimal(ed.Negate()) : CBORObject.FromEDecimal(ed);
Expand Down
8 changes: 4 additions & 4 deletions CBOR/PeterO/Cbor/CBORDataUtilitiesTextString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static CBORObject ParseJSONNumber(
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble ||
kind == JSONOptions.ConversionMode.IntOrFloat) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else if (negativeExp) {
// underflow
Expand All @@ -170,7 +170,7 @@ internal static CBORObject ParseJSONNumber(
return !negative ? CBORObject.FromFloatingPointBits(0, 2) :
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
return CBORObject.FromInt(0);
return CBORObject.FromInt32(0);
}
} else {
// overflow
Expand Down Expand Up @@ -247,7 +247,7 @@ internal static CBORObject ParseJSONNumber(
} else {
var cbor = CBORObject.FromArrayBackedObject(
new CBORObject[] {
CBORObject.FromInt(expo),
CBORObject.FromInt32(expo),
CBORObject.FromInt64(lv),
});
return cbor.WithTag(4);
Expand All @@ -263,7 +263,7 @@ internal static CBORObject ParseJSONNumber(
return ed.IsZero && negative ? ed.Exponent.IsZero ?
preserveNegativeZero ?
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromInt(0) :
CBORObject.FromInt32(0) :
!preserveNegativeZero ? CBORObject.FromEDecimal(ed.Negate()) :
CBORObject.FromEDecimal(ed) :
ed.Exponent.IsZero ? CBORObject.FromEInteger(ed.Mantissa) :
Expand Down
2 changes: 1 addition & 1 deletion CBOR/PeterO/Cbor/CBORNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ public CBORNumber Remainder(CBORNumber b) {
/// if they receive a null argument rather than treating null as less
/// or greater than any object.</para>.</returns>
public int CompareTo(int other) {
return this.CompareTo(CBORObject.FromInt(other).AsNumber());
return this.CompareTo(CBORObject.FromInt32(other).AsNumber());
}

/// <summary>Compares this CBOR number with a 64-bit signed integer. In
Expand Down
26 changes: 13 additions & 13 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public CBORObject this[int index]
}
if (this.Type == CBORType.Map) {
IDictionary<CBORObject, CBORObject> map = this.AsMap();
var key = CBORObject.FromInt(index);
var key = CBORObject.FromInt32(index);
// TODO: In next major version, consider throwing an exception
// instead if key does not exist.
return PropertyMap.GetOrDefault(map, key, null);
Expand All @@ -548,7 +548,7 @@ public CBORObject this[int index]
list[index] = value;
} else if (this.Type == CBORType.Map) {
IDictionary<CBORObject, CBORObject> map = this.AsMap();
var key = CBORObject.FromInt(index);
var key = CBORObject.FromInt32(index);
map[key] = value;
} else {
throw new InvalidOperationException("Not an array or map");
Expand Down Expand Up @@ -617,7 +617,7 @@ public CBORObject GetOrDefault(int key, CBORObject defaultValue) {
}
if (this.Type == CBORType.Map) {
IDictionary<CBORObject, CBORObject> map = this.AsMap();
var ckey = FromInt(key);
var ckey = FromInt32(key);
return PropertyMap.GetOrDefault(map, ckey, defaultValue);
}
return defaultValue;
Expand Down Expand Up @@ -2118,7 +2118,7 @@ public static CBORObject FromEFloat(EFloat bigValue) {
cbor = NewArray(
FromEInteger(bigValue.Exponent),
FromEInteger(bigValue.UnsignedMantissa),
FromInt(options));
FromInt32(options));
tag = 269;
} else {
EInteger exponent = bigValue.Exponent;
Expand Down Expand Up @@ -2200,7 +2200,7 @@ public static CBORObject FromERational(ERational bigValue) {
cbor = NewArray(
FromEInteger(bigValue.UnsignedNumerator),
FromEInteger(bigValue.Denominator),
FromInt(options));
FromInt32(options));
tag = 270;
} else {
tag = 30;
Expand Down Expand Up @@ -2255,7 +2255,7 @@ public static CBORObject FromEDecimal(EDecimal bigValue) {
cbor = NewArray(
FromEInteger(bigValue.Exponent),
FromEInteger(bigValue.UnsignedMantissa),
FromInt(options));
FromInt32(options));
tag = 268;
} else {
EInteger exponent = bigValue.Exponent;
Expand Down Expand Up @@ -2314,7 +2314,7 @@ public static CBORObject FromString(string strValue) {
/// <param name='value'>The parameter <paramref name='value'/> is a
/// 32-bit signed integer.</param>
/// <returns>A CBOR object.</returns>
public static CBORObject FromInt(int value) {
public static CBORObject FromInt32(int value) {
return value >= 0 && value < 24 ? FixedObjects[value] :
(value >= -24 && value < 0) ? FixedObjects[0x20 - (value + 1)] :
FromInt64((long)value);
Expand All @@ -2326,7 +2326,7 @@ public static CBORObject FromInt(int value) {
/// 32-bit signed integer.</param>
/// <returns>A CBOR object.</returns>
[Obsolete("Use FromInt instead.")]
public static CBORObject FromObject(int value) => FromInt(value);
public static CBORObject FromObject(int value) => FromInt32(value);

/// <summary>Generates a CBOR object from a 16-bit signed
/// integer.</summary>
Expand Down Expand Up @@ -2368,7 +2368,7 @@ public static CBORObject FromBool(bool value) {
/// byte (from 0 to 255).</param>
/// <returns>A CBOR object generated from the given integer.</returns>
public static CBORObject FromByte(byte value) {
return FromInt(value & 0xff);
return FromInt32(value & 0xff);
}

/// <summary>Generates a CBOR object from a byte.</summary>
Expand Down Expand Up @@ -2500,7 +2500,7 @@ public static CBORObject FromObject(int[] array) {
IList<CBORObject> list = new List<CBORObject>(array.Length ==
Int32.MaxValue ? array.Length : (array.Length + 1));
foreach (int i in array) {
list.Add(FromInt(i));
list.Add(FromInt32(i));
}
return new CBORObject(CBORObjectTypeArray, list);
}
Expand Down Expand Up @@ -2860,7 +2860,7 @@ internal static CBORObject FromObject(
return FromString((string)obj);
}
if (obj is int) {
return FromInt((int)obj);
return FromInt32((int)obj);
}
if (obj is long) {
return FromInt64((long)obj);
Expand All @@ -2881,7 +2881,7 @@ internal static CBORObject FromObject(
return FromInt16((short)obj);
}
if (obj is char) {
return FromInt((int)(char)obj);
return FromInt32((int)(char)obj);
}
if (obj is bool) {
return FromBool((bool)obj);
Expand Down Expand Up @@ -5769,7 +5769,7 @@ public CBORObject Set(CBORObject mapKey, CBORObject mapValue) {
/// an array.</exception>
public CBORObject Set(int key, CBORObject mapValue) {
if (this.Type == CBORType.Map) {
CBORObject mapKey = CBORObject.FromInt(key);
CBORObject mapKey = CBORObject.FromInt32(key);
IDictionary<CBORObject, CBORObject> map = this.AsMap();
map[mapKey] = mapValue;
} else if (this.Type == CBORType.Array) {
Expand Down
12 changes: 6 additions & 6 deletions CBORTest/CBORExtraTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ public System.Collections.Generic.IEnumerator<byte>
[Test]
public void TestCustomFlagsEnum() {
var cbor = CBORObject.FromObject(CustomBits.A | CustomBits.B);
Assert.AreEqual(CBORObject.FromInt(3), cbor);
Assert.AreEqual(CBORObject.FromInt32(3), cbor);
CustomBits cfe = cbor.ToObject<CustomBits>();
Assert.AreEqual(CustomBits.A | CustomBits.B, cfe);
cbor = CBORObject.FromObject(CustomBits.A);
Assert.AreEqual(CBORObject.FromInt(1), cbor);
Assert.AreEqual(CBORObject.FromInt32(1), cbor);
cfe = cbor.ToObject<CustomBits>();
Assert.AreEqual(CustomBits.A, cfe);
}
Expand Down Expand Up @@ -6574,19 +6574,19 @@ public void TestToObjectNull() {
public void TestNullable() {
int? nvalue = 1;
var cbor = CBORObject.FromObject((object)nvalue);
Assert.AreEqual(CBORObject.FromInt(1), cbor);
Assert.AreEqual(CBORObject.FromInt32(1), cbor);
nvalue = null;
_ = CBORObject.FromObject((object)nvalue);
uint? unvalue = 1u;
cbor = CBORObject.FromObject((object)unvalue);
Assert.AreEqual(CBORObject.FromInt(1), cbor);
Assert.AreEqual(CBORObject.FromInt32(1), cbor);
unvalue = null;
cbor = CBORObject.FromObject((object)unvalue);
Assert.AreEqual(CBORObject.Null, cbor);
Assert.AreEqual(null, CBORObject.Null.ToObject<int?>());
Assert.AreEqual(1, CBORObject.FromInt(1).ToObject<int?>());
Assert.AreEqual(1, CBORObject.FromInt32(1).ToObject<int?>());
Assert.AreEqual(null, CBORObject.Null.ToObject<uint?>());
Assert.AreEqual(1u, CBORObject.FromInt(1).ToObject<uint?>());
Assert.AreEqual(1u, CBORObject.FromInt32(1).ToObject<uint?>());
Assert.AreEqual(null, CBORObject.Null.ToObject<double?>());
if (CBORObject.FromDouble(3.5).ToObject<double?>() != 3.5) {
Assert.Fail();
Expand Down
24 changes: 12 additions & 12 deletions CBORTest/CBORNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ public void TestCanFitInInt32() {

[Test]
public void TestCanFitInInt64() {
Assert.IsTrue(CBORObject.FromInt(0).AsNumber().CanFitInInt64());
Assert.IsTrue(CBORObject.FromInt(99).AsNumber().CanFitInInt64());
Assert.IsTrue(CBORObject.FromInt32(0).AsNumber().CanFitInInt64());
Assert.IsTrue(CBORObject.FromInt32(99).AsNumber().CanFitInInt64());
Assert.IsFalse(CBORObject.PositiveInfinity.AsNumber().CanFitInInt64());
Assert.IsFalse(CBORObject.NegativeInfinity.AsNumber().CanFitInInt64());
Assert.IsFalse(CBORObject.NaN.AsNumber().CanFitInInt64());
}

[Test]
public void TestCanFitInUInt64() {
Assert.IsTrue(CBORObject.FromInt(0).AsNumber().CanFitInUInt64(), "0");
Assert.IsTrue(CBORObject.FromInt32(0).AsNumber().CanFitInUInt64(), "0");
Assert.IsTrue(
CBORObject.FromInt(99).AsNumber().CanFitInUInt64(),
CBORObject.FromInt32(99).AsNumber().CanFitInUInt64(),
"99");

Assert.IsTrue(CBORObject.FromDouble(99.0).AsNumber().CanFitInUInt64(),
Expand All @@ -91,7 +91,7 @@ public void TestCanFitInUInt64() {
Assert.IsFalse(b);

Assert.IsFalse(
CBORObject.FromInt(-99).AsNumber().CanFitInUInt64(),
CBORObject.FromInt32(-99).AsNumber().CanFitInUInt64(),
"-99");

Assert.IsFalse(CBORObject.FromDouble(-99.0).AsNumber().CanFitInUInt64(),
Expand All @@ -111,11 +111,11 @@ public void TestCanFitInUInt64() {
[Test]
public void TestCanTruncatedIntFitInUInt64() {
Assert.IsTrue(
CBORObject.FromInt(0).AsNumber().CanTruncatedIntFitInUInt64(),
CBORObject.FromInt32(0).AsNumber().CanTruncatedIntFitInUInt64(),
"0");

Assert.IsTrue(
CBORObject.FromInt(99).AsNumber().CanTruncatedIntFitInUInt64(),
CBORObject.FromInt32(99).AsNumber().CanTruncatedIntFitInUInt64(),
"99");

Assert.IsTrue(
Expand All @@ -125,7 +125,7 @@ public void TestCanTruncatedIntFitInUInt64() {
-0.0).AsNumber().CanTruncatedIntFitInUInt64());

Assert.IsFalse(
CBORObject.FromInt(-99).AsNumber().CanTruncatedIntFitInUInt64());
CBORObject.FromInt32(-99).AsNumber().CanTruncatedIntFitInUInt64());
bool
b = CBORObject.FromEInteger(EInteger.FromInt32(1).ShiftLeft(65)).AsNumber()
.CanTruncatedIntFitInUInt64();
Expand Down Expand Up @@ -154,17 +154,17 @@ public void TestCanTruncatedIntFitInUInt64() {

[Test]
public void TestIsInfinity() {
Assert.IsFalse(CBORObject.FromInt(0).AsNumber().IsInfinity());
Assert.IsFalse(CBORObject.FromInt(99).AsNumber().IsInfinity());
Assert.IsFalse(CBORObject.FromInt32(0).AsNumber().IsInfinity());
Assert.IsFalse(CBORObject.FromInt32(99).AsNumber().IsInfinity());
Assert.IsTrue(CBORObject.PositiveInfinity.AsNumber().IsInfinity());
Assert.IsTrue(CBORObject.NegativeInfinity.AsNumber().IsInfinity());
Assert.IsFalse(CBORObject.NaN.AsNumber().IsInfinity());
}

[Test]
public void TestIsNaN() {
Assert.IsFalse(CBORObject.FromInt(0).AsNumber().IsNaN());
Assert.IsFalse(CBORObject.FromInt(99).AsNumber().IsNaN());
Assert.IsFalse(CBORObject.FromInt32(0).AsNumber().IsNaN());
Assert.IsFalse(CBORObject.FromInt32(99).AsNumber().IsNaN());
Assert.IsFalse(CBORObject.PositiveInfinity.AsNumber().IsNaN());
Assert.IsFalse(CBORObject.NegativeInfinity.AsNumber().IsNaN());
Assert.IsTrue(CBORObject.NaN.AsNumber().IsNaN());
Expand Down
Loading

0 comments on commit 0e8456d

Please sign in to comment.