mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Convert unix date to .net dates.
Array.Equals() does not compare array internals but object reference, implement substitute. String.Substring() has a different API than Java, correct.
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* ParseTest.cs:
|
||||||
|
Convert unix date to .net dates.
|
||||||
|
Array.Equals() does not compare array internals but object
|
||||||
|
reference, implement substitute.
|
||||||
|
String.Substring() has a different API than Java, correct.
|
||||||
|
|
||||||
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* IssueTest.cs:
|
* IssueTest.cs:
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace plistcil.test
|
|||||||
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
||||||
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
||||||
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc)));
|
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc)));
|
||||||
Assert.True(Array.Equals(((NSData)d.ObjectForKey("data")).Bytes,
|
Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes,
|
||||||
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
||||||
NSArray a = (NSArray)d.ObjectForKey("array");
|
NSArray a = (NSArray)d.ObjectForKey("array");
|
||||||
Assert.True(a.Count == 4);
|
Assert.True(a.Count == 4);
|
||||||
@@ -112,8 +112,8 @@ namespace plistcil.test
|
|||||||
Assert.True(d.Count == 5);
|
Assert.True(d.Count == 5);
|
||||||
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
||||||
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
||||||
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(1322472090000L)));
|
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc)));
|
||||||
Assert.True(Array.Equals(((NSData)d.ObjectForKey("data")).Bytes,
|
Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes,
|
||||||
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
||||||
NSArray a = (NSArray)d.ObjectForKey("array");
|
NSArray a = (NSArray)d.ObjectForKey("array");
|
||||||
Assert.True(a.Count == 4);
|
Assert.True(a.Count == 4);
|
||||||
@@ -131,8 +131,8 @@ namespace plistcil.test
|
|||||||
Assert.True(d.Count == 5);
|
Assert.True(d.Count == 5);
|
||||||
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA"));
|
||||||
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B"));
|
||||||
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(1322472090000L)));
|
Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc)));
|
||||||
Assert.True(Array.Equals(((NSData)d.ObjectForKey("data")).Bytes,
|
Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes,
|
||||||
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
new byte[]{ 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 }));
|
||||||
NSArray a = (NSArray)d.ObjectForKey("array");
|
NSArray a = (NSArray)d.ObjectForKey("array");
|
||||||
Assert.True(a.Count == 4);
|
Assert.True(a.Count == 4);
|
||||||
@@ -266,6 +266,23 @@ namespace plistcil.test
|
|||||||
Assert.True(((long)map.get("long")) == lng);
|
Assert.True(((long)map.get("long")) == lng);
|
||||||
Assert.True(((DateTime)map.get("date")).Equals(date));*/
|
Assert.True(((DateTime)map.get("date")).Equals(date));*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ArrayEquals(byte[] arrayA, byte[] arrayB)
|
||||||
|
{
|
||||||
|
if (arrayA.Length == arrayB.Length)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < arrayA.Length; i++)
|
||||||
|
{
|
||||||
|
if (arrayA[i] != arrayB[i])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ namespace Claunia.PropertyList
|
|||||||
int numBytes = dataString.Length / 2;
|
int numBytes = dataString.Length / 2;
|
||||||
byte[] bytes = new byte[numBytes];
|
byte[] bytes = new byte[numBytes];
|
||||||
for (int i = 0; i < bytes.Length; i++) {
|
for (int i = 0; i < bytes.Length; i++) {
|
||||||
string byteString = dataString.Substring(i * 2, i * 2 + 2);
|
string byteString = dataString.Substring(i * 2, 2);
|
||||||
int byteValue = Convert.ToInt32(byteString, 16);
|
int byteValue = Convert.ToInt32(byteString, 16);
|
||||||
bytes[i] = (byte) byteValue;
|
bytes[i] = (byte) byteValue;
|
||||||
}
|
}
|
||||||
@@ -579,7 +579,7 @@ namespace Claunia.PropertyList
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
//Build string
|
//Build string
|
||||||
string result = Encoding.UTF8.GetString(bytArr);
|
string result = Encoding.BigEndianUnicode.GetString(bytArr);
|
||||||
//emoryStream charBuf = CharBuffer.wrap(result);
|
//emoryStream charBuf = CharBuffer.wrap(result);
|
||||||
|
|
||||||
//If the string can be represented in the ASCII codepage
|
//If the string can be represented in the ASCII codepage
|
||||||
@@ -587,7 +587,7 @@ namespace Claunia.PropertyList
|
|||||||
try{
|
try{
|
||||||
if (asciiEncoder == null)
|
if (asciiEncoder == null)
|
||||||
asciiEncoder = Encoding.GetEncoding("ascii", EncoderExceptionFallback.ExceptionFallback, DecoderExceptionFallback.ExceptionFallback);
|
asciiEncoder = Encoding.GetEncoding("ascii", EncoderExceptionFallback.ExceptionFallback, DecoderExceptionFallback.ExceptionFallback);
|
||||||
return asciiEncoder.GetString(Encoding.Convert(Encoding.UTF8, asciiEncoder, bytArr));
|
return asciiEncoder.GetString(Encoding.Convert(Encoding.BigEndianUnicode, asciiEncoder, bytArr));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
|
* NSData.cs:
|
||||||
|
* NSArray.cs:
|
||||||
|
* NSObject.cs:
|
||||||
|
* NSDictionary.cs:
|
||||||
|
* ASCIIPropertyListParser.cs:
|
||||||
|
Convert unix date to .net dates.
|
||||||
|
Array.Equals() does not compare array internals but object
|
||||||
|
reference, implement substitute.
|
||||||
|
String.Substring() has a different API than Java, correct.
|
||||||
|
|
||||||
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
2015-02-19 Natalia Portillo <claunia@claunia.com>
|
||||||
|
|
||||||
* plist-cil.csproj:
|
* plist-cil.csproj:
|
||||||
|
|||||||
@@ -201,14 +201,14 @@ namespace Claunia.PropertyList
|
|||||||
{
|
{
|
||||||
if (obj.GetType().Equals(typeof(NSArray)))
|
if (obj.GetType().Equals(typeof(NSArray)))
|
||||||
{
|
{
|
||||||
return Array.Equals(((NSArray)obj).GetArray(), this.array);
|
return ArrayEquals(((NSArray)obj).GetArray(), this.array);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSObject nso = NSObject.Wrap(obj);
|
NSObject nso = NSObject.Wrap(obj);
|
||||||
if (nso.GetType().Equals(typeof(NSArray)))
|
if (nso.GetType().Equals(typeof(NSArray)))
|
||||||
{
|
{
|
||||||
return Array.Equals(((NSArray)nso).GetArray(), this.array);
|
return ArrayEquals(((NSArray)nso).GetArray(), this.array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace Claunia.PropertyList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(Object obj) {
|
public override bool Equals(Object obj) {
|
||||||
return obj.GetType().Equals(GetType()) && Array.Equals(((NSData) obj).bytes, bytes);
|
return obj.GetType().Equals(GetType()) && ArrayEquals(((NSData) obj).bytes, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ namespace Claunia.PropertyList
|
|||||||
foreach (NSObject o in dict.Values) {
|
foreach (NSObject o in dict.Values) {
|
||||||
if (o.GetType().Equals(typeof(NSData))) {
|
if (o.GetType().Equals(typeof(NSData))) {
|
||||||
NSData dat = (NSData) o;
|
NSData dat = (NSData) o;
|
||||||
if (Array.Equals(dat.Bytes, val))
|
if (ArrayEquals(dat.Bytes, val))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,6 +409,39 @@ namespace Claunia.PropertyList
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool ArrayEquals(byte[] arrayA, byte[] arrayB)
|
||||||
|
{
|
||||||
|
if (arrayA.Length == arrayB.Length)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < arrayA.Length; i++)
|
||||||
|
{
|
||||||
|
if (arrayA[i] != arrayB[i])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool ArrayEquals(NSObject[] arrayA, NSObject[] arrayB)
|
||||||
|
{
|
||||||
|
if (arrayA.Length == arrayB.Length)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < arrayA.Length; i++)
|
||||||
|
{
|
||||||
|
if (arrayA[i] != arrayB[i])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user