mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
fix byte order error
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32782 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4d646deb2e
commit
92ac6e50d4
1 changed files with 27 additions and 1 deletions
|
@ -10,6 +10,7 @@ copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
|||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAttributedString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSByteOrder.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
|
@ -26,6 +27,10 @@ copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
|||
#include <Foundation/NSURL.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
@interface NSObject (Equality)
|
||||
- (BOOL) testEquality: (id)other;
|
||||
@end
|
||||
|
||||
@interface NSObject (DecodingTests)
|
||||
+ (NSObject*) createTestInstance;
|
||||
+ (BOOL) verifyTestInstance: (NSObject *)instance
|
||||
|
@ -115,7 +120,28 @@ copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
|||
@implementation NSData (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[@"We need constant data" dataUsingEncoding: NSUnicodeStringEncoding] retain];
|
||||
NSString *source = @"We need constant data";
|
||||
NSData *data = [source dataUsingEncoding: NSUnicodeStringEncoding];
|
||||
|
||||
if (NSHostByteOrder() == NS_BigEndian)
|
||||
{
|
||||
NSMutableData *m = [data mutableCopy];
|
||||
uint8_t *p = (uint8_t*)[m mutableBytes];
|
||||
uint8_t *e = p + [m length];
|
||||
|
||||
while (p < e)
|
||||
{
|
||||
uint8_t tmp = p[0];
|
||||
|
||||
p[0] = *++p;
|
||||
*p++ = tmp;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [data retain];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue